diff options
Diffstat (limited to 'SocketHttpListener/Net/WebSockets')
6 files changed, 23 insertions, 41 deletions
diff --git a/SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs b/SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs index 49375678d..5ed49ec47 100644 --- a/SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs +++ b/SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs @@ -1,14 +1,8 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; -using System.IO; using System.Net; using System.Security.Principal; -using MediaBrowser.Model.Cryptography; -using MediaBrowser.Model.IO; -using MediaBrowser.Model.Net; using MediaBrowser.Model.Services; -using SocketHttpListener.Primitives; namespace SocketHttpListener.Net.WebSockets { diff --git a/SocketHttpListener/Net/WebSockets/HttpWebSocket.Managed.cs b/SocketHttpListener/Net/WebSockets/HttpWebSocket.Managed.cs index 571e4bdba..1cfd2dc90 100644 --- a/SocketHttpListener/Net/WebSockets/HttpWebSocket.Managed.cs +++ b/SocketHttpListener/Net/WebSockets/HttpWebSocket.Managed.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System; using System.Threading.Tasks; namespace SocketHttpListener.Net.WebSockets @@ -28,12 +26,11 @@ namespace SocketHttpListener.Net.WebSockets string origin = request.Headers[HttpKnownHeaderNames.Origin]; string[] secWebSocketProtocols = null; - string outgoingSecWebSocketProtocolString; bool shouldSendSecWebSocketProtocolHeader = ProcessWebSocketProtocolHeader( request.Headers[HttpKnownHeaderNames.SecWebSocketProtocol], subProtocol, - out outgoingSecWebSocketProtocolString); + out var outgoingSecWebSocketProtocolString); if (shouldSendSecWebSocketProtocolHeader) { @@ -52,15 +49,15 @@ namespace SocketHttpListener.Net.WebSockets response.StatusCode = (int)HttpStatusCode.SwitchingProtocols; // HTTP 101 response.StatusDescription = HttpStatusDescription.Get(HttpStatusCode.SwitchingProtocols); - HttpResponseStream responseStream = response.OutputStream as HttpResponseStream; + var responseStream = response.OutputStream as HttpResponseStream; // Send websocket handshake headers await responseStream.WriteWebSocketHandshakeHeadersAsync().ConfigureAwait(false); //WebSocket webSocket = WebSocket.CreateFromStream(context.Connection.ConnectedStream, isServer: true, subProtocol, keepAliveInterval); - WebSocket webSocket = new WebSocket(subProtocol); + var webSocket = new WebSocket(subProtocol); - HttpListenerWebSocketContext webSocketContext = new HttpListenerWebSocketContext( + var webSocketContext = new HttpListenerWebSocketContext( request.Url, request.Headers, request.Cookies, diff --git a/SocketHttpListener/Net/WebSockets/HttpWebSocket.cs b/SocketHttpListener/Net/WebSockets/HttpWebSocket.cs index 9dc9143f8..b346cc98e 100644 --- a/SocketHttpListener/Net/WebSockets/HttpWebSocket.cs +++ b/SocketHttpListener/Net/WebSockets/HttpWebSocket.cs @@ -1,8 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Text; +using System; using System.Diagnostics.CodeAnalysis; using System.Security.Cryptography; +using System.Text; using System.Threading; namespace SocketHttpListener.Net.WebSockets @@ -20,7 +19,7 @@ namespace SocketHttpListener.Net.WebSockets string retVal; // SHA1 used only for hashing purposes, not for crypto. Check here for FIPS compat. - using (SHA1 sha1 = SHA1.Create()) + using (var sha1 = SHA1.Create()) { string acceptString = string.Concat(secWebSocketKey, HttpWebSocket.SecWebSocketKeyGuid); byte[] toHash = Encoding.UTF8.GetBytes(acceptString); @@ -30,7 +29,7 @@ namespace SocketHttpListener.Net.WebSockets return retVal; } - // return value here signifies if a Sec-WebSocket-Protocol header should be returned by the server. + // return value here signifies if a Sec-WebSocket-Protocol header should be returned by the server. internal static bool ProcessWebSocketProtocolHeader(string clientSecWebSocketProtocol, string subProtocol, out string acceptProtocol) @@ -44,7 +43,7 @@ namespace SocketHttpListener.Net.WebSockets // If the server specified _anything_ this isn't valid. throw new WebSocketException("UnsupportedProtocol"); } - // Treat empty and null from the server as the same thing here, server should not send headers. + // Treat empty and null from the server as the same thing here, server should not send headers. return false; } @@ -52,7 +51,7 @@ namespace SocketHttpListener.Net.WebSockets if (subProtocol == null) { - // client specified some protocols, server specified 'null'. So server should send headers. + // client specified some protocols, server specified 'null'. So server should send headers. return true; } @@ -63,8 +62,8 @@ namespace SocketHttpListener.Net.WebSockets StringSplitOptions.RemoveEmptyEntries); acceptProtocol = subProtocol; - // client specified protocols, serverOptions has exactly 1 non-empty entry. Check that - // this exists in the list the client specified. + // client specified protocols, serverOptions has exactly 1 non-empty entry. Check that + // this exists in the list the client specified. for (int i = 0; i < requestProtocols.Length; i++) { string currentRequestProtocol = requestProtocols[i].Trim(); @@ -86,27 +85,27 @@ namespace SocketHttpListener.Net.WebSockets if (receiveBufferSize < MinReceiveBufferSize) { - throw new ArgumentOutOfRangeException("net_WebSockets_ArgumentOutOfRange_TooSmall"); + throw new ArgumentOutOfRangeException(nameof(receiveBufferSize), "The receiveBufferSize was too small."); } if (sendBufferSize < MinSendBufferSize) { - throw new ArgumentOutOfRangeException("net_WebSockets_ArgumentOutOfRange_TooSmall"); + throw new ArgumentOutOfRangeException(nameof(sendBufferSize), "The sendBufferSize was too small."); } if (receiveBufferSize > MaxBufferSize) { - throw new ArgumentOutOfRangeException("net_WebSockets_ArgumentOutOfRange_TooBig"); + throw new ArgumentOutOfRangeException(nameof(receiveBufferSize), "The receiveBufferSize was too large."); } if (sendBufferSize > MaxBufferSize) { - throw new ArgumentOutOfRangeException("net_WebSockets_ArgumentOutOfRange_TooBig"); + throw new ArgumentOutOfRangeException(nameof(sendBufferSize), "The sendBufferSize was too large."); } if (keepAliveInterval < Timeout.InfiniteTimeSpan) // -1 millisecond { - throw new ArgumentOutOfRangeException("net_WebSockets_ArgumentOutOfRange_TooSmall"); + throw new ArgumentOutOfRangeException(nameof(keepAliveInterval), "The keepAliveInterval was too small."); } } diff --git a/SocketHttpListener/Net/WebSockets/WebSocketCloseStatus.cs b/SocketHttpListener/Net/WebSockets/WebSocketCloseStatus.cs index 0f43b7b80..5ac89cf48 100644 --- a/SocketHttpListener/Net/WebSockets/WebSocketCloseStatus.cs +++ b/SocketHttpListener/Net/WebSockets/WebSocketCloseStatus.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace SocketHttpListener.Net.WebSockets { public enum WebSocketCloseStatus @@ -22,9 +18,9 @@ namespace SocketHttpListener.Net.WebSockets // 0 - 999 Status codes in the range 0-999 are not used. // 1000 - 1999 Status codes in the range 1000-1999 are reserved for definition by this protocol. // 2000 - 2999 Status codes in the range 2000-2999 are reserved for use by extensions. - // 3000 - 3999 Status codes in the range 3000-3999 MAY be used by libraries and frameworks. The - // interpretation of these codes is undefined by this protocol. End applications MUST - // NOT use status codes in this range. + // 3000 - 3999 Status codes in the range 3000-3999 MAY be used by libraries and frameworks. The + // interpretation of these codes is undefined by this protocol. End applications MUST + // NOT use status codes in this range. // 4000 - 4999 Status codes in the range 4000-4999 MAY be used by application code. The interpretation // of these codes is undefined by this protocol. } diff --git a/SocketHttpListener/Net/WebSockets/WebSocketContext.cs b/SocketHttpListener/Net/WebSockets/WebSocketContext.cs index 071b5fe05..10ad86439 100644 --- a/SocketHttpListener/Net/WebSockets/WebSocketContext.cs +++ b/SocketHttpListener/Net/WebSockets/WebSocketContext.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; -using System.Collections.Specialized; using System.Net; using System.Security.Principal; -using MediaBrowser.Model.Net; using MediaBrowser.Model.Services; namespace SocketHttpListener.Net.WebSockets diff --git a/SocketHttpListener/Net/WebSockets/WebSocketValidate.cs b/SocketHttpListener/Net/WebSockets/WebSocketValidate.cs index 00895ea01..0469e3b6c 100644 --- a/SocketHttpListener/Net/WebSockets/WebSocketValidate.cs +++ b/SocketHttpListener/Net/WebSockets/WebSocketValidate.cs @@ -1,8 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; -using MediaBrowser.Model.Net; +using System; using System.Globalization; +using System.Text; using WebSocketState = System.Net.WebSockets.WebSocketState; namespace SocketHttpListener.Net.WebSockets |
