2 // System.Web.HttpCookie
5 // Patrik Torstensson (Patrik.Torstensson@labs2.com)
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System
.Globalization
;
32 using System
.Collections
.Specialized
;
36 public sealed class HttpCookie
46 HttpValueCollection _Values
;
48 internal HttpCookie ()
53 public HttpCookie (string name
)
59 public HttpCookie (string name
, string value)
66 internal HttpCookie (string name
, string value, string path
, DateTime expires
)
71 if (expires
!= DateTime
.MinValue
)
75 internal HttpResponseHeader
GetCookieHeader ()
77 StringBuilder oSetCookie
= new StringBuilder ();
79 if (null != _Name
&& _Name
.Length
> 0) {
80 oSetCookie
.Append (_Name
);
81 oSetCookie
.Append ("=");
84 if (null != _Values
) {
85 oSetCookie
.Append (_Values
.ToString (false));
86 } else if (null != _Value
) {
87 oSetCookie
.Append (_Value
);
90 if (null != _Domain
&& _Domain
.Length
> 0) {
91 oSetCookie
.Append ("; domain=");
92 oSetCookie
.Append (_Domain
);
95 if (null != _Path
&& Path
.Length
> 0) {
96 oSetCookie
.Append ("; path=");
97 oSetCookie
.Append (_Path
);
100 if (_ExpiresSet
&& _Expires
!= DateTime
.MinValue
) {
101 oSetCookie
.Append ("; expires=");
102 DateTime ut
= _Expires
.ToUniversalTime ();
103 oSetCookie
.Append (ut
.ToString ("ddd, dd-MMM-yyyy HH':'mm':'ss 'GMT'",
104 DateTimeFormatInfo
.InvariantInfo
));
108 oSetCookie
.Append ("; secure");
110 return new HttpResponseHeader (HttpWorkerRequest
.HeaderSetCookie
, oSetCookie
.ToString());
115 get { return _Domain; }
116 set { _Domain = value; }
119 public DateTime Expires
123 return DateTime
.MinValue
;
137 return Values
.HasKeys ();
141 public string this [string key
]
143 get { return Values [key]; }
144 set { Values [key] = value; }
149 get { return _Name; }
150 set { _Name = value; }
155 get { return _Path; }
156 set { _Path = value; }
161 get { return _Secure; }
162 set { _Secure = value; }
169 return _Values
.ToString (false);
175 if (null != _Values
) {
177 _Values
.Add (null, value);
185 public NameValueCollection Values
188 if (null == _Values
) {
189 _Values
= new HttpValueCollection ();
190 if (null != _Value
) {
191 // Do we have multiple keys
192 if (_Value
.IndexOf ("&") >= 0 || _Value
.IndexOf ("=") >= 0) {
193 _Values
.FillFromCookieString (_Value
);
195 _Values
.Add (null, _Value
);