From 86d332be05580366e264fb712178ef44d38c6c8b Mon Sep 17 00:00:00 2001 From: Gonzalo Paniagua Javier Date: Mon, 26 Jan 2009 05:06:30 +0000 Subject: [PATCH] Backported fixes from HEAD svn path=/branches/mono-2-2/mcs/; revision=124454 --- mcs/class/System/System.Net/ChangeLog | 24 +++++++++- mcs/class/System/System.Net/HttpWebRequest.cs | 44 +++++++++++++------ mcs/class/System/System.Net/IPAddress.cs | 8 +++- 3 files changed, 61 insertions(+), 15 deletions(-) diff --git a/mcs/class/System/System.Net/ChangeLog b/mcs/class/System/System.Net/ChangeLog index c49de68e7f7..bc95b2aeee6 100644 --- a/mcs/class/System/System.Net/ChangeLog +++ b/mcs/class/System/System.Net/ChangeLog @@ -1,9 +1,21 @@ +2009-01-26 Gonzalo Paniagua Javier + + * HttpWebRequest.cs: added locking in SetResponseData for the case + when we get an error response before BeginGetResponse has been + called. + 2009-01-20 Gonzalo Paniagua Javier * IPAddress.cs: handle sign extension for the high byte when using the byte[] ctor for an IPv4 address. Fixes bug #467472. +2009-01-19 Marek Habersack + + * HttpWebRequest.cs: implemented the UseDefaultCredentials + property, patch from Florian Maetschke , + thanks! + 2009-01-16 Gonzalo Paniagua Javier * FtpWebRequest.cs: adjust to the correct directory when listing too. @@ -20,6 +32,13 @@ * WebConnectionStream.cs: if the buffer has been killed, return -1 for its length. Fixes regression in System.Runtime.Remoting. +2009-01-14 Gonzalo Paniagua Javier + + * HttpWebRequest.cs: create a result from the response when + *GetResponse() has not been called yet and we have already received + all the data. + Fixes bug #464013. + 2009-01-13 Gonzalo Paniagua Javier * HttpWebRequest.cs: keepAlive is of no use here. @@ -38,13 +57,16 @@ * FtpWebRequest.cs: now deleting a file works when we're not in the root directory. +2008-12-20 Gonzalo Paniagua Javier + + * IPAddress.cs: avoid throwing when parsing a subnet. + 2008-11-18 Gonzalo Paniagua Javier * HttpConnection.cs: remove CWL. When reusing, BeginReadRequest might throw if the client closes. * HttpListenerResponse.cs: close the connection for 1.0 clients. - Backported from HEAD. Fixes bug #459432. 2008-11-13 Gonzalo Paniagua Javier * FtpDataStream.cs: use the socket for reading until the end of a diff --git a/mcs/class/System/System.Net/HttpWebRequest.cs b/mcs/class/System/System.Net/HttpWebRequest.cs index 16776c66563..dfa3a8f5b88 100644 --- a/mcs/class/System/System.Net/HttpWebRequest.cs +++ b/mcs/class/System/System.Net/HttpWebRequest.cs @@ -538,15 +538,10 @@ namespace System.Net } #if NET_2_0 - [MonoTODO] public override bool UseDefaultCredentials { - get { - throw GetMustImplement (); - } - set { - throw GetMustImplement (); - } + get { return CredentialCache.DefaultCredentials == Credentials; } + set { Credentials = value ? CredentialCache.DefaultCredentials : null; } } #endif @@ -732,7 +727,7 @@ namespace System.Net void CheckIfForceWrite () { - if (writeStream == null || contentLength < 0 || !InternalAllowBuffering) + if (writeStream == null || writeStream.RequestWritten|| contentLength < 0 || !InternalAllowBuffering) return; // This will write the POST/PUT if the write stream already has the expected @@ -750,10 +745,10 @@ namespace System.Net } CommonChecks (send); - Monitor.Enter (this); + Monitor.Enter (locker); getResponseCalled = true; if (asyncRead != null && !haveResponse) { - Monitor.Exit (this); + Monitor.Exit (locker); throw new InvalidOperationException ("Cannot re-call start of asynchronous " + "method while a previous call is still in progress."); } @@ -765,7 +760,7 @@ namespace System.Net if (haveResponse) { if (webResponse != null) { Exception saved = saved_exc; - Monitor.Exit (this); + Monitor.Exit (locker); if (saved == null) { aread.SetCompleted (true, webResponse); } else { @@ -773,6 +768,10 @@ namespace System.Net } aread.DoCallback (); return aread; + } else if (saved_exc != null) { + aread.SetCompleted (true, saved_exc); + aread.DoCallback (); + return aread; } } @@ -783,7 +782,7 @@ namespace System.Net abortHandler = servicePoint.SendRequest (this, connectionGroup); } - Monitor.Exit (this); + Monitor.Exit (locker); return aread; } @@ -1172,6 +1171,7 @@ namespace System.Net internal void SetResponseData (WebConnectionData data) { + lock (locker) { if (aborted) { if (data.stream != null) data.stream.Close (); @@ -1181,7 +1181,6 @@ namespace System.Net WebException wexc = null; try { webResponse = new HttpWebResponse (actualUri, method, data, cookieContainer); - haveResponse = true; } catch (Exception e) { wexc = new WebException (e.Message, e, WebExceptionStatus.ProtocolError, null); if (data.stream != null) @@ -1197,6 +1196,15 @@ namespace System.Net } WebAsyncResult r = asyncRead; + + bool forced = false; + if (r == null && webResponse != null) { + // This is a forced completion (302, 204)... + forced = true; + r = new WebAsyncResult (null, null); + r.SetCompleted (false, webResponse); + } + if (r != null) { if (wexc != null) { r.SetCompleted (false, wexc); @@ -1222,6 +1230,7 @@ namespace System.Net if (writeStream != null) writeStream.KillBuffer (); + haveResponse = true; r.SetCompleted (false, webResponse); r.DoCallback (); } else { @@ -1239,16 +1248,25 @@ namespace System.Net abortHandler = servicePoint.SendRequest (this, connectionGroup); } } catch (WebException wexc2) { + if (forced) { + saved_exc = wexc2; + haveResponse = true; + } r.SetCompleted (false, wexc2); r.DoCallback (); return; } catch (Exception ex) { wexc = new WebException (ex.Message, ex, WebExceptionStatus.ProtocolError, null); + if (forced) { + saved_exc = wexc; + haveResponse = true; + } r.SetCompleted (false, wexc); r.DoCallback (); return; } } + } } bool CheckAuthorization (WebResponse response, HttpStatusCode code) diff --git a/mcs/class/System/System.Net/IPAddress.cs b/mcs/class/System/System.Net/IPAddress.cs index 3a7ee7ec3f4..f130fe20be5 100644 --- a/mcs/class/System/System.Net/IPAddress.cs +++ b/mcs/class/System/System.Net/IPAddress.cs @@ -269,8 +269,14 @@ namespace System.Net { return null; } } - else + else { +#if NET_2_0 + if (!Int64.TryParse (subnet, NumberStyles.None, null, out val)) + return null; +#else val = long.Parse (subnet, NumberStyles.None); +#endif + } if (i == (ips.Length - 1)) i = 3; -- 2.25.1