Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/System/System.Net/HttpWebResponse.cs')
-rw-r--r--mcs/class/System/System.Net/HttpWebResponse.cs146
1 files changed, 48 insertions, 98 deletions
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 ();
- }
}
}