2008-11-03 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mcs / class / System / System.Net / Cookie.cs
index b952d3e1164ad8d7516cdd3908111cf54ab0e67b..02bd572f98d01db7aef2a8e3cbc48a76c6311197 100644 (file)
@@ -4,6 +4,7 @@
 // Authors:
 //     Lawrence Pit (loz@cable.a2000.nl)
 //     Gonzalo Paniagua Javier (gonzalo@ximian.com)
+//      Daniel Nauck    (dna(at)mono-project(dot)de)
 //
 // (c) Copyright 2004 Novell, Inc. (http://www.ximian.com)
 //
@@ -47,8 +48,11 @@ namespace System.Net {
                Uri commentUri;
                bool discard;
                string domain;
-               bool expired;
+//             bool expired;
                DateTime expires;
+#if NET_2_0            
+               bool httpOnly;
+#endif         
                string name;
                string path;
                string port;
@@ -117,11 +121,9 @@ namespace System.Net {
                                return expires <= DateTime.Now && 
                                       expires != DateTime.MinValue;
                        }
-                       set { 
-                               expired = value; 
-                               if (expired) {
+                       set {  
+                               if (value)
                                        expires = DateTime.Now;
-                               }
                        }
                }
 
@@ -130,21 +132,11 @@ namespace System.Net {
                        set { expires = value; }
                }
 
-#if NET_2_0
-               static Exception GetMustImplement ()
-               {
-                       return new NotImplementedException ();
-               }
-               
-               [MonoTODO]
+#if NET_2_0    
                public bool HttpOnly
                {
-                       get {
-                               throw GetMustImplement ();
-                       }
-                       set {
-                               throw GetMustImplement ();
-                       }
+                       get { return httpOnly; }
+                       set { httpOnly = value; }
                }
 #endif
 
@@ -194,6 +186,7 @@ namespace System.Net {
                                                throw new CookieException("The 'Port'='" + value + "' part of the cookie is invalid. Invalid value: " + values [i], e);
                                        }
                                }
+                               Version = 1;
                        }
                }
 
@@ -268,7 +261,8 @@ namespace System.Net {
 
                // returns a string that can be used to send a cookie to an Origin Server
                // i.e., only used for clients
-               // see also para 3.3.4 of RFC 1965
+               // see para 4.2.2 of RFC 2109 and para 3.3.4 of RFC 2965
+               // see also bug #316017
                public override string ToString () 
                {
                        if (name.Length == 0) 
@@ -276,22 +270,46 @@ namespace System.Net {
 
                        StringBuilder result = new StringBuilder (64);
        
-                       if (version > 0) {
-                               result.Append ("$Version=").Append (version).Append (";");
-                       }                               
+                       if (version > 0)
+                               result.Append ("$Version=").Append (version).Append ("; ");             
+                               
+                       result.Append (name).Append ("=").Append (val);
+                       
+                       if (version == 0)
+                               return result.ToString ();
+
+                       if (path != null && path.Length != 0)
+                               result.Append ("; $Path=").Append (path);
+                               
+                       if (domain != null && domain.Length != 0)
+                               result.Append ("; $Domain=").Append (domain);                   
+       
+                       if (port != null && port.Length != 0)
+                               result.Append ("; $Port=").Append (port);       
+                                               
+                       return result.ToString ();
+               }
+
+               internal string ToClientString () 
+               {
+                       if (name.Length == 0) 
+                               return String.Empty;
+
+                       StringBuilder result = new StringBuilder (64);
+       
+                       if (version > 0) 
+                               result.Append ("Version=").Append (version).Append (";");
                                
                        result.Append (name).Append ("=").Append (val);
 
-                       // in the MS.Net implementation path and domain don't show up in
-                       // the result, I guess that's a bug in their implementation...
                        if (path != null && path.Length != 0)
-                               result.Append (";$Path=").Append (QuotedString (path));
+                               result.Append (";Path=").Append (QuotedString (path));
                                
                        if (domain != null && domain.Length != 0)
-                               result.Append (";$Domain=").Append (QuotedString (domain));                     
+                               result.Append (";Domain=").Append (QuotedString (domain));                      
        
                        if (port != null && port.Length != 0)
-                               result.Append (";$Port=").Append (port);        
+                               result.Append (";Port=").Append (port); 
                                                
                        return result.ToString ();
                }