Commit
[mono.git] / mcs / class / System / System.Net / HttpWebResponse.cs
index 49fff0b0d125c34d2176535fd141d4937d72cdaa..3dc8bb97ec1cee776c1679b473e099153dda62a5 100644 (file)
@@ -4,9 +4,11 @@
 // Authors:
 //     Lawrence Pit (loz@cable.a2000.nl)
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//      Daniel Nauck    (dna(at)mono-project(dot)de)
 //
 // (c) 2002 Lawrence Pit
 // (c) 2003 Ximian, Inc. (http://www.ximian.com)
+// (c) 2008 Daniel Nauck
 //
 
 //
@@ -74,6 +76,9 @@ namespace System.Net
                        }
                }
 
+#if NET_2_0
+               [Obsolete ("Serialization is obsoleted for this type", false)]
+#endif
                protected HttpWebResponse (SerializationInfo serializationInfo, StreamingContext streamingContext)
                {
                        SerializationInfo info = serializationInfo;
@@ -166,6 +171,21 @@ namespace System.Net
                                return webHeaders; 
                        }
                }
+
+#if NET_2_0
+               static Exception GetMustImplement ()
+               {
+                       return new NotImplementedException ();
+               }
+               
+               [MonoTODO]
+               public override bool IsMutuallyAuthenticated
+               {
+                       get {
+                               throw GetMustImplement ();
+                       }
+               }
+#endif
                
                public DateTime LastModified {
                        get {
@@ -261,6 +281,15 @@ namespace System.Net
                
                void ISerializable.GetObjectData (SerializationInfo serializationInfo,
                                                  StreamingContext streamingContext)
+               {
+                       GetObjectData (serializationInfo, streamingContext);
+               }
+
+#if NET_2_0
+               protected override
+#endif
+               void GetObjectData (SerializationInfo serializationInfo,
+                                   StreamingContext streamingContext)
                {
                        SerializationInfo info = serializationInfo;
 
@@ -272,8 +301,7 @@ namespace System.Net
                        info.AddValue ("cookieCollection", cookieCollection);
                        info.AddValue ("version", version);
                        info.AddValue ("statusCode", statusCode);
-               }               
-
+               }
 
                // Cleaning up stuff
 
@@ -370,6 +398,11 @@ namespace System.Net
                                        if (cookie.Domain == "")
                                                cookie.Domain = val;
                                        break;
+#if NET_2_0
+                               case "HTTPONLY":
+                                       cookie.HttpOnly = true;
+                                       break;
+#endif
                                case "MAX-AGE": // RFC Style Set-Cookie2
                                        if (cookie.Expires == DateTime.MinValue) {
                                                try {
@@ -380,17 +413,8 @@ namespace System.Net
                                case "EXPIRES": // Netscape Style Set-Cookie
                                        if (cookie.Expires != DateTime.MinValue)
                                                break;
-                                       try {
-                                               cookie.Expires = DateTime.ParseExact (val, "r", CultureInfo.InvariantCulture);
-                                       } catch {
-                                               try { 
-                                               cookie.Expires = DateTime.ParseExact (val,
-                                                               "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'",
-                                                               CultureInfo.InvariantCulture);
-                                               } catch {
-                                                       cookie.Expires = DateTime.Now.AddDays (1);
-                                               }
-                                       }
+
+                                       cookie.Expires = TryParseCookieExpires (val);
                                        break;
                                case "PATH":
                                        cookie.Path = val;
@@ -428,6 +452,37 @@ namespace System.Net
                        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 {