Fix due to the modified Handshake.cs
This commit is contained in:
parent
c513fe7670
commit
8ba6ff1f09
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -37,7 +37,7 @@ namespace WebSocketSharp {
|
|||||||
|
|
||||||
#region Protected Const Fields
|
#region Protected Const Fields
|
||||||
|
|
||||||
protected const string _crlf = "\r\n";
|
protected const string CrLf = "\r\n";
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -46,15 +46,20 @@ namespace WebSocketSharp {
|
|||||||
protected Handshake()
|
protected Handshake()
|
||||||
{
|
{
|
||||||
ProtocolVersion = HttpVersion.Version11;
|
ProtocolVersion = HttpVersion.Version11;
|
||||||
Headers = new NameValueCollection();
|
Headers = new NameValueCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Public Properties
|
#region Public Properties
|
||||||
|
|
||||||
public NameValueCollection Headers { get; internal set; }
|
public NameValueCollection Headers {
|
||||||
public Version ProtocolVersion { get; internal set; }
|
get; protected set;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Version ProtocolVersion {
|
||||||
|
get; protected set;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -65,22 +70,22 @@ namespace WebSocketSharp {
|
|||||||
Headers.Add(name, value);
|
Headers.Add(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool ContainsHeader(string name)
|
||||||
|
{
|
||||||
|
return Headers.Exists(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ContainsHeader(string name, string value)
|
||||||
|
{
|
||||||
|
return Headers.Exists(name, value);
|
||||||
|
}
|
||||||
|
|
||||||
public string[] GetHeaderValues(string name)
|
public string[] GetHeaderValues(string name)
|
||||||
{
|
{
|
||||||
return Headers.GetValues(name);
|
return Headers.GetValues(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HeaderExists(string name)
|
public byte[] ToByteArray()
|
||||||
{
|
|
||||||
return Headers.Exists(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool HeaderExists(string name, string value)
|
|
||||||
{
|
|
||||||
return Headers.Exists(name, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public byte[] ToBytes()
|
|
||||||
{
|
{
|
||||||
return Encoding.UTF8.GetBytes(ToString());
|
return Encoding.UTF8.GetBytes(ToString());
|
||||||
}
|
}
|
||||||
|
@ -72,7 +72,9 @@ namespace WebSocketSharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string HttpMethod { get; private set; }
|
public string HttpMethod {
|
||||||
|
get; private set;
|
||||||
|
}
|
||||||
|
|
||||||
public bool IsWebSocketRequest {
|
public bool IsWebSocketRequest {
|
||||||
get {
|
get {
|
||||||
@ -80,15 +82,15 @@ namespace WebSocketSharp {
|
|||||||
? false
|
? false
|
||||||
: ProtocolVersion < HttpVersion.Version11
|
: ProtocolVersion < HttpVersion.Version11
|
||||||
? false
|
? false
|
||||||
: !HeaderExists("Upgrade", "websocket")
|
: !ContainsHeader("Upgrade", "websocket")
|
||||||
? false
|
? false
|
||||||
: !HeaderExists("Connection", "Upgrade")
|
: !ContainsHeader("Connection", "Upgrade")
|
||||||
? false
|
? false
|
||||||
: !HeaderExists("Host")
|
: !ContainsHeader("Host")
|
||||||
? false
|
? false
|
||||||
: !HeaderExists("Sec-WebSocket-Key")
|
: !ContainsHeader("Sec-WebSocket-Key")
|
||||||
? false
|
? false
|
||||||
: HeaderExists("Sec-WebSocket-Version");
|
: ContainsHeader("Sec-WebSocket-Version");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ namespace WebSocketSharp {
|
|||||||
var i = RawUrl.IndexOf('?');
|
var i = RawUrl.IndexOf('?');
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
{
|
{
|
||||||
var query = RawUrl.Substring(i + 1);
|
var query = RawUrl.Substring(i + 1);
|
||||||
var components = query.Split('&');
|
var components = query.Split('&');
|
||||||
foreach (var c in components)
|
foreach (var c in components)
|
||||||
{
|
{
|
||||||
@ -109,7 +111,7 @@ namespace WebSocketSharp {
|
|||||||
if (nv.Key != null)
|
if (nv.Key != null)
|
||||||
{
|
{
|
||||||
var name = nv.Key.UrlDecode();
|
var name = nv.Key.UrlDecode();
|
||||||
var val = nv.Value.UrlDecode();
|
var val = nv.Value.UrlDecode();
|
||||||
_queryString.Add(name, val);
|
_queryString.Add(name, val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -128,7 +130,9 @@ namespace WebSocketSharp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Uri RequestUri { get; private set; }
|
public Uri RequestUri {
|
||||||
|
get; private set;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -148,9 +152,9 @@ namespace WebSocketSharp {
|
|||||||
headers.SetInternal(request[i], false);
|
headers.SetInternal(request[i], false);
|
||||||
|
|
||||||
return new RequestHandshake {
|
return new RequestHandshake {
|
||||||
Headers = headers,
|
Headers = headers,
|
||||||
HttpMethod = requestLine[0],
|
HttpMethod = requestLine[0],
|
||||||
RequestUri = requestLine[1].ToUri(),
|
RequestUri = requestLine[1].ToUri(),
|
||||||
ProtocolVersion = new Version(requestLine[2].Substring(5))
|
ProtocolVersion = new Version(requestLine[2].Substring(5))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -158,20 +162,20 @@ namespace WebSocketSharp {
|
|||||||
public static RequestHandshake Parse(WebSocketContext context)
|
public static RequestHandshake Parse(WebSocketContext context)
|
||||||
{
|
{
|
||||||
return new RequestHandshake {
|
return new RequestHandshake {
|
||||||
Headers = context.Headers,
|
Headers = context.Headers,
|
||||||
HttpMethod = "GET",
|
HttpMethod = "GET",
|
||||||
RequestUri = context.RequestUri,
|
RequestUri = context.RequestUri,
|
||||||
ProtocolVersion = HttpVersion.Version11
|
ProtocolVersion = HttpVersion.Version11
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCookies(CookieCollection cookies)
|
public void SetCookies(CookieCollection cookies)
|
||||||
{
|
{
|
||||||
if (cookies.IsNull() || cookies.Count == 0)
|
if (cookies == null || cookies.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var sorted = cookies.Sorted.ToArray();
|
var sorted = cookies.Sorted.ToArray();
|
||||||
var header = new StringBuilder(sorted[0].ToString());
|
var header = new StringBuilder(sorted[0].ToString(), 64);
|
||||||
for (int i = 1; i < sorted.Length; i++)
|
for (int i = 1; i < sorted.Length; i++)
|
||||||
if (!sorted[i].Expired)
|
if (!sorted[i].Expired)
|
||||||
header.AppendFormat("; {0}", sorted[i].ToString());
|
header.AppendFormat("; {0}", sorted[i].ToString());
|
||||||
@ -181,12 +185,12 @@ namespace WebSocketSharp {
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var buffer = new StringBuilder();
|
var buffer = new StringBuilder(64);
|
||||||
buffer.AppendFormat("{0} {1} HTTP/{2}{3}", HttpMethod, RawUrl, ProtocolVersion, _crlf);
|
buffer.AppendFormat("{0} {1} HTTP/{2}{3}", HttpMethod, RawUrl, ProtocolVersion, CrLf);
|
||||||
foreach (string key in Headers.AllKeys)
|
foreach (string key in Headers.AllKeys)
|
||||||
buffer.AppendFormat("{0}: {1}{2}", key, Headers[key], _crlf);
|
buffer.AppendFormat("{0}: {1}{2}", key, Headers[key], CrLf);
|
||||||
|
|
||||||
buffer.Append(_crlf);
|
buffer.Append(CrLf);
|
||||||
return buffer.ToString();
|
return buffer.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,17 +67,21 @@ namespace WebSocketSharp {
|
|||||||
? false
|
? false
|
||||||
: StatusCode != "101"
|
: StatusCode != "101"
|
||||||
? false
|
? false
|
||||||
: !HeaderExists("Upgrade", "websocket")
|
: !ContainsHeader("Upgrade", "websocket")
|
||||||
? false
|
? false
|
||||||
: !HeaderExists("Connection", "Upgrade")
|
: !ContainsHeader("Connection", "Upgrade")
|
||||||
? false
|
? false
|
||||||
: HeaderExists("Sec-WebSocket-Accept");
|
: ContainsHeader("Sec-WebSocket-Accept");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Reason { get; internal set; }
|
public string Reason {
|
||||||
|
get; private set;
|
||||||
|
}
|
||||||
|
|
||||||
public string StatusCode { get; internal set; }
|
public string StatusCode {
|
||||||
|
get; private set;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@ -97,7 +101,7 @@ namespace WebSocketSharp {
|
|||||||
if (statusLine.Length < 3)
|
if (statusLine.Length < 3)
|
||||||
throw new ArgumentException("Invalid status line.");
|
throw new ArgumentException("Invalid status line.");
|
||||||
|
|
||||||
var reason = new StringBuilder(statusLine[2]);
|
var reason = new StringBuilder(statusLine[2], 64);
|
||||||
for (int i = 3; i < statusLine.Length; i++)
|
for (int i = 3; i < statusLine.Length; i++)
|
||||||
reason.AppendFormat(" {0}", statusLine[i]);
|
reason.AppendFormat(" {0}", statusLine[i]);
|
||||||
|
|
||||||
@ -106,16 +110,16 @@ namespace WebSocketSharp {
|
|||||||
headers.SetInternal(response[i], true);
|
headers.SetInternal(response[i], true);
|
||||||
|
|
||||||
return new ResponseHandshake {
|
return new ResponseHandshake {
|
||||||
Headers = headers,
|
Headers = headers,
|
||||||
Reason = reason.ToString(),
|
Reason = reason.ToString(),
|
||||||
StatusCode = statusLine[1],
|
StatusCode = statusLine[1],
|
||||||
ProtocolVersion = new Version(statusLine[0].Substring(5))
|
ProtocolVersion = new Version(statusLine[0].Substring(5))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetCookies(CookieCollection cookies)
|
public void SetCookies(CookieCollection cookies)
|
||||||
{
|
{
|
||||||
if (cookies.IsNull() || cookies.Count == 0)
|
if (cookies == null || cookies.Count == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (var cookie in cookies.Sorted)
|
foreach (var cookie in cookies.Sorted)
|
||||||
@ -124,12 +128,12 @@ namespace WebSocketSharp {
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
var buffer = new StringBuilder();
|
var buffer = new StringBuilder(64);
|
||||||
buffer.AppendFormat("HTTP/{0} {1} {2}{3}", ProtocolVersion, StatusCode, Reason, _crlf);
|
buffer.AppendFormat("HTTP/{0} {1} {2}{3}", ProtocolVersion, StatusCode, Reason, CrLf);
|
||||||
foreach (string key in Headers.AllKeys)
|
foreach (string key in Headers.AllKeys)
|
||||||
buffer.AppendFormat("{0}: {1}{2}", key, Headers[key], _crlf);
|
buffer.AppendFormat("{0}: {1}{2}", key, Headers[key], CrLf);
|
||||||
|
|
||||||
buffer.Append(_crlf);
|
buffer.Append(CrLf);
|
||||||
return buffer.ToString();
|
return buffer.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -827,10 +827,10 @@ namespace WebSocketSharp {
|
|||||||
{
|
{
|
||||||
return !response.IsWebSocketResponse
|
return !response.IsWebSocketResponse
|
||||||
? false
|
? false
|
||||||
: !response.HeaderExists("Sec-WebSocket-Accept", createResponseKey())
|
: !response.ContainsHeader("Sec-WebSocket-Accept", createResponseKey())
|
||||||
? false
|
? false
|
||||||
: !response.HeaderExists("Sec-WebSocket-Version") ||
|
: !response.ContainsHeader("Sec-WebSocket-Version") ||
|
||||||
response.HeaderExists("Sec-WebSocket-Version", _version);
|
response.ContainsHeader("Sec-WebSocket-Version", _version);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onClose(CloseEventArgs eventArgs)
|
private void onClose(CloseEventArgs eventArgs)
|
||||||
|
@ -256,7 +256,7 @@ namespace WebSocketSharp {
|
|||||||
|
|
||||||
public bool Write(Handshake handshake)
|
public bool Write(Handshake handshake)
|
||||||
{
|
{
|
||||||
return write(handshake.ToBytes());
|
return write(handshake.ToByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user