Fix for issue #15
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
|
||||
// Daniel Nauck (dna@mono-project.de)
|
||||
// Sebastien Pouliot (sebastien@ximian.com)
|
||||
// sta (sta.blockhead@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2004,2009 Novell, Inc (http://www.novell.com)
|
||||
// Copyright (c) 2012-2013 sta.blockhead (sta.blockhead@gmail.com)
|
||||
@@ -241,6 +242,22 @@ namespace WebSocketSharp.Net {
|
||||
|
||||
internal bool ExactDomain { get; set; }
|
||||
|
||||
internal int MaxAge {
|
||||
get {
|
||||
if (expires == DateTime.MinValue || Expired)
|
||||
return 0;
|
||||
|
||||
var tmp = expires.Kind == DateTimeKind.Local
|
||||
? expires
|
||||
: expires.ToLocalTime ();
|
||||
|
||||
var span = tmp - DateTime.Now;
|
||||
return span <= TimeSpan.Zero
|
||||
? 0
|
||||
: (int) span.TotalSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
internal int [] Ports {
|
||||
get { return ports; }
|
||||
}
|
||||
@@ -308,16 +325,17 @@ namespace WebSocketSharp.Net {
|
||||
/// Gets or sets a value indicating whether the cookie has expired.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// <c>true</c> if the cookie has expired; otherwise, <c>false</c>.
|
||||
/// <c>true</c> if the cookie has expired; otherwise, <c>false</c>. The default is <c>false</c>.
|
||||
/// </value>
|
||||
public bool Expired {
|
||||
get {
|
||||
return expires <= DateTime.Now &&
|
||||
expires != DateTime.MinValue;
|
||||
}
|
||||
set {
|
||||
if (value)
|
||||
expires = DateTime.Now;
|
||||
set {
|
||||
expires = value
|
||||
? DateTime.Now
|
||||
: DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -326,6 +344,7 @@ namespace WebSocketSharp.Net {
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="DateTime"/> that contains the date and time at which the cookie expires.
|
||||
/// The default is <see cref="DateTime.MinValue"/>.
|
||||
/// </value>
|
||||
public DateTime Expires {
|
||||
get { return expires; }
|
||||
@@ -390,7 +409,7 @@ namespace WebSocketSharp.Net {
|
||||
/// A <see cref="string"/> that contains a list of the TCP ports to which the cookie applies.
|
||||
/// </value>
|
||||
/// <exception cref="CookieException">
|
||||
/// The value specified for a set operation could not be parsed or is not enclosed in double quotes.
|
||||
/// The value specified for a set operation is not enclosed in double quotes or could not be parsed.
|
||||
/// </exception>
|
||||
public string Port {
|
||||
get { return port; }
|
||||
@@ -402,11 +421,13 @@ namespace WebSocketSharp.Net {
|
||||
}
|
||||
|
||||
if (!value.IsEnclosedIn ('"'))
|
||||
throw new CookieException ("The 'Port'='" + value + "' attribute of the cookie is invalid. Port must be enclosed in double quotes.");
|
||||
throw new CookieException (String.Format (
|
||||
"The 'Port={0}' attribute of the cookie is invalid. The value must be enclosed in double quotes.", value));
|
||||
|
||||
string error;
|
||||
if (!TryCreatePorts (value, out ports, out error))
|
||||
throw new CookieException ("The 'Port'='" + value + "' attribute of the cookie is invalid. Invalid value: " + error);
|
||||
throw new CookieException (String.Format (
|
||||
"The 'Port={0}' attribute of the cookie is invalid. Invalid value: {1}", value, error));
|
||||
|
||||
port = value;
|
||||
}
|
||||
@@ -472,13 +493,13 @@ namespace WebSocketSharp.Net {
|
||||
/// to which the cookie conforms.
|
||||
/// </value>
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// The value specified for a set operation is less than zero.
|
||||
/// The value specified for a set operation is not allowed. The value must be 0 or 1.
|
||||
/// </exception>
|
||||
public int Version {
|
||||
get { return version; }
|
||||
set {
|
||||
if (value < 0)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
if (value < 0 || value > 1)
|
||||
throw new ArgumentOutOfRangeException ("value", "Must be 0 or 1.");
|
||||
else
|
||||
version = value;
|
||||
}
|
||||
@@ -536,6 +557,61 @@ namespace WebSocketSharp.Net {
|
||||
return "\"" + value.Replace("\"", "\\\"") + "\"";
|
||||
}
|
||||
|
||||
string ToResponseStringVersion0 ()
|
||||
{
|
||||
var result = new StringBuilder ();
|
||||
result.AppendFormat ("{0}={1}", name, val);
|
||||
if (expires != DateTime.MinValue)
|
||||
result.AppendFormat ("; Expires={0}",
|
||||
expires.ToUniversalTime ().ToString ("ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'",
|
||||
CultureInfo.CreateSpecificCulture("en-US")));
|
||||
|
||||
if (!path.IsNullOrEmpty ())
|
||||
result.AppendFormat ("; Path={0}", path);
|
||||
|
||||
if (!domain.IsNullOrEmpty ())
|
||||
result.AppendFormat ("; Domain={0}", domain);
|
||||
|
||||
if (secure)
|
||||
result.Append ("; Secure");
|
||||
|
||||
if (httpOnly)
|
||||
result.Append ("; HttpOnly");
|
||||
|
||||
return result.ToString ();
|
||||
}
|
||||
|
||||
string ToResponseStringVersion1 ()
|
||||
{
|
||||
var result = new StringBuilder ();
|
||||
result.AppendFormat ("{0}={1}; Version={2}", name, val, version);
|
||||
if (expires != DateTime.MinValue)
|
||||
result.AppendFormat ("; Max-Age={0}", MaxAge);
|
||||
|
||||
if (!path.IsNullOrEmpty ())
|
||||
result.AppendFormat ("; Path={0}", path);
|
||||
|
||||
if (!domain.IsNullOrEmpty ())
|
||||
result.AppendFormat ("; Domain={0}", domain);
|
||||
|
||||
if (!port.IsNullOrEmpty ())
|
||||
result.AppendFormat ("; Port={0}", port);
|
||||
|
||||
if (!comment.IsNullOrEmpty ())
|
||||
result.AppendFormat ("; Comment={0}", comment.UrlEncode ());
|
||||
|
||||
if (!commentUri.IsNull ())
|
||||
result.AppendFormat ("; CommentURL={0}", Quote (commentUri.OriginalString));
|
||||
|
||||
if (discard)
|
||||
result.Append ("; Discard");
|
||||
|
||||
if (secure)
|
||||
result.Append ("; Secure");
|
||||
|
||||
return result.ToString ();
|
||||
}
|
||||
|
||||
static bool TryCreatePorts (string value, out int [] result, out string parseError)
|
||||
{
|
||||
var values = value.Trim ('"').Split (',');
|
||||
@@ -562,60 +638,44 @@ namespace WebSocketSharp.Net {
|
||||
|
||||
#region Internal Methods
|
||||
|
||||
// From server to client
|
||||
internal string ToClientString ()
|
||||
{
|
||||
if (name.IsEmpty ())
|
||||
return String.Empty;
|
||||
|
||||
var result = new StringBuilder (64);
|
||||
if (version > 0)
|
||||
result.Append ("Version=").Append (version).Append ("; ");
|
||||
|
||||
result.Append (name).Append ("=").Append (Quote (val));
|
||||
if (!path.IsNullOrEmpty ())
|
||||
result.Append ("; Path=").Append (path);
|
||||
|
||||
if (!domain.IsNullOrEmpty ())
|
||||
result.Append ("; Domain=").Append (domain);
|
||||
|
||||
if (!port.IsNullOrEmpty ())
|
||||
result.Append ("; Port=").Append (port);
|
||||
|
||||
return result.ToString ();
|
||||
}
|
||||
|
||||
// From client to server
|
||||
internal string ToString (Uri uri)
|
||||
internal string ToRequestString (Uri uri)
|
||||
{
|
||||
if (name.IsEmpty ())
|
||||
return String.Empty;
|
||||
|
||||
var result = new StringBuilder (64);
|
||||
if (version > 0)
|
||||
result.Append ("$Version=").Append (version).Append ("; ");
|
||||
|
||||
result.Append (name).Append ("=").Append (val);
|
||||
if (version == 0)
|
||||
return result.ToString ();
|
||||
return String.Format ("{0}={1}", name, val);
|
||||
|
||||
var result = new StringBuilder ();
|
||||
result.AppendFormat ("$Version={0}; {1}={2}", version, name, val);
|
||||
if (!path.IsNullOrEmpty ())
|
||||
result.Append ("; $Path=").Append (path);
|
||||
result.AppendFormat ("; $Path={0}", path);
|
||||
else if (!uri.IsNull ())
|
||||
result.Append ("; $Path=").Append (uri.GetAbsolutePath ());
|
||||
result.AppendFormat ("; $Path={0}", uri.GetAbsolutePath ());
|
||||
else
|
||||
result.Append ("; $Path=/");
|
||||
|
||||
bool append_domain = uri.IsNull () || uri.Host != domain;
|
||||
if (append_domain && !domain.IsNullOrEmpty ())
|
||||
result.Append ("; $Domain=").Append (domain);
|
||||
result.AppendFormat ("; $Domain={0}", domain);
|
||||
|
||||
if (!port.IsNullOrEmpty ())
|
||||
result.Append ("; $Port=").Append (port);
|
||||
result.AppendFormat ("; $Port={0}", port);
|
||||
|
||||
return result.ToString ();
|
||||
}
|
||||
|
||||
// From server to client
|
||||
internal string ToResponseString ()
|
||||
{
|
||||
return name.IsEmpty ()
|
||||
? String.Empty
|
||||
: version == 0
|
||||
? ToResponseStringVersion0 ()
|
||||
: ToResponseStringVersion1 ();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
@@ -634,11 +694,11 @@ namespace WebSocketSharp.Net {
|
||||
{
|
||||
var cookie = comparand as Cookie;
|
||||
return !cookie.IsNull() &&
|
||||
String.Compare (this.name, cookie.Name, true, CultureInfo.InvariantCulture) == 0 &&
|
||||
String.Compare (this.val, cookie.Value, false, CultureInfo.InvariantCulture) == 0 &&
|
||||
String.Compare (this.path, cookie.Path, false, CultureInfo.InvariantCulture) == 0 &&
|
||||
String.Compare (this.domain, cookie.Domain, true, CultureInfo.InvariantCulture) == 0 &&
|
||||
this.version == cookie.Version;
|
||||
name.Equals (cookie.Name, StringComparison.InvariantCultureIgnoreCase) &&
|
||||
val.Equals (cookie.Value, StringComparison.InvariantCulture) &&
|
||||
path.Equals (cookie.Path, StringComparison.InvariantCulture) &&
|
||||
domain.Equals (cookie.Domain, StringComparison.InvariantCultureIgnoreCase) &&
|
||||
version == cookie.Version;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -671,7 +731,7 @@ namespace WebSocketSharp.Net {
|
||||
// i.e., only used for clients
|
||||
// see para 4.2.2 of RFC 2109 and para 3.3.4 of RFC 2965
|
||||
// see also bug #316017
|
||||
return ToString (null);
|
||||
return ToRequestString (null);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@@ -5,7 +5,8 @@
|
||||
// Authors:
|
||||
// Lawrence Pit (loz@cable.a2000.nl)
|
||||
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
|
||||
// Sebastien Pouliot <sebastien@ximian.com>
|
||||
// Sebastien Pouliot (sebastien@ximian.com)
|
||||
// sta (sta.blockhead@gmail.com)
|
||||
//
|
||||
// Copyright (c) 2004,2009 Novell, Inc (http://www.novell.com)
|
||||
// Copyright (c) 2012-2013 sta.blockhead (sta.blockhead@gmail.com)
|
||||
@@ -34,7 +35,9 @@ using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
|
||||
namespace WebSocketSharp.Net {
|
||||
|
||||
@@ -90,6 +93,16 @@ namespace WebSocketSharp.Net {
|
||||
get { return list; }
|
||||
}
|
||||
|
||||
internal IEnumerable<Cookie> Sorted {
|
||||
get {
|
||||
return from cookie in list
|
||||
orderby cookie.Version,
|
||||
cookie.Name,
|
||||
cookie.Path.Length descending
|
||||
select cookie;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Properties
|
||||
@@ -137,7 +150,7 @@ namespace WebSocketSharp.Net {
|
||||
/// A <see cref="Cookie"/> with the specified <paramref name="index"/> in the <see cref="CookieCollection"/>.
|
||||
/// </value>
|
||||
/// <param name="index">
|
||||
/// An <see cref="int"/> that is the zero-based index of the <see cref="Cookie"/> to find.
|
||||
/// An <see cref="int"/> is the zero-based index of the <see cref="Cookie"/> to find.
|
||||
/// </param>
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// <paramref name="index"/> is less than zero or <paramref name="index"/> is greater than or
|
||||
@@ -159,7 +172,7 @@ namespace WebSocketSharp.Net {
|
||||
/// A <see cref="Cookie"/> with the specified <paramref name="name"/> in the <see cref="CookieCollection"/>.
|
||||
/// </value>
|
||||
/// <param name="name">
|
||||
/// A <see cref="string"/> that is the name of the <see cref="Cookie"/> to find.
|
||||
/// A <see cref="string"/> is the name of the <see cref="Cookie"/> to find.
|
||||
/// </param>
|
||||
/// <exception cref="ArgumentNullException">
|
||||
/// <paramref name="name"/> is <see langword="null"/>.
|
||||
@@ -170,7 +183,7 @@ namespace WebSocketSharp.Net {
|
||||
throw new ArgumentNullException ("name");
|
||||
|
||||
foreach (var cookie in list) {
|
||||
if (0 == String.Compare (cookie.Name, name, true, CultureInfo.InvariantCulture))
|
||||
if (cookie.Name.Equals (name, StringComparison.InvariantCultureIgnoreCase))
|
||||
return cookie;
|
||||
}
|
||||
|
||||
@@ -197,24 +210,179 @@ namespace WebSocketSharp.Net {
|
||||
|
||||
#region Private Method
|
||||
|
||||
static CookieCollection ParseRequest (string value)
|
||||
{
|
||||
var cookies = new CookieCollection ();
|
||||
|
||||
Cookie cookie = null;
|
||||
int version = 0;
|
||||
string [] pairs = value.Split (',', ';');
|
||||
for (int i = 0; i < pairs.Length; i++)
|
||||
{
|
||||
string pair = pairs [i].Trim ();
|
||||
if (pair.IsEmpty ())
|
||||
continue;
|
||||
|
||||
if (pair.StartsWith ("$version", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
version = Int32.Parse (pair.GetValueInternal ("=").Trim ('"'));
|
||||
}
|
||||
else if (pair.StartsWith ("$path", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!cookie.IsNull ())
|
||||
cookie.Path = pair.GetValueInternal ("=");
|
||||
}
|
||||
else if (pair.StartsWith ("$domain", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!cookie.IsNull ())
|
||||
cookie.Domain = pair.GetValueInternal ("=");
|
||||
}
|
||||
else if (pair.StartsWith ("$port", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!pair.Equals ("$port", StringComparison.InvariantCultureIgnoreCase) && !pair.EndsWith ("\"")) {
|
||||
var buffer = new StringBuilder (pair);
|
||||
string port;
|
||||
while (i < pairs.Length - 1) {
|
||||
port = pairs [++i].Trim ();
|
||||
buffer.AppendFormat (", {0}", port);
|
||||
if (port.EndsWith ("\""))
|
||||
break;
|
||||
}
|
||||
|
||||
pair = buffer.ToString ();
|
||||
}
|
||||
|
||||
if (!cookie.IsNull ())
|
||||
cookie.Port = pair.GetValueInternal ("=");
|
||||
}
|
||||
else {
|
||||
if (!cookie.IsNull ())
|
||||
cookies.Add (cookie);
|
||||
|
||||
cookie = new Cookie (pair.GetNameInternal ("="), pair.GetValueInternal ("="));
|
||||
if (version != 0)
|
||||
cookie.Version = version;
|
||||
}
|
||||
}
|
||||
|
||||
if (!cookie.IsNull ())
|
||||
cookies.Add (cookie);
|
||||
|
||||
return cookies;
|
||||
}
|
||||
|
||||
static CookieCollection ParseResponse (string value)
|
||||
{
|
||||
var cookies = new CookieCollection ();
|
||||
|
||||
Cookie cookie = null;
|
||||
string [] pairs = value.Split (',', ';');
|
||||
for (int i = 0; i < pairs.Length; i++)
|
||||
{
|
||||
string pair = pairs [i].Trim ();
|
||||
if (pair.IsEmpty ())
|
||||
continue;
|
||||
|
||||
if (pair.StartsWith ("version", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!cookie.IsNull ())
|
||||
cookie.Version = Int32.Parse (pair.GetValueInternal ("=").Trim ('"'));
|
||||
}
|
||||
else if (pair.StartsWith ("expires", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
var buffer = new StringBuilder (pair.GetValueInternal ("="));
|
||||
if (i < pairs.Length - 1)
|
||||
buffer.AppendFormat (", {0}", pairs [++i].Trim ());
|
||||
|
||||
DateTime expires;
|
||||
if (!DateTime.TryParseExact (buffer.ToString (),
|
||||
new string [] { "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'", "r" },
|
||||
CultureInfo.CreateSpecificCulture("en-US"),
|
||||
DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal,
|
||||
out expires))
|
||||
expires = DateTime.Now;
|
||||
|
||||
if (!cookie.IsNull () && cookie.Expires == DateTime.MinValue)
|
||||
cookie.Expires = expires.ToLocalTime ();
|
||||
}
|
||||
else if (pair.StartsWith ("max-age", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
int max = Int32.Parse (pair.GetValueInternal ("=").Trim ('"'));
|
||||
var expires = DateTime.Now.AddSeconds ((double) max);
|
||||
if (!cookie.IsNull ())
|
||||
cookie.Expires = expires;
|
||||
}
|
||||
else if (pair.StartsWith ("path", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!cookie.IsNull ())
|
||||
cookie.Path = pair.GetValueInternal ("=");
|
||||
}
|
||||
else if (pair.StartsWith ("domain", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!cookie.IsNull ())
|
||||
cookie.Domain = pair.GetValueInternal ("=");
|
||||
}
|
||||
else if (pair.StartsWith ("port", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!pair.Equals ("port", StringComparison.InvariantCultureIgnoreCase) && !pair.EndsWith ("\"")) {
|
||||
var buffer = new StringBuilder (pair);
|
||||
string port;
|
||||
while (i < pairs.Length - 1) {
|
||||
port = pairs [++i].Trim ();
|
||||
buffer.AppendFormat (", {0}", port);
|
||||
if (port.EndsWith ("\""))
|
||||
break;
|
||||
}
|
||||
|
||||
pair = buffer.ToString ();
|
||||
}
|
||||
|
||||
if (!cookie.IsNull ())
|
||||
cookie.Port = pair.GetValueInternal ("=");
|
||||
}
|
||||
else if (pair.StartsWith ("comment", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!cookie.IsNull ())
|
||||
cookie.Comment = pair.GetValueInternal ("=").UrlDecode ();
|
||||
}
|
||||
else if (pair.StartsWith ("commenturl", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!cookie.IsNull ())
|
||||
cookie.CommentUri = pair.GetValueInternal ("=").Trim ('"').ToUri ();
|
||||
}
|
||||
else if (pair.StartsWith ("discard", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!cookie.IsNull ())
|
||||
cookie.Discard = true;
|
||||
}
|
||||
else if (pair.StartsWith ("secure", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!cookie.IsNull ())
|
||||
cookie.Secure = true;
|
||||
}
|
||||
else if (pair.StartsWith ("httponly", StringComparison.InvariantCultureIgnoreCase)) {
|
||||
if (!cookie.IsNull ())
|
||||
cookie.HttpOnly = true;
|
||||
}
|
||||
else {
|
||||
if (!cookie.IsNull ())
|
||||
cookies.Add (cookie);
|
||||
|
||||
cookie = new Cookie (pair.GetNameInternal ("="), pair.GetValueInternal ("="));
|
||||
}
|
||||
}
|
||||
|
||||
if (!cookie.IsNull ())
|
||||
cookies.Add (cookie);
|
||||
|
||||
return cookies;
|
||||
}
|
||||
|
||||
int SearchCookie (Cookie cookie)
|
||||
{
|
||||
string name = cookie.Name;
|
||||
string domain = cookie.Domain;
|
||||
string path = cookie.Path;
|
||||
string domain = cookie.Domain;
|
||||
int version = cookie.Version;
|
||||
|
||||
for (int i = list.Count - 1; i >= 0; i--) {
|
||||
Cookie c = list [i];
|
||||
if (0 != String.Compare (name, c.Name, true, CultureInfo.InvariantCulture))
|
||||
if (!c.Name.Equals (name, StringComparison.InvariantCultureIgnoreCase))
|
||||
continue;
|
||||
|
||||
if (0 != String.Compare (domain, c.Domain, true, CultureInfo.InvariantCulture))
|
||||
if (!c.Path.Equals (path, StringComparison.InvariantCulture))
|
||||
continue;
|
||||
|
||||
if (0 != String.Compare (path, c.Path, false, CultureInfo.InvariantCulture))
|
||||
if (!c.Domain.Equals (domain, StringComparison.InvariantCultureIgnoreCase))
|
||||
continue;
|
||||
|
||||
if (c.Version != cookie.Version)
|
||||
if (c.Version != version)
|
||||
continue;
|
||||
|
||||
return i;
|
||||
@@ -227,6 +395,34 @@ namespace WebSocketSharp.Net {
|
||||
|
||||
#region Internal Method
|
||||
|
||||
internal static CookieCollection Parse (string value, bool response)
|
||||
{
|
||||
return response
|
||||
? ParseResponse (value)
|
||||
: ParseRequest (value);
|
||||
}
|
||||
|
||||
internal void SetOrRemove (Cookie cookie)
|
||||
{
|
||||
int pos = SearchCookie (cookie);
|
||||
if (pos == -1) {
|
||||
if (!cookie.Expired)
|
||||
list.Add (cookie);
|
||||
}
|
||||
else {
|
||||
if (!cookie.Expired)
|
||||
list [pos] = cookie;
|
||||
else
|
||||
list.RemoveAt (pos);
|
||||
}
|
||||
}
|
||||
|
||||
internal void SetOrRemove (CookieCollection cookies)
|
||||
{
|
||||
foreach (Cookie cookie in cookies)
|
||||
SetOrRemove (cookie);
|
||||
}
|
||||
|
||||
internal void Sort ()
|
||||
{
|
||||
if (list.Count > 0)
|
||||
@@ -281,7 +477,7 @@ namespace WebSocketSharp.Net {
|
||||
/// starting at the specified <paramref name="index"/> in the <paramref name="array"/>.
|
||||
/// </summary>
|
||||
/// <param name="array">
|
||||
/// An <see cref="Array"/> that is the destination of the elements copied from the <see cref="CookieCollection"/>.
|
||||
/// An <see cref="Array"/> is the destination of the elements copied from the <see cref="CookieCollection"/>.
|
||||
/// </param>
|
||||
/// <param name="index">
|
||||
/// An <see cref="int"/> that indicates the zero-based index in <paramref name="array"/> at which copying begins.
|
||||
@@ -292,6 +488,22 @@ namespace WebSocketSharp.Net {
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// <paramref name="index"/> is less than zero.
|
||||
/// </exception>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// <para>
|
||||
/// <paramref name="array"/> is multidimensional.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// -or-
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The number of elements in the <see cref="CookieCollection"/> is greater than the available space
|
||||
/// from index to the end of the destination <paramref name="array"/>.
|
||||
/// </para>
|
||||
/// </exception>
|
||||
/// <exception cref="InvalidCastException">
|
||||
/// The elements in the <see cref="CookieCollection"/> cannot be cast automatically
|
||||
/// to the type of the destination <paramref name="array"/>.
|
||||
/// </exception>
|
||||
public void CopyTo (Array array, int index)
|
||||
{
|
||||
if (array.IsNull ())
|
||||
@@ -300,7 +512,16 @@ namespace WebSocketSharp.Net {
|
||||
if (index < 0)
|
||||
throw new ArgumentOutOfRangeException ("index", "Must not be less than zero.");
|
||||
|
||||
// TODO: Support for ArgumentException and InvalidCastException.
|
||||
if (array.Rank > 1)
|
||||
throw new ArgumentException ("Must not be multidimensional.", "array");
|
||||
|
||||
if (array.Length - index < list.Count)
|
||||
throw new ArgumentException (
|
||||
"The number of elements in this collection is greater than the available space of the destination array.");
|
||||
|
||||
if (!array.GetType ().GetElementType ().IsAssignableFrom (typeof (Cookie)))
|
||||
throw new InvalidCastException (
|
||||
"The elements in this collection cannot be cast automatically to the type of the destination array.");
|
||||
|
||||
(list as IList).CopyTo (array, index);
|
||||
}
|
||||
@@ -310,7 +531,7 @@ namespace WebSocketSharp.Net {
|
||||
/// starting at the specified <paramref name="index"/> in the <paramref name="array"/>.
|
||||
/// </summary>
|
||||
/// <param name="array">
|
||||
/// An array of <see cref="Cookie"/> that is the destination of the elements copied from the <see cref="CookieCollection"/>.
|
||||
/// An array of <see cref="Cookie"/> is the destination of the elements copied from the <see cref="CookieCollection"/>.
|
||||
/// </param>
|
||||
/// <param name="index">
|
||||
/// An <see cref="int"/> that indicates the zero-based index in <paramref name="array"/> at which copying begins.
|
||||
@@ -321,6 +542,10 @@ namespace WebSocketSharp.Net {
|
||||
/// <exception cref="ArgumentOutOfRangeException">
|
||||
/// <paramref name="index"/> is less than zero.
|
||||
/// </exception>
|
||||
/// <exception cref="ArgumentException">
|
||||
/// The number of elements in the <see cref="CookieCollection"/> is greater than the available space
|
||||
/// from index to the end of the destination <paramref name="array"/>.
|
||||
/// </exception>
|
||||
public void CopyTo (Cookie [] array, int index)
|
||||
{
|
||||
if (array.IsNull ())
|
||||
@@ -329,7 +554,9 @@ namespace WebSocketSharp.Net {
|
||||
if (index < 0)
|
||||
throw new ArgumentOutOfRangeException ("index", "Must not be less than zero.");
|
||||
|
||||
// TODO: Support for ArgumentException.
|
||||
if (array.Length - index < list.Count)
|
||||
throw new ArgumentException (
|
||||
"The number of elements in this collection is greater than the available space of the destination array.");
|
||||
|
||||
list.CopyTo (array, index);
|
||||
}
|
||||
|
@@ -555,7 +555,7 @@ namespace WebSocketSharp.Net {
|
||||
|
||||
if (cookies != null) {
|
||||
foreach (Cookie cookie in cookies)
|
||||
headers.SetInternal ("Set-Cookie", cookie.ToClientString (), true);
|
||||
headers.SetInternal ("Set-Cookie", cookie.ToResponseString (), true);
|
||||
}
|
||||
|
||||
StreamWriter writer = new StreamWriter (ms, encoding, 256);
|
||||
|
@@ -43,6 +43,7 @@ namespace WebSocketSharp.Net.WebSockets {
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private CookieCollection _cookies;
|
||||
private TcpClient _tcpClient;
|
||||
private bool _isSecure;
|
||||
private RequestHandshake _request;
|
||||
@@ -80,14 +81,14 @@ namespace WebSocketSharp.Net.WebSockets {
|
||||
/// Gets the cookies used in the WebSocket opening handshake.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// A <see cref="WebSocketSharp.Net.CookieCollection"/> that contains the cookies.
|
||||
/// A <see cref="CookieCollection"/> that contains the cookies.
|
||||
/// </value>
|
||||
/// <exception cref="NotImplementedException">
|
||||
/// This property is not implemented.
|
||||
/// </exception>
|
||||
public override CookieCollection CookieCollection {
|
||||
get {
|
||||
throw new NotImplementedException();
|
||||
if (_cookies.IsNull())
|
||||
_cookies = _request.Cookies;
|
||||
|
||||
return _cookies;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user