diff --git a/Example/bin/Debug_Ubuntu/example.exe b/Example/bin/Debug_Ubuntu/example.exe index d7d6fb52..a035389f 100755 Binary files a/Example/bin/Debug_Ubuntu/example.exe and b/Example/bin/Debug_Ubuntu/example.exe differ diff --git a/Example/bin/Debug_Ubuntu/websocket-sharp.dll b/Example/bin/Debug_Ubuntu/websocket-sharp.dll index 41736fd4..8b213901 100755 Binary files a/Example/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example1/bin/Debug_Ubuntu/example1.exe b/Example1/bin/Debug_Ubuntu/example1.exe index b288785d..44628063 100755 Binary files a/Example1/bin/Debug_Ubuntu/example1.exe and b/Example1/bin/Debug_Ubuntu/example1.exe differ diff --git a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll index 41736fd4..8b213901 100755 Binary files a/Example1/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example1/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example2/bin/Debug_Ubuntu/example2.exe b/Example2/bin/Debug_Ubuntu/example2.exe index 2faa8c55..4a133c17 100755 Binary files a/Example2/bin/Debug_Ubuntu/example2.exe and b/Example2/bin/Debug_Ubuntu/example2.exe differ diff --git a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll index 41736fd4..8b213901 100755 Binary files a/Example2/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example2/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/Example3/bin/Debug_Ubuntu/Example3.exe b/Example3/bin/Debug_Ubuntu/Example3.exe index 4eee9dbb..1faf9d14 100755 Binary files a/Example3/bin/Debug_Ubuntu/Example3.exe and b/Example3/bin/Debug_Ubuntu/Example3.exe differ diff --git a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll index 41736fd4..8b213901 100755 Binary files a/Example3/bin/Debug_Ubuntu/websocket-sharp.dll and b/Example3/bin/Debug_Ubuntu/websocket-sharp.dll differ diff --git a/websocket-sharp/Handshake.cs b/websocket-sharp/Handshake.cs index a0ccef63..d5310b74 100644 --- a/websocket-sharp/Handshake.cs +++ b/websocket-sharp/Handshake.cs @@ -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 string[] GetHeaderValues(string name) + public bool ContainsHeader(string name) { - return Headers.GetValues(name); + return Headers.Exists(name); } - public bool HeaderExists(string name) + public bool ContainsHeader(string name, string value) { - return Headers.Exists(name); + return Headers.Exists(name, value); } - public bool HeaderExists(string name, string value) + public string[] GetHeaderValues(string name) { - return Headers.Exists(name, value); + return Headers.GetValues(name); } - public byte[] ToBytes() + public byte[] ToByteArray() { return Encoding.UTF8.GetBytes(ToString()); } diff --git a/websocket-sharp/RequestHandshake.cs b/websocket-sharp/RequestHandshake.cs index 351aa1d7..d2b721ee 100644 --- a/websocket-sharp/RequestHandshake.cs +++ b/websocket-sharp/RequestHandshake.cs @@ -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(); } diff --git a/websocket-sharp/ResponseHandshake.cs b/websocket-sharp/ResponseHandshake.cs index 7e80687f..a9fe75d8 100644 --- a/websocket-sharp/ResponseHandshake.cs +++ b/websocket-sharp/ResponseHandshake.cs @@ -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(); } diff --git a/websocket-sharp/WebSocket.cs b/websocket-sharp/WebSocket.cs index 77b4c111..77c2ed29 100644 --- a/websocket-sharp/WebSocket.cs +++ b/websocket-sharp/WebSocket.cs @@ -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) diff --git a/websocket-sharp/WsStream.cs b/websocket-sharp/WsStream.cs index fb77b117..b6f8ddc5 100644 --- a/websocket-sharp/WsStream.cs +++ b/websocket-sharp/WsStream.cs @@ -256,7 +256,7 @@ namespace WebSocketSharp { public bool Write(Handshake handshake) { - return write(handshake.ToBytes()); + return write(handshake.ToByteArray()); } #endregion diff --git a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll index 41736fd4..8b213901 100755 Binary files a/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll and b/websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll differ