diff options
Diffstat (limited to 'mcs/class/System/System.Net')
-rw-r--r-- | mcs/class/System/System.Net/ChangeLog | 49 | ||||
-rw-r--r-- | mcs/class/System/System.Net/Cookie.cs | 35 | ||||
-rw-r--r-- | mcs/class/System/System.Net/HttpWebRequest.cs | 6 | ||||
-rw-r--r-- | mcs/class/System/System.Net/HttpWebResponse.cs | 146 | ||||
-rw-r--r-- | mcs/class/System/System.Net/WebConnection.cs | 60 | ||||
-rw-r--r-- | mcs/class/System/System.Net/WebConnectionStream.cs | 15 | ||||
-rw-r--r-- | mcs/class/System/System.Net/WebHeaderCollection.cs | 47 | ||||
-rw-r--r-- | mcs/class/System/System.Net/WebProxy.cs | 2 |
8 files changed, 116 insertions, 244 deletions
diff --git a/mcs/class/System/System.Net/ChangeLog b/mcs/class/System/System.Net/ChangeLog index 92fa9343ef4..2b470e6423b 100644 --- a/mcs/class/System/System.Net/ChangeLog +++ b/mcs/class/System/System.Net/ChangeLog @@ -1,52 +1,3 @@ -2004-08-11 Gonzalo Paniagua Javier <gonzalo@ximian.com> - - * Cookie.cs: don't fail when using default constructor. Fixes bug - #62890. - -2004-08-11 Gonzalo Paniagua Javier <gonzalo@ximian.com> - - * HttpWebResponse.cs: set-cookie and set-cookie2 can be present more - than once and have multiple values. Don't rely on string.split when - parsing cookie values. - - * WebHeaderCollection.cs: same thing for set-cookie and set-cookie2. - Fixed GetValues (it was splitting values that contained a comma) and - changed SetInternal to handle multi-value headers. - - Fixes bug #62744. - -2004-07-26 Gonzalo Paniagua Javier <gonzalo@ximian.com> - - * WebProxy.cs: fix scheme detection. Patch by Konstantin Triger - (kostat@mainsoft.com). - -2004-07-16 Gonzalo Paniagua Javier <gonzalo@ximian.com> - - * HttpWebRequest.cs: detect changes in scheme or port when redirecting. - Fixes las take on bug 61218. - -2004-07-14 Gonzalo Paniagua Javier <gonzalo@ximian.com> - - * WebConnection.cs: moved loading of the ssl stream Type to its own - method. Don't create a new ssl stream if we're reusing the connection. - - * WebConnectionStream.cs: ensure the number of bytes copied in ReadAll - is the expected even if the dta from the server has extra bytes. - -2004-07-12 Gonzalo Paniagua Javier <gonzalo@ximian.com> - - * WebConnection.cs: - * WebConnectionStream.cs: when the status code is 1xx, 204 or 304, - "responses MUST NOT include a message-body". We tried to read the - stream even when getting those codes and considered the 0 length - read as a failure. - -2004-07-09 Gonzalo Paniagua Javier <gonzalo@ximian.com> - - * HttpWebRequest.cs: removed bogus Monitor.Exit. - * WebConnection.cs: use Address instead of RequestUri when checking for - the scheme in order to select the stream type. Fixes bug #61218. - 2004-06-06 Gonzalo Paniagua Javier <gonzalo@ximian.com> * ChunkStream.cs: added ChunkLeft property. diff --git a/mcs/class/System/System.Net/Cookie.cs b/mcs/class/System/System.Net/Cookie.cs index 30ee979fef1..c0235be1f1e 100644 --- a/mcs/class/System/System.Net/Cookie.cs +++ b/mcs/class/System/System.Net/Cookie.cs @@ -57,23 +57,24 @@ namespace System.Net { private static char [] reservedCharsValue = new char [] {';', ','};
private static char [] portSeparators = new char [] {'"', ','};
private static string tspecials = "()<>@,;:\\\"/[]?={} \t"; // from RFC 2965, 2068
- - public Cookie () - { - expires = DateTime.MinValue; - timestamp = DateTime.Now; - domain = ""; - name = ""; - val = ""; - } - - public Cookie (string name, string value) - : this () - { - Name = name; - Value = value; - } - +
+ public Cookie ()
+ : this (String.Empty, String.Empty) {}
+
+ public Cookie (string name, string value)
+ {
+ Name = name;
+ Value = value;
+
+ discard = false;
+ expired = false;
+ secure = false;
+ expires = DateTime.MinValue;
+ timestamp = DateTime.Now;
+ version = 0;
+ domain = "";
+ }
+
public Cookie (string name, string value, string path)
: this (name, value)
{
diff --git a/mcs/class/System/System.Net/HttpWebRequest.cs b/mcs/class/System/System.Net/HttpWebRequest.cs index f20a0747a3f..40dfe26a546 100644 --- a/mcs/class/System/System.Net/HttpWebRequest.cs +++ b/mcs/class/System/System.Net/HttpWebRequest.cs @@ -584,6 +584,7 @@ namespace System.Net initialMethod = method; if (haveRequest) { if (writeStream != null) { + Monitor.Exit (this); asyncWrite.SetCompleted (true, writeStream); asyncWrite.DoCallback (); return asyncWrite; @@ -829,7 +830,7 @@ namespace System.Net throw new WebException ("No Location header found for " + (int) code, WebExceptionStatus.ProtocolError); - Uri prev = actualUri; + string host = actualUri.Host; try { actualUri = new Uri (actualUri, uriString); } catch (Exception) { @@ -838,8 +839,7 @@ namespace System.Net WebExceptionStatus.ProtocolError); } - hostChanged = (actualUri.Scheme != prev.Scheme || actualUri.Host != prev.Host || - actualUri.Port != prev.Port); + hostChanged = (actualUri.Host != host); return true; } diff --git a/mcs/class/System/System.Net/HttpWebResponse.cs b/mcs/class/System/System.Net/HttpWebResponse.cs index 9fcdce33fe3..b38108a1597 100644 --- a/mcs/class/System/System.Net/HttpWebResponse.cs +++ b/mcs/class/System/System.Net/HttpWebResponse.cs @@ -31,7 +31,6 @@ // using System; -using System.Globalization; using System.IO; using System.Net.Sockets; using System.Runtime.Serialization; @@ -316,17 +315,13 @@ namespace System.Net if (webHeaders == null) return; - string [] values = webHeaders.GetValues ("Set-Cookie"); - if (values != null) { - foreach (string va in values) - SetCookie (va); - } + string val = webHeaders ["Set-Cookie"]; + if (val != null && val.Trim () != "") + SetCookie (val); - values = webHeaders.GetValues ("Set-Cookie2"); - if (values != null) { - foreach (string va in values) - SetCookie2 (va); - } + val = webHeaders ["Set-Cookie2"]; + if (val != null && val.Trim () != "") + SetCookie2 (val); } static string [] SplitValue (string input) @@ -343,76 +338,65 @@ namespace System.Net return result; } - void SetCookie (string header) + [MonoTODO ("Parse dates")] + void SetCookie (string cookie_str) { - string [] name_values = header.Trim ().Split (';'); - int length = name_values.Length; + string[] parts = null; + Collections.Queue options = null; Cookie cookie = null; - int pos; - for (int i = 0; i < length; i++) { - pos = 0; - string name_value = name_values [i].Trim (); - string name = GetCookieName (name_value, name_value.Length, ref pos); - string value = GetCookieValue (name_value, name_value.Length, ref pos); - if (cookie == null) { - cookie = new Cookie (name, value); - continue; - } - name = name.ToUpper (); - switch (name) { - case "COMMENT": - if (cookie.Comment == null) - cookie.Comment = value; + options = new Collections.Queue (cookie_str.Split (';')); + parts = SplitValue ((string) options.Dequeue()); // NAME=VALUE must be first + + cookie = new Cookie (parts[0], parts[1]); + + while (options.Count > 0) { + parts = SplitValue ((string) options.Dequeue()); + switch (parts [0]) { + case "COMMENT": + if (cookie.Comment == null) + cookie.Comment = parts[1]; break; - case "COMMENTURL": - if (cookie.CommentUri == null) - cookie.CommentUri = new Uri (value); + case "COMMENTURL": + if (cookie.CommentUri == null) + cookie.CommentUri = new Uri(parts[1]); break; - case "DISCARD": - cookie.Discard = true; + case "DISCARD": + cookie.Discard = true; break; - case "DOMAIN": - if (cookie.Domain == "") - cookie.Domain = value; + case "DOMAIN": + if (cookie.Domain == "") + cookie.Domain = parts[1]; break; - case "MAX-AGE": // RFC Style Set-Cookie2 - if (cookie.Expires == DateTime.MinValue) - cookie.Expires = cookie.TimeStamp.AddSeconds (Int32.Parse (value)); + case "MAX-AGE": // RFC Style Set-Cookie2 + if (cookie.Expires == DateTime.MinValue) + cookie.Expires = cookie.TimeStamp.AddSeconds (Int32.Parse (parts[1])); break; - case "EXPIRES": // Netscape Style Set-Cookie - if (cookie.Expires != DateTime.MinValue) - break; - try { - cookie.Expires = DateTime.ParseExact (value, "r", CultureInfo.InvariantCulture); - } catch { - try { - cookie.Expires = DateTime.ParseExact (value, - "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'", - CultureInfo.InvariantCulture); - } catch { + case "EXPIRES": // Netscape Style Set-Cookie + if (cookie.Expires == DateTime.MinValue) { + //FIXME: Does DateTime parse something like: "Sun, 17-Jan-2038 19:14:07 GMT"? + //cookie.Expires = DateTime.ParseExact (parts[1]); cookie.Expires = DateTime.Now.AddDays (1); } - } break; - case "PATH": - cookie.Path = value; + case "PATH": + cookie.Path = parts[1]; break; - case "PORT": - if (cookie.Port == null) - cookie.Port = value; + case "PORT": + if (cookie.Port == null) + cookie.Port = parts[1]; break; - case "SECURE": - cookie.Secure = true; + case "SECURE": + cookie.Secure = true; break; - case "VERSION": - cookie.Version = Int32.Parse (value); + case "VERSION": + cookie.Version = Int32.Parse (parts[1]); break; - } - } + } // switch + } // while if (cookieCollection == null) - cookieCollection = new CookieCollection (); + cookieCollection = new CookieCollection(); if (cookie.Domain == "") cookie.Domain = uri.Host; @@ -427,40 +411,6 @@ namespace System.Net foreach (string cookie_str in cookies) SetCookie (cookie_str); } - - static string GetCookieValue (string str, int length, ref int i) - { - if (i >= length) - return null; - - int k = i; - while (k < length && Char.IsWhiteSpace (str [k])) - k++; - - int begin = k; - while (k < length && str [k] != ';') - k++; - - i = k; - return str.Substring (begin, i - begin).Trim (); - } - - static string GetCookieName (string str, int length, ref int i) - { - if (i >= length) - return null; - - int k = i; - while (k < length && Char.IsWhiteSpace (str [k])) - k++; - - int begin = k; - while (k < length && str [k] != ';' && str [k] != '=') - k++; - - i = k + 1; - return str.Substring (begin, k - begin).Trim (); - } } } diff --git a/mcs/class/System/System.Net/WebConnection.cs b/mcs/class/System/System.Net/WebConnection.cs index f3ef1d22076..c4b08a363d1 100644 --- a/mcs/class/System/System.Net/WebConnection.cs +++ b/mcs/class/System/System.Net/WebConnection.cs @@ -71,7 +71,7 @@ namespace System.Net bool ssl; bool certsAvailable; - static object classLock = new object (); + static bool sslCheck; static Type sslStream; static PropertyInfo piClient; static PropertyInfo piServer; @@ -127,48 +127,36 @@ namespace System.Net } } - static void EnsureSSLStreamAvailable () - { - lock (classLock) { - if (sslStream != null) - return; - - // HttpsClientStream is an internal glue class in Mono.Security.dll - sslStream = Type.GetType ("Mono.Security.Protocol.Tls.HttpsClientStream, " + - Consts.AssemblyMono_Security, false); - - if (sslStream == null) { - string msg = "Missing Mono.Security.dll assembly. " + - "Support for SSL/TLS is unavailable."; - - throw new NotSupportedException (msg); - } - piClient = sslStream.GetProperty ("SelectedClientCertificate"); - piServer = sslStream.GetProperty ("ServerCertificate"); - } - } - bool CreateStream (HttpWebRequest request) { try { NetworkStream serverStream = new NetworkStream (socket, false); - if (request.Address.Scheme == Uri.UriSchemeHttps) { + if (request.RequestUri.Scheme == Uri.UriSchemeHttps) { ssl = true; - EnsureSSLStreamAvailable (); - if (!reused || nstream == null || nstream.GetType () != sslStream) { - object[] args = new object [3] { serverStream, - request.ClientCertificates, - request }; - nstream = (Stream) Activator.CreateInstance (sslStream, args); + if (!sslCheck) { + lock (typeof (WebConnection)) { + sslCheck = true; + // HttpsClientStream is an internal glue class in Mono.Security.dll + sslStream = Type.GetType ("Mono.Security.Protocol.Tls.HttpsClientStream, " + Consts.AssemblyMono_Security, false); + if (sslStream != null) { + piClient = sslStream.GetProperty ("SelectedClientCertificate"); + piServer = sslStream.GetProperty ("ServerCertificate"); + } + } } + if (sslStream == null) + throw new NotSupportedException ("Missing Mono.Security.dll assembly. Support for SSL/TLS is unavailable."); + + object[] args = new object [4] { serverStream, request.RequestUri.Host, request.ClientCertificates, request }; + nstream = (Stream) Activator.CreateInstance (sslStream, args); + // we also need to set ServicePoint.Certificate // and ServicePoint.ClientCertificate but this can // only be done later (after handshake - which is // done only after a read operation). - } else { - ssl = false; - nstream = serverStream; } + else + nstream = serverStream; } catch (Exception) { status = WebExceptionStatus.ConnectFailure; return false; @@ -280,9 +268,6 @@ namespace System.Net data.stream = stream; - if (!ExpectContent (data.StatusCode)) - stream.ForceCompletion (); - lock (cnc) { lock (cnc.queue) { if (cnc.queue.Count > 0) { @@ -297,11 +282,6 @@ namespace System.Net data.request.SetResponseData (data); } - static bool ExpectContent (int statusCode) - { - return (statusCode >= 200 && statusCode != 204 && statusCode != 304); - } - internal void GetCertificates () { // here the SSL negotiation have been done diff --git a/mcs/class/System/System.Net/WebConnectionStream.cs b/mcs/class/System/System.Net/WebConnectionStream.cs index c609455f32f..703f35d42b4 100644 --- a/mcs/class/System/System.Net/WebConnectionStream.cs +++ b/mcs/class/System/System.Net/WebConnectionStream.cs @@ -57,7 +57,6 @@ namespace System.Net byte [] headers; bool disposed; bool headersSent; - bool forceCompletion; public WebConnectionStream (WebConnection cnc) { @@ -114,15 +113,9 @@ namespace System.Net get { return (int) writeBuffer.Length; } } - internal void ForceCompletion () - { - forceCompletion = true; - } - internal void CheckComplete () { - bool nrc = nextReadCalled; - if (forceCompletion || (!nrc && readBufferSize - readBufferOffset == contentLength)) { + if (!nextReadCalled && readBufferSize - readBufferOffset == contentLength) { nextReadCalled = true; cnc.NextRead (); } @@ -158,12 +151,8 @@ namespace System.Net } else { new_size = contentLength - totalRead; b = new byte [new_size]; - if (readBuffer != null && diff > 0) { - if (diff > new_size) - diff = new_size; - + if (readBuffer != null && diff > 0) Buffer.BlockCopy (readBuffer, readBufferOffset, b, 0, diff); - } int remaining = new_size - diff; int r = -1; diff --git a/mcs/class/System/System.Net/WebHeaderCollection.cs b/mcs/class/System/System.Net/WebHeaderCollection.cs index f41105bd5bc..e4ea21688c6 100644 --- a/mcs/class/System/System.Net/WebHeaderCollection.cs +++ b/mcs/class/System/System.Net/WebHeaderCollection.cs @@ -96,10 +96,6 @@ namespace System.Net multiValue.Add ("vary", true);
multiValue.Add ("via", true);
multiValue.Add ("warning", true);
- - // Extra - multiValue.Add ("set-cookie", true);
- multiValue.Add ("set-cookie2", true);
}
// Constructors
@@ -155,19 +151,28 @@ namespace System.Net throw new ArgumentException ("invalid header value: " + headerValue, "headerValue");
base.Add (headerName, headerValue);
}
- - public override string [] GetValues (string header) - { - if (header == null) - throw new ArgumentNullException ("header"); - - string [] values = base.GetValues (header); - if (values == null || values.Length == 0) - return null; - - return values; - } - +
+ public override string [] GetValues (string header)
+ {
+ if (header == null)
+ throw new ArgumentNullException ("header");
+ string [] values = base.GetValues (header);
+ if (values == null || values.Length == 0)
+ return null;
+ if (!IsMultiValue (header))
+ return values;
+ StringCollection col = new StringCollection ();
+ for (int i = 0; i < values.Length; i++) {
+ string [] s = values [i].Split (new char [] {','});
+ for (int j = 0; j < s.Length; j++)
+ s [j] = s [j].Trim ();
+ col.AddRange (s);
+ }
+ values = new string [col.Count];
+ col.CopyTo (values, 0);
+ return values;
+ }
+
public static bool IsRestricted (string headerName)
{
if (headerName == null)
@@ -260,12 +265,8 @@ namespace System.Net if (!IsHeaderValue (value))
throw new ArgumentException ("invalid header value");
- if (IsMultiValue (name)) { - base.Add (name, value); - } else { - base.Remove (name);
- base.Set (name, value);
- } + base.Remove (name);
+ base.Set (name, value);
}
internal void RemoveInternal (string name)
diff --git a/mcs/class/System/System.Net/WebProxy.cs b/mcs/class/System/System.Net/WebProxy.cs index df8976c6966..b0299575f60 100644 --- a/mcs/class/System/System.Net/WebProxy.cs +++ b/mcs/class/System/System.Net/WebProxy.cs @@ -208,7 +208,7 @@ namespace System.Net if (address == null)
return null;
- if (address.IndexOf ("://") == -1)
+ if (address.IndexOf (':') == -1)
address = "http://" + address;
return new Uri (address);
|