//
//
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2009 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
using System.Collections.Specialized;
using System.Security.Permissions;
-namespace System.Web {
-
+namespace System.Web
+{
[Flags]
internal enum CookieFlags : byte {
Secure = 1,
- HttpOnly = 2
- }
+ HttpOnly = 2
+ }
// CAS - no InheritanceDemand here as the class is sealed
[AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
}
public HttpCookie (string name, string value)
- : this (name)
+ : this (name)
{
Value = value;
}
- internal BaseResponseHeader GetCookieHeader ()
+ internal string GetCookieHeaderValue ()
{
- StringBuilder builder = new StringBuilder ("");
+ StringBuilder builder = new StringBuilder ();
builder.Append (name);
builder.Append ("=");
builder.Append ("; HttpOnly");
}
- return new UnknownResponseHeader ("Set-Cookie", builder.ToString());
+ return builder.ToString ();
}
public string Domain {
public string Value {
get {
- return values.ToString ();
+ return HttpUtility.UrlDecode(values.ToString ());
}
set {
values.Clear ();
}
}
-#if NET_2_0
public bool HttpOnly {
get {
return (flags & CookieFlags.HttpOnly) == CookieFlags.HttpOnly;
}
set {
- flags |= CookieFlags.HttpOnly;
+ if (value)
+ flags |= CookieFlags.HttpOnly;
+ else
+ flags &= ~CookieFlags.HttpOnly;
}
}
-#endif
/*
* simple utility class that just overrides ToString
* to get the desired behavior for
* HttpCookie.Values
*/
- class CookieNVC : NameValueCollection
+ [Serializable]
+ sealed class CookieNVC : NameValueCollection
{
+ public CookieNVC ()
+ : base (StringComparer.OrdinalIgnoreCase)
+ {
+ }
+
public override string ToString ()
{
StringBuilder builder = new StringBuilder ("");
if (!first_key)
builder.Append ("&");
- bool first_val = true;
- foreach (string v in GetValues (key)) {
- if (!first_val)
- builder.Append ("&");
-
- if (key != null) {
- builder.Append (key);
- builder.Append ("=");
- }
- builder.Append (v);
- first_val = false;
+ string[] vals = GetValues (key);
+ if(vals == null)
+ vals = new string[1] {String.Empty};
+
+ bool first_val = true;
+ foreach (string v in vals) {
+ if (!first_val)
+ builder.Append ("&");
+
+ if (key != null && key.Length > 0) {
+ builder.Append (HttpUtility.UrlEncode(key));
+ builder.Append ("=");
+ }
+ if(v != null && v.Length > 0)
+ builder.Append (HttpUtility.UrlEncode(v));
+
+ first_val = false;
}
first_key = false;
}
if (this.IsReadOnly)
throw new NotSupportedException ("Collection is read-only");
- if (name == null)
+ if (name == null) {
Clear();
+ name = string.Empty;
+ }
+// if (value == null)
+// value = string.Empty;
base.Set (name, value);
}
}
}
-
}