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