// 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)
//
using System;
using System.Text;
using System.Globalization;
+using System.Collections;
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;
return expires <= DateTime.Now &&
expires != DateTime.MinValue;
}
- set {
- expired = value;
- if (expired) {
+ set {
+ if (value)
expires = DateTime.Now;
- }
}
}
set { expires = value; }
}
+#if NET_2_0
+ public bool HttpOnly
+ {
+ get { return httpOnly; }
+ set { httpOnly = value; }
+ }
+#endif
+
public string Name {
get { return name; }
set {
}
public string Path {
- get { return (path == null || path == "") ? "/" : path; }
+ get { return (path == null || path == "") ? String.Empty : path; }
set { path = (value == null) ? String.Empty : value; }
}
throw new CookieException("The 'Port'='" + value + "' part of the cookie is invalid. Invalid value: " + values [i], e);
}
}
+ Version = 1;
}
}
public override int GetHashCode ()
{
- return hash(name.ToLower ().GetHashCode (),
+ return hash(CaseInsensitiveHashCodeProvider.DefaultInvariant.GetHashCode(name),
val.GetHashCode (),
Path.GetHashCode (),
- domain.ToLower ().GetHashCode (),
+ CaseInsensitiveHashCodeProvider.DefaultInvariant.GetHashCode (domain),
version);
}
// 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)
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 ();
}