[Modify] Polish it
This commit is contained in:
parent
3a2d5580a1
commit
dda0adbd6c
@ -249,64 +249,75 @@ namespace WebSocketSharp.Net
|
|||||||
|
|
||||||
private static CookieCollection parseRequest (string value)
|
private static CookieCollection parseRequest (string value)
|
||||||
{
|
{
|
||||||
var cookies = new CookieCollection ();
|
var ret = new CookieCollection ();
|
||||||
|
|
||||||
Cookie cookie = null;
|
Cookie cookie = null;
|
||||||
|
var compType = StringComparison.InvariantCultureIgnoreCase;
|
||||||
var ver = 0;
|
var ver = 0;
|
||||||
|
|
||||||
var pairs = splitCookieHeaderValue (value);
|
var pairs = splitCookieHeaderValue (value);
|
||||||
|
|
||||||
for (var i = 0; i < pairs.Length; i++) {
|
for (var i = 0; i < pairs.Length; i++) {
|
||||||
var pair = pairs[i].Trim ();
|
var pair = pairs[i].Trim ();
|
||||||
if (pair.Length == 0)
|
if (pair.Length == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (pair.StartsWith ("$version", StringComparison.InvariantCultureIgnoreCase)) {
|
if (pair.StartsWith ("$version", compType)) {
|
||||||
ver = Int32.Parse (pair.GetValue ('=', true));
|
ver = Int32.Parse (pair.GetValue ('=', true));
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else if (pair.StartsWith ("$path", StringComparison.InvariantCultureIgnoreCase)) {
|
|
||||||
|
if (pair.StartsWith ("$path", compType)) {
|
||||||
if (cookie != null)
|
if (cookie != null)
|
||||||
cookie.Path = pair.GetValue ('=');
|
cookie.Path = pair.GetValue ('=');
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else if (pair.StartsWith ("$domain", StringComparison.InvariantCultureIgnoreCase)) {
|
|
||||||
|
if (pair.StartsWith ("$domain", compType)) {
|
||||||
if (cookie != null)
|
if (cookie != null)
|
||||||
cookie.Domain = pair.GetValue ('=');
|
cookie.Domain = pair.GetValue ('=');
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pair.StartsWith ("$port", compType)) {
|
||||||
|
if (cookie != null) {
|
||||||
|
cookie.Port = !pair.Equals ("$port", compType)
|
||||||
|
? pair.GetValue ('=')
|
||||||
|
: "\"\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
else if (pair.StartsWith ("$port", StringComparison.InvariantCultureIgnoreCase)) {
|
|
||||||
var port = pair.Equals ("$port", StringComparison.InvariantCultureIgnoreCase)
|
|
||||||
? "\"\""
|
|
||||||
: pair.GetValue ('=');
|
|
||||||
|
|
||||||
if (cookie != null)
|
if (cookie != null)
|
||||||
cookie.Port = port;
|
ret.Add (cookie);
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (cookie != null)
|
|
||||||
cookies.Add (cookie);
|
|
||||||
|
|
||||||
string name;
|
string name = null;
|
||||||
string val = String.Empty;
|
string val = String.Empty;
|
||||||
|
|
||||||
var pos = pair.IndexOf ('=');
|
var idx = pair.IndexOf ('=');
|
||||||
if (pos == -1) {
|
if (idx == -1) {
|
||||||
name = pair;
|
name = pair;
|
||||||
}
|
}
|
||||||
else if (pos == pair.Length - 1) {
|
else if (idx == pair.Length - 1) {
|
||||||
name = pair.Substring (0, pos).TrimEnd (' ');
|
name = pair.Substring (0, idx).TrimEnd (' ');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
name = pair.Substring (0, pos).TrimEnd (' ');
|
name = pair.Substring (0, idx).TrimEnd (' ');
|
||||||
val = pair.Substring (pos + 1).TrimStart (' ');
|
val = pair.Substring (idx + 1).TrimStart (' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
cookie = new Cookie (name, val);
|
cookie = new Cookie (name, val);
|
||||||
if (ver != 0)
|
if (ver != 0)
|
||||||
cookie.Version = ver;
|
cookie.Version = ver;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (cookie != null)
|
if (cookie != null)
|
||||||
cookies.Add (cookie);
|
ret.Add (cookie);
|
||||||
|
|
||||||
return cookies;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CookieCollection parseResponse (string value)
|
private static CookieCollection parseResponse (string value)
|
||||||
|
Loading…
Reference in New Issue
Block a user