Author: dna
Date: 2008-02-20 12:55:59 -0500 (Wed, 20 Feb 2008)
New Revision: 96279
Modified:
branches/mono-1-9/mcs/class/System/System.Net/ChangeLog
branches/mono-1-9/mcs/class/System/System.Net/HttpWebResponse.cs
Log:
2008-02-17 Daniel Nauck <[EMAIL PROTECTED]>
[Backport from r95967 to 1.9]
* HttpWebResponse.cs: refactored cookie expires parsing to
allow all common expires datetime formats.
Modified: branches/mono-1-9/mcs/class/System/System.Net/ChangeLog
===================================================================
--- branches/mono-1-9/mcs/class/System/System.Net/ChangeLog 2008-02-20
17:30:50 UTC (rev 96278)
+++ branches/mono-1-9/mcs/class/System/System.Net/ChangeLog 2008-02-20
17:55:59 UTC (rev 96279)
@@ -1,3 +1,9 @@
+2008-02-17 Daniel Nauck <[EMAIL PROTECTED]>
+
+ [Backport from r95967 to 1.9]
+ * HttpWebResponse.cs: refactored cookie expires parsing to
+ allow all common expires datetime formats.
+
2008-02-13 Daniel Nauck <[EMAIL PROTECTED]>
[Backport from r95334 to 1.9]
Modified: branches/mono-1-9/mcs/class/System/System.Net/HttpWebResponse.cs
===================================================================
--- branches/mono-1-9/mcs/class/System/System.Net/HttpWebResponse.cs
2008-02-20 17:30:50 UTC (rev 96278)
+++ branches/mono-1-9/mcs/class/System/System.Net/HttpWebResponse.cs
2008-02-20 17:55:59 UTC (rev 96279)
@@ -8,6 +8,7 @@
//
// (c) 2002 Lawrence Pit
// (c) 2003 Ximian, Inc. (http://www.ximian.com)
+// (c) 2008 Daniel Nauck
//
//
@@ -408,27 +409,7 @@
if (cookie.Expires != DateTime.MinValue)
break;
- //If no Expires is set, use cookie as
session cookie (expires is DateTime.MinValue)
- DateTime cookieExpiresUtc =
DateTime.MinValue;
- try {
- cookieExpiresUtc =
DateTime.ParseExact (val, "r", CultureInfo.InvariantCulture);
- } catch {
- try {
- cookieExpiresUtc =
DateTime.ParseExact (val,
- "ddd,
dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'",
-
CultureInfo.InvariantCulture);
- } catch {}
- }
-
- //convert UTC/GMT time to local time
-#if NET_2_0
- cookieExpiresUtc = DateTime.SpecifyKind
(cookieExpiresUtc, DateTimeKind.Utc);
- cookie.Expires =
TimeZone.CurrentTimeZone.ToLocalTime (cookieExpiresUtc);
-#else
- //DateTime.Kind is only available on
.NET 2.0, so do some calculation
- TimeSpan localOffset =
TimeZone.CurrentTimeZone.GetUtcOffset (cookieExpiresUtc.Date);
- cookie.Expires = cookieExpiresUtc.Add
(localOffset);
-#endif
+ cookie.Expires = TryParseCookieExpires
(val);
break;
case "PATH":
cookie.Path = val;
@@ -466,6 +447,37 @@
foreach (string cookie_str in cookies)
SetCookie (cookie_str);
}
+
+ string[] cookieExpiresFormats =
+ new string[] { "r",
+ "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss
'GMT'",
+ "ddd, dd'-'MMM'-'yy HH':'mm':'ss 'GMT'"
};
+
+ DateTime TryParseCookieExpires (string value)
+ {
+ if (value == null || value.Length == 0)
+ return DateTime.MinValue;
+
+ for (int i = 0; i < cookieExpiresFormats.Length; i++)
+ {
+ try {
+ DateTime cookieExpiresUtc =
DateTime.ParseExact (value, cookieExpiresFormats [i],
CultureInfo.InvariantCulture);
+
+ //convert UTC/GMT time to local time
+#if NET_2_0
+ cookieExpiresUtc = DateTime.SpecifyKind
(cookieExpiresUtc, DateTimeKind.Utc);
+ return
TimeZone.CurrentTimeZone.ToLocalTime (cookieExpiresUtc);
+#else
+ //DateTime.Kind is only available on
.NET 2.0, so do some calculation
+ TimeSpan localOffset =
TimeZone.CurrentTimeZone.GetUtcOffset (cookieExpiresUtc.Date);
+ return cookieExpiresUtc.Add
(localOffset);
+#endif
+ } catch {}
+ }
+
+ //If we can't parse Expires, use cookie as session
cookie (expires is DateTime.MinValue)
+ return DateTime.MinValue;
+ }
}
class CookieParser {
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches