X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FSystem.Web%2FHttpCookie.cs;h=2b4e68cf8ed8d8ad018ea72686d0fa9134cabaa0;hb=7a3dff8be5987d05481ff7c972524ca48d4cc94a;hp=f7e61e084fd9992a703d3ab6276ab479489b31ce;hpb=c4aef31eeea309e6a795c84c098ac8e1a2490340;p=mono.git diff --git a/mcs/class/System.Web/System.Web/HttpCookie.cs b/mcs/class/System.Web/System.Web/HttpCookie.cs index f7e61e084fd..2b4e68cf8ed 100644 --- a/mcs/class/System.Web/System.Web/HttpCookie.cs +++ b/mcs/class/System.Web/System.Web/HttpCookie.cs @@ -6,7 +6,7 @@ // // -// 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 @@ -32,13 +32,13 @@ using System.Text; 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)] @@ -69,14 +69,14 @@ namespace System.Web { } 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 ("="); @@ -105,7 +105,7 @@ namespace System.Web { builder.Append ("; HttpOnly"); } - return new UnknownResponseHeader ("Set-Cookie", builder.ToString()); + return builder.ToString (); } public string Domain { @@ -174,7 +174,7 @@ namespace System.Web { public string Value { get { - return values.ToString (); + return HttpUtility.UrlDecode(values.ToString ()); } set { values.Clear (); @@ -202,25 +202,32 @@ namespace System.Web { } } -#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 (""); @@ -230,17 +237,23 @@ namespace System.Web { 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; } @@ -257,12 +270,15 @@ namespace System.Web { 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); } } } - }