Refactored Ext.cs

This commit is contained in:
sta 2014-08-11 21:45:18 +09:00
parent aedefc1391
commit decddde20a
3 changed files with 237 additions and 285 deletions

View File

@ -51,11 +51,11 @@ using WebSocketSharp.Server;
namespace WebSocketSharp
{
/// <summary>
/// Provides a set of static methods for the websocket-sharp.
/// Provides a set of static methods for websocket-sharp.
/// </summary>
public static class Ext
{
#region Private Const Fields
#region Private Fields
private const string _tspecials = "()<>@,;:\\\"/[]?={} \t";
@ -63,16 +63,15 @@ namespace WebSocketSharp
#region Private Methods
private static byte [] compress (this byte [] value)
private static byte[] compress (this byte[] data)
{
if (value.LongLength == 0)
if (data.LongLength == 0)
//return new Byte[] { 0x00, 0x00, 0x00, 0xff, 0xff };
return value;
return data;
using (var input = new MemoryStream (value)) {
using (var input = new MemoryStream (data))
return input.compressToArray ();
}
}
private static MemoryStream compress (this Stream stream)
{
@ -92,21 +91,20 @@ namespace WebSocketSharp
private static byte[] compressToArray (this Stream stream)
{
using (var comp = stream.compress ()) {
comp.Close ();
return comp.ToArray ();
using (var output = stream.compress ()) {
output.Close ();
return output.ToArray ();
}
}
private static byte [] decompress (this byte [] value)
private static byte[] decompress (this byte[] data)
{
if (value.LongLength == 0)
return value;
if (data.LongLength == 0)
return data;
using (var input = new MemoryStream (value)) {
using (var input = new MemoryStream (data))
return input.decompressToArray ();
}
}
private static MemoryStream decompress (this Stream stream)
{
@ -123,9 +121,9 @@ namespace WebSocketSharp
private static byte[] decompressToArray (this Stream stream)
{
using (var decomp = stream.decompress ()) {
decomp.Close ();
return decomp.ToArray ();
using (var output = stream.decompress ()) {
output.Close ();
return output.ToArray ();
}
}
@ -171,23 +169,23 @@ namespace WebSocketSharp
internal static byte[] Append (this ushort code, string reason)
{
using (var buffer = new MemoryStream ()) {
using (var buff = new MemoryStream ()) {
var tmp = code.ToByteArrayInternally (ByteOrder.Big);
buffer.Write (tmp, 0, 2);
buff.Write (tmp, 0, 2);
if (reason != null && reason.Length > 0) {
tmp = Encoding.UTF8.GetBytes (reason);
buffer.Write (tmp, 0, tmp.Length);
buff.Write (tmp, 0, tmp.Length);
}
buffer.Close ();
return buffer.ToArray ();
buff.Close ();
return buff.ToArray ();
}
}
internal static string CheckIfCanRead (this Stream stream)
{
return stream == null
? "'stream' must not be null."
? "'stream' is null."
: !stream.CanRead
? "'stream' cannot be read."
: null;
@ -250,7 +248,7 @@ namespace WebSocketSharp
internal static string CheckIfValidControlData (this byte[] data, string paramName)
{
return data.Length > 125
? String.Format ("'{0}' length must be less.", paramName)
? String.Format ("'{0}' is greater than the allowable size.", paramName)
: null;
}
@ -267,39 +265,39 @@ namespace WebSocketSharp
internal static string CheckIfValidSendData (this byte[] data)
{
return data == null
? "'data' must not be null."
? "'data' is null."
: null;
}
internal static string CheckIfValidSendData (this FileInfo file)
{
return file == null
? "'file' must not be null."
? "'file' is null."
: null;
}
internal static string CheckIfValidSendData (this string data)
{
return data == null
? "'data' must not be null."
? "'data' is null."
: null;
}
internal static string CheckIfValidServicePath (this string servicePath)
{
return servicePath == null || servicePath.Length == 0
? "'servicePath' must not be null or empty."
? "'servicePath' is null or empty."
: servicePath[0] != '/'
? "'servicePath' not absolute path."
? "'servicePath' isn't absolute path."
: servicePath.IndexOfAny (new[] {'?', '#'}) != -1
? "'servicePath' must not contain either or both query and fragment components."
? "'servicePath' contains either or both query and fragment components."
: null;
}
internal static string CheckIfValidSessionID (this string id)
{
return id == null || id.Length == 0
? "'id' must not be null or empty."
? "'id' is null or empty."
: null;
}
@ -316,11 +314,11 @@ namespace WebSocketSharp
response.Close (HttpStatusCode.Unauthorized);
}
internal static byte [] Compress (this byte [] value, CompressionMethod method)
internal static byte[] Compress (this byte[] data, CompressionMethod method)
{
return method == CompressionMethod.Deflate
? value.compress ()
: value;
? data.compress ()
: data;
}
internal static Stream Compress (this Stream stream, CompressionMethod method)
@ -351,13 +349,13 @@ namespace WebSocketSharp
var len = values.Length;
Func<int, bool> contains = null;
contains = index => {
if (index < len - 1) {
for (var i = index + 1; i < len; i++)
if (values [i] == values [index])
contains = idx => {
if (idx < len - 1) {
for (var i = idx + 1; i < len; i++)
if (values[i] == values[idx])
return true;
return contains (++index);
return contains (++idx);
}
return false;
@ -382,21 +380,20 @@ namespace WebSocketSharp
internal static void CopyTo (this Stream src, Stream dest, bool setDefaultPosition)
{
var readLen = 0;
var bufferLen = 256;
var buffer = new byte [bufferLen];
while ((readLen = src.Read (buffer, 0, bufferLen)) > 0) {
dest.Write (buffer, 0, readLen);
}
var buffLen = 256;
var buff = new byte[buffLen];
while ((readLen = src.Read (buff, 0, buffLen)) > 0)
dest.Write (buff, 0, readLen);
if (setDefaultPosition)
dest.Position = 0;
}
internal static byte [] Decompress (this byte [] value, CompressionMethod method)
internal static byte[] Decompress (this byte[] data, CompressionMethod method)
{
return method == CompressionMethod.Deflate
? value.decompress ()
: value;
? data.decompress ()
: data;
}
internal static Stream Decompress (this Stream stream, CompressionMethod method)
@ -452,7 +449,7 @@ namespace WebSocketSharp
/// otherwise, <see langword="null"/>.
/// </returns>
/// <param name="uri">
/// A <see cref="Uri"/> that represents a URI to get the absolute path from.
/// A <see cref="Uri"/> that represents the URI to get the absolute path from.
/// </param>
internal static string GetAbsolutePath (this Uri uri)
{
@ -484,7 +481,7 @@ namespace WebSocketSharp
: code == CloseStatusCode.TooBig
? "A too big data has been received."
: code == CloseStatusCode.IgnoreExtension
? "WebSocket client did not receive expected extension(s)."
? "WebSocket client didn't receive expected extension(s)."
: code == CloseStatusCode.ServerError
? "WebSocket server got an internal error."
: code == CloseStatusCode.TlsHandshakeFailure
@ -492,7 +489,21 @@ namespace WebSocketSharp
: String.Empty;
}
internal static string GetNameInternal (this string nameAndValue, string separator)
/// <summary>
/// Gets the name from the specified <see cref="string"/> that contains a pair of name and
/// value separated by a separator character.
/// </summary>
/// <returns>
/// A <see cref="string"/> that represents the name if any; otherwise, <c>null</c>.
/// </returns>
/// <param name="nameAndValue">
/// A <see cref="string"/> that contains a pair of name and value separated by a separator
/// character.
/// </param>
/// <param name="separator">
/// A <see cref="char"/> that represents the separator character.
/// </param>
internal static string GetName (this string nameAndValue, char separator)
{
var i = nameAndValue.IndexOf (separator);
return i > 0
@ -500,15 +511,29 @@ namespace WebSocketSharp
: null;
}
internal static string GetValueInternal (this string nameAndValue, string separator)
/// <summary>
/// Gets the value from the specified <see cref="string"/> that contains a pair of name and
/// value separated by a separator character.
/// </summary>
/// <returns>
/// A <see cref="string"/> that represents the value if any; otherwise, <c>null</c>.
/// </returns>
/// <param name="nameAndValue">
/// A <see cref="string"/> that contains a pair of name and value separated by a separator
/// character.
/// </param>
/// <param name="separator">
/// A <see cref="char"/> that represents the separator character.
/// </param>
internal static string GetValue (this string nameAndValue, char separator)
{
var i = nameAndValue.IndexOf (separator);
return i >= 0 && i < nameAndValue.Length - 1
return i > -1 && i < nameAndValue.Length - 1
? nameAndValue.Substring (i + 1).Trim ()
: null;
}
internal static string GetValue (this string nameAndValue, string separator, bool unquote)
internal static string GetValue (this string nameAndValue, char separator, bool unquote)
{
var i = nameAndValue.IndexOf (separator);
if (i < 0 || i == nameAndValue.Length - 1)
@ -602,33 +627,33 @@ namespace WebSocketSharp
internal static byte[] ReadBytes (this Stream stream, long length, int bufferLength)
{
using (var result = new MemoryStream ()) {
var count = length / bufferLength;
using (var res = new MemoryStream ()) {
var cnt = length / bufferLength;
var rem = (int) (length % bufferLength);
var buffer = new byte [bufferLength];
var buff = new byte[bufferLength];
var end = false;
for (long i = 0; i < count; i++) {
if (!stream.readBytes (buffer, 0, bufferLength, result)) {
for (long i = 0; i < cnt; i++) {
if (!stream.readBytes (buff, 0, bufferLength, res)) {
end = true;
break;
}
}
if (!end && rem > 0)
stream.readBytes (new byte [rem], 0, rem, result);
stream.readBytes (new byte[rem], 0, rem, res);
result.Close ();
return result.ToArray ();
res.Close ();
return res.ToArray ();
}
}
internal static void ReadBytesAsync (
this Stream stream, int length, Action<byte[]> completed, Action<Exception> error)
{
var buffer = new byte [length];
var buff = new byte[length];
stream.BeginRead (
buffer,
buff,
0,
length,
ar => {
@ -637,8 +662,8 @@ namespace WebSocketSharp
var bytes = len < 1
? new byte[0]
: len < length
? stream.readBytes (buffer, len, length - len)
: buffer;
? stream.readBytes (buff, len, length - len)
: buff;
if (completed != null)
completed (bytes);
@ -669,7 +694,7 @@ namespace WebSocketSharp
internal static T[] Reverse<T> (this T[] array)
{
var len = array.Length;
T [] reverse = new T [len];
var reverse = new T[len];
var end = len - 1;
for (var i = 0; i <= end; i++)
@ -684,7 +709,7 @@ namespace WebSocketSharp
var len = value.Length;
var separators = new string (separator);
var buffer = new StringBuilder (32);
var buff = new StringBuilder (32);
var quoted = false;
var escaped = false;
@ -703,8 +728,8 @@ namespace WebSocketSharp
}
else if (separators.Contains (c)) {
if (!quoted) {
yield return buffer.ToString ();
buffer.Length = 0;
yield return buff.ToString ();
buff.Length = 0;
continue;
}
@ -712,11 +737,11 @@ namespace WebSocketSharp
else {
}
buffer.Append (c);
buff.Append (c);
}
if (buffer.Length > 0)
yield return buffer.ToString ();
if (buff.Length > 0)
yield return buff.ToString ();
}
internal static byte[] ToByteArray (this Stream stream)
@ -821,46 +846,43 @@ namespace WebSocketSharp
{
result = null;
if (uriString.Length == 0) {
message = "Must not be empty.";
message = "Empty string.";
return false;
}
var uri = uriString.ToUri ();
if (!uri.IsAbsoluteUri) {
message = "Must be the absolute URI: " + uriString;
message = "Not absolute URI: " + uriString;
return false;
}
var scheme = uri.Scheme;
if (scheme != "ws" && scheme != "wss") {
message = "The scheme part must be 'ws' or 'wss': " + scheme;
var schm = uri.Scheme;
if (schm != "ws" && schm != "wss") {
message = "The scheme part isn't 'ws' or 'wss': " + uriString;
return false;
}
var fragment = uri.Fragment;
if (fragment.Length > 0) {
message = "Must not contain the fragment component: " + uriString;
if (uri.Fragment.Length > 0) {
message = "Contains the fragment component: " + uriString;
return false;
}
var port = uri.Port;
if (port > 0) {
if (port > 65535) {
message = "The port part must be between 1 and 65535: " + port;
message = "The port part is greater than 65535: " + uriString;
return false;
}
if ((scheme == "ws" && port == 443) || (scheme == "wss" && port == 80)) {
message = String.Format (
"Invalid pair of scheme and port: {0}, {1}", scheme, port);
if ((schm == "ws" && port == 443) || (schm == "wss" && port == 80)) {
message = "Invalid pair of scheme and port: " + uriString;
return false;
}
}
else {
port = scheme == "ws" ? 80 : 443;
var url = String.Format (
"{0}://{1}:{2}{3}", scheme, uri.Host, port, uri.PathAndQuery);
uri = url.ToUri ();
uri = String.Format (
"{0}://{1}:{2}{3}", schm, uri.Host, schm == "ws" ? 80 : 443, uri.PathAndQuery)
.ToUri ();
}
result = uri;
@ -871,19 +893,18 @@ namespace WebSocketSharp
internal static string Unquote (this string value)
{
var start = value.IndexOf ('\"');
var end = value.LastIndexOf ('\"');
var start = value.IndexOf ('"');
var end = value.LastIndexOf ('"');
if (start < end)
value = value.Substring (start + 1, end - start - 1).Replace ("\\\"", "\"");
return value.Trim ();
}
internal static void WriteBytes (this Stream stream, byte [] value)
internal static void WriteBytes (this Stream stream, byte[] data)
{
using (var src = new MemoryStream (value)) {
src.CopyTo (stream);
}
using (var input = new MemoryStream (data))
input.CopyTo (stream);
}
#endregion
@ -939,9 +960,8 @@ namespace WebSocketSharp
/// with the specified both <paramref name="name"/> and <paramref name="value"/>.
/// </summary>
/// <returns>
/// <c>true</c> if <paramref name="collection"/> contains the entry
/// with both <paramref name="name"/> and <paramref name="value"/>;
/// otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="collection"/> contains the entry with both
/// <paramref name="name"/> and <paramref name="value"/>; otherwise, <c>false</c>.
/// </returns>
/// <param name="collection">
/// A <see cref="NameValueCollection"/> to test.
@ -957,12 +977,12 @@ namespace WebSocketSharp
if (collection == null || collection.Count == 0)
return false;
var values = collection [name];
if (values == null)
var vals = collection[name];
if (vals == null)
return false;
foreach (var v in values.Split (','))
if (v.Trim ().Equals (value, StringComparison.OrdinalIgnoreCase))
foreach (var val in vals.Split (','))
if (val.Trim ().Equals (value, StringComparison.OrdinalIgnoreCase))
return true;
return false;
@ -1038,59 +1058,13 @@ namespace WebSocketSharp
/// A <see cref="string"/> that represents the description of the HTTP status code.
/// </returns>
/// <param name="code">
/// One of <see cref="HttpStatusCode"/> enum values, indicates the HTTP status codes.
/// One of <see cref="HttpStatusCode"/> enum values, indicates the HTTP status code.
/// </param>
public static string GetDescription (this HttpStatusCode code)
{
return ((int) code).GetStatusDescription ();
}
/// <summary>
/// Gets the name from the specified <see cref="string"/> that contains a pair of name and
/// value separated by a separator string.
/// </summary>
/// <returns>
/// A <see cref="string"/> that represents the name if any; otherwise, <c>null</c>.
/// </returns>
/// <param name="nameAndValue">
/// A <see cref="string"/> that contains a pair of name and value separated by a separator
/// string.
/// </param>
/// <param name="separator">
/// A <see cref="string"/> that represents a separator string.
/// </param>
public static string GetName (this string nameAndValue, string separator)
{
return (nameAndValue != null && nameAndValue.Length > 0) &&
(separator != null && separator.Length > 0)
? nameAndValue.GetNameInternal (separator)
: null;
}
/// <summary>
/// Gets the name and value from the specified <see cref="string"/> that contains a pair of
/// name and value separated by a separator string.
/// </summary>
/// <returns>
/// A <c>KeyValuePair&lt;string, string&gt;</c> that represents the name and value if any.
/// </returns>
/// <param name="nameAndValue">
/// A <see cref="string"/> that contains a pair of name and value separated by a separator
/// string.
/// </param>
/// <param name="separator">
/// A <see cref="string"/> that represents a separator string.
/// </param>
public static KeyValuePair<string, string> GetNameAndValue (
this string nameAndValue, string separator)
{
var name = nameAndValue.GetName (separator);
var value = nameAndValue.GetValue (separator);
return name != null
? new KeyValuePair<string, string> (name, value)
: new KeyValuePair<string, string> (null, null);
}
/// <summary>
/// Gets the description of the specified HTTP status <paramref name="code"/>.
/// </summary>
@ -1154,34 +1128,12 @@ namespace WebSocketSharp
return String.Empty;
}
/// <summary>
/// Gets the value from the specified <see cref="string"/> that contains a pair of name and
/// value separated by a separator string.
/// </summary>
/// <returns>
/// A <see cref="string"/> that represents the value if any; otherwise, <c>null</c>.
/// </returns>
/// <param name="nameAndValue">
/// A <see cref="string"/> that contains a pair of name and value separated by a separator
/// string.
/// </param>
/// <param name="separator">
/// A <see cref="string"/> that represents a separator string.
/// </param>
public static string GetValue (this string nameAndValue, string separator)
{
return (nameAndValue != null && nameAndValue.Length > 0) &&
(separator != null && separator.Length > 0)
? nameAndValue.GetValueInternal (separator)
: null;
}
/// <summary>
/// Determines whether the specified <see cref="ushort"/> is in the allowable range of
/// the WebSocket close status code.
/// </summary>
/// <remarks>
/// Not allowable ranges are the followings.
/// Not allowable ranges are the following:
/// <list type="bullet">
/// <item>
/// <term>
@ -1230,12 +1182,11 @@ namespace WebSocketSharp
}
/// <summary>
/// Determines whether the specified <see cref="ByteOrder"/> is host
/// (this computer architecture) byte order.
/// Determines whether the specified <see cref="ByteOrder"/> is host (this computer
/// architecture) byte order.
/// </summary>
/// <returns>
/// <c>true</c> if <paramref name="order"/> is host byte order;
/// otherwise, <c>false</c>.
/// <c>true</c> if <paramref name="order"/> is host byte order; otherwise, <c>false</c>.
/// </returns>
/// <param name="order">
/// One of the <see cref="ByteOrder"/> enum values, to test.
@ -1364,7 +1315,7 @@ namespace WebSocketSharp
throw new ArgumentNullException ("protocol");
if (protocol.Length == 0)
throw new ArgumentException ("Must not be empty.", "protocol");
throw new ArgumentException ("Empty string.", "protocol");
return request.Headers.Contains ("Upgrade", protocol) &&
request.Headers.Contains ("Connection", "Upgrade");
@ -1429,7 +1380,7 @@ namespace WebSocketSharp
if (startIndex == 0 && array.Length == length)
return array;
T [] subArray = new T [length];
var subArray = new T[length];
Array.Copy (array, startIndex, subArray, 0, length);
return subArray;
@ -1600,28 +1551,28 @@ namespace WebSocketSharp
return default (T);
var type = typeof (T);
var buffer = src.ToHostOrder (srcOrder);
var buff = src.ToHostOrder (srcOrder);
return type == typeof (Boolean)
? (T)(object) BitConverter.ToBoolean (buffer, 0)
? (T)(object) BitConverter.ToBoolean (buff, 0)
: type == typeof (Char)
? (T)(object) BitConverter.ToChar (buffer, 0)
? (T)(object) BitConverter.ToChar (buff, 0)
: type == typeof (Double)
? (T)(object) BitConverter.ToDouble (buffer, 0)
? (T)(object) BitConverter.ToDouble (buff, 0)
: type == typeof (Int16)
? (T)(object) BitConverter.ToInt16 (buffer, 0)
? (T)(object) BitConverter.ToInt16 (buff, 0)
: type == typeof (Int32)
? (T)(object) BitConverter.ToInt32 (buffer, 0)
? (T)(object) BitConverter.ToInt32 (buff, 0)
: type == typeof (Int64)
? (T)(object) BitConverter.ToInt64 (buffer, 0)
? (T)(object) BitConverter.ToInt64 (buff, 0)
: type == typeof (Single)
? (T)(object) BitConverter.ToSingle (buffer, 0)
? (T)(object) BitConverter.ToSingle (buff, 0)
: type == typeof (UInt16)
? (T)(object) BitConverter.ToUInt16 (buffer, 0)
? (T)(object) BitConverter.ToUInt16 (buff, 0)
: type == typeof (UInt32)
? (T)(object) BitConverter.ToUInt32 (buffer, 0)
? (T)(object) BitConverter.ToUInt32 (buff, 0)
: type == typeof (UInt64)
? (T)(object) BitConverter.ToUInt64 (buffer, 0)
? (T)(object) BitConverter.ToUInt64 (buff, 0)
: default (T);
}
@ -1733,11 +1684,11 @@ namespace WebSocketSharp
if (separator == null)
separator = String.Empty;
var buffer = new StringBuilder (64);
(len - 1).Times (i => buffer.AppendFormat ("{0}{1}", array [i].ToString (), separator));
var buff = new StringBuilder (64);
(len - 1).Times (i => buff.AppendFormat ("{0}{1}", array[i].ToString (), separator));
buffer.Append (array [len - 1].ToString ());
return buffer.ToString ();
buff.Append (array[len - 1].ToString ());
return buff.ToString ();
}
/// <summary>
@ -1812,12 +1763,13 @@ namespace WebSocketSharp
if (response == null)
throw new ArgumentNullException ("response");
if (content == null || content.Length == 0)
var len = 0;
if (content == null || (len = content.Length) == 0)
return;
var output = response.OutputStream;
response.ContentLength64 = content.Length;
output.Write (content, 0, content.Length);
response.ContentLength64 = len;
output.Write (content, 0, len);
output.Close ();
}

View File

@ -227,20 +227,20 @@ namespace WebSocketSharp.Net
continue;
if (pair.StartsWith ("$version", StringComparison.InvariantCultureIgnoreCase)) {
version = Int32.Parse (pair.GetValueInternal ("=").Trim ('"'));
version = Int32.Parse (pair.GetValue ('=', true));
}
else if (pair.StartsWith ("$path", StringComparison.InvariantCultureIgnoreCase)) {
if (cookie != null)
cookie.Path = pair.GetValueInternal ("=");
cookie.Path = pair.GetValue ('=');
}
else if (pair.StartsWith ("$domain", StringComparison.InvariantCultureIgnoreCase)) {
if (cookie != null)
cookie.Domain = pair.GetValueInternal ("=");
cookie.Domain = pair.GetValue ('=');
}
else if (pair.StartsWith ("$port", StringComparison.InvariantCultureIgnoreCase)) {
var port = pair.Equals ("$port", StringComparison.InvariantCultureIgnoreCase)
? "\"\""
: pair.GetValueInternal ("=");
: pair.GetValue ('=');
if (cookie != null)
cookie.Port = port;
@ -289,10 +289,10 @@ namespace WebSocketSharp.Net
if (pair.StartsWith ("version", StringComparison.InvariantCultureIgnoreCase)) {
if (cookie != null)
cookie.Version = Int32.Parse (pair.GetValueInternal ("=").Trim ('"'));
cookie.Version = Int32.Parse (pair.GetValue ('=', true));
}
else if (pair.StartsWith ("expires", StringComparison.InvariantCultureIgnoreCase)) {
var buffer = new StringBuilder (pair.GetValueInternal ("="), 32);
var buffer = new StringBuilder (pair.GetValue ('='), 32);
if (i < pairs.Length - 1)
buffer.AppendFormat (", {0}", pairs [++i].Trim ());
@ -309,34 +309,34 @@ namespace WebSocketSharp.Net
cookie.Expires = expires.ToLocalTime ();
}
else if (pair.StartsWith ("max-age", StringComparison.InvariantCultureIgnoreCase)) {
var max = Int32.Parse (pair.GetValueInternal ("=").Trim ('"'));
var max = Int32.Parse (pair.GetValue ('=', true));
var expires = DateTime.Now.AddSeconds ((double) max);
if (cookie != null)
cookie.Expires = expires;
}
else if (pair.StartsWith ("path", StringComparison.InvariantCultureIgnoreCase)) {
if (cookie != null)
cookie.Path = pair.GetValueInternal ("=");
cookie.Path = pair.GetValue ('=');
}
else if (pair.StartsWith ("domain", StringComparison.InvariantCultureIgnoreCase)) {
if (cookie != null)
cookie.Domain = pair.GetValueInternal ("=");
cookie.Domain = pair.GetValue ('=');
}
else if (pair.StartsWith ("port", StringComparison.InvariantCultureIgnoreCase)) {
var port = pair.Equals ("port", StringComparison.InvariantCultureIgnoreCase)
? "\"\""
: pair.GetValueInternal ("=");
: pair.GetValue ('=');
if (cookie != null)
cookie.Port = port;
}
else if (pair.StartsWith ("comment", StringComparison.InvariantCultureIgnoreCase)) {
if (cookie != null)
cookie.Comment = pair.GetValueInternal ("=").UrlDecode ();
cookie.Comment = pair.GetValue ('=').UrlDecode ();
}
else if (pair.StartsWith ("commenturl", StringComparison.InvariantCultureIgnoreCase)) {
if (cookie != null)
cookie.CommentUri = pair.GetValueInternal ("=").Trim ('"').ToUri ();
cookie.CommentUri = pair.GetValue ('=', true).ToUri ();
}
else if (pair.StartsWith ("discard", StringComparison.InvariantCultureIgnoreCase)) {
if (cookie != null)

View File

@ -522,7 +522,7 @@ namespace WebSocketSharp.Net
foreach (var p in parts) {
var part = p.Trim ();
if (part.StartsWith ("charset", StringComparison.OrdinalIgnoreCase)) {
var charset = part.GetValue ("=", true);
var charset = part.GetValue ('=', true);
if (charset != null && charset.Length > 0) {
try {
_contentEncoding = Encoding.GetEncoding (charset);