Author: dna
Date: 2008-02-13 09:58:29 -0500 (Wed, 13 Feb 2008)
New Revision: 95581

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-13  Daniel Nauck  <[EMAIL PROTECTED]>

        [Backport from r95334 to 1.9]
        * HttpWebResponse.cs: convert UTC/GMT Expires DateTime from a cookie
        into local time.



Modified: branches/mono-1-9/mcs/class/System/System.Net/ChangeLog
===================================================================
--- branches/mono-1-9/mcs/class/System/System.Net/ChangeLog     2008-02-13 
14:30:06 UTC (rev 95580)
+++ branches/mono-1-9/mcs/class/System/System.Net/ChangeLog     2008-02-13 
14:58:29 UTC (rev 95581)
@@ -1,3 +1,9 @@
+2008-02-13  Daniel Nauck  <[EMAIL PROTECTED]>
+
+       [Backport from r95334 to 1.9]
+        * HttpWebResponse.cs: convert UTC/GMT Expires DateTime from a cookie
+        into local time.
+
 2008-01-27  Gert Driesen  <[EMAIL PROTECTED]>
 
        * IPAddress.cs (Parse): Changed argument name to match MS.

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-13 14:30:06 UTC (rev 95580)
+++ branches/mono-1-9/mcs/class/System/System.Net/HttpWebResponse.cs    
2008-02-13 14:58:29 UTC (rev 95581)
@@ -4,6 +4,7 @@
 // Authors:
 //     Lawrence Pit ([EMAIL PROTECTED])
 //     Gonzalo Paniagua Javier ([EMAIL PROTECTED])
+//      Daniel Nauck    (dna(at)mono-project(dot)de)
 //
 // (c) 2002 Lawrence Pit
 // (c) 2003 Ximian, Inc. (http://www.ximian.com)
@@ -406,17 +407,28 @@
                                case "EXPIRES": // Netscape Style Set-Cookie
                                        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 {
-                                               cookie.Expires = 
DateTime.ParseExact (val, "r", CultureInfo.InvariantCulture);
+                                               cookieExpiresUtc = 
DateTime.ParseExact (val, "r", CultureInfo.InvariantCulture);
                                        } catch {
                                                try { 
-                                               cookie.Expires = 
DateTime.ParseExact (val,
+                                               cookieExpiresUtc = 
DateTime.ParseExact (val,
                                                                "ddd, 
dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'",
                                                                
CultureInfo.InvariantCulture);
-                                               } catch {
-                                                       cookie.Expires = 
DateTime.Now.AddDays (1);
-                                               }
+                                               } 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
                                        break;
                                case "PATH":
                                        cookie.Path = val;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to