diff options
| author | Andrew Rabert <6550543+nvllsvm@users.noreply.github.com> | 2019-01-19 15:11:50 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-01-19 15:11:50 -0500 |
| commit | 55538764fa06a64795c099fc6496df9dbb4156bd (patch) | |
| tree | 8c1f94861ecebdf634b70a7265945b6f8f13aff1 /SocketHttpListener/Net | |
| parent | 3b52035ee064a5d9aa215d9515211d4508585d39 (diff) | |
| parent | c5430f86b0b5863482e7c4f7e55a79c7d88c133b (diff) | |
Merge pull request #575 from EraYaN/reformat
Reformat all C# server code to conform with code standards
Diffstat (limited to 'SocketHttpListener/Net')
38 files changed, 449 insertions, 688 deletions
diff --git a/SocketHttpListener/Net/AuthenticationSchemeSelector.cs b/SocketHttpListener/Net/AuthenticationSchemeSelector.cs index c6e7e538e..77e6d0b8a 100644 --- a/SocketHttpListener/Net/AuthenticationSchemeSelector.cs +++ b/SocketHttpListener/Net/AuthenticationSchemeSelector.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; namespace SocketHttpListener.Net { diff --git a/SocketHttpListener/Net/AuthenticationTypes.cs b/SocketHttpListener/Net/AuthenticationTypes.cs index df6b9d576..a3dbe9dff 100644 --- a/SocketHttpListener/Net/AuthenticationTypes.cs +++ b/SocketHttpListener/Net/AuthenticationTypes.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace SocketHttpListener.Net { internal class AuthenticationTypes diff --git a/SocketHttpListener/Net/BoundaryType.cs b/SocketHttpListener/Net/BoundaryType.cs index f1e799f63..da0b22910 100644 --- a/SocketHttpListener/Net/BoundaryType.cs +++ b/SocketHttpListener/Net/BoundaryType.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - namespace SocketHttpListener.Net { internal enum BoundaryType diff --git a/SocketHttpListener/Net/ChunkStream.cs b/SocketHttpListener/Net/ChunkStream.cs index 5cc01614f..3836947d4 100644 --- a/SocketHttpListener/Net/ChunkStream.cs +++ b/SocketHttpListener/Net/ChunkStream.cs @@ -1,5 +1,4 @@ using System; -using System.Collections; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -109,7 +108,7 @@ namespace SocketHttpListener.Net var chunksForRemoving = new List<Chunk>(count); for (int i = 0; i < count; i++) { - Chunk chunk = _chunks[i]; + var chunk = _chunks[i]; if (chunk.Offset == chunk.Bytes.Length) { @@ -181,10 +180,7 @@ namespace SocketHttpListener.Net InternalWrite(buffer, ref offset, size); } - public bool WantMore - { - get { return (_chunkRead != _chunkSize || _chunkSize != 0 || _state != State.None); } - } + public bool WantMore => (_chunkRead != _chunkSize || _chunkSize != 0 || _state != State.None); public bool DataAvailable { @@ -193,7 +189,7 @@ namespace SocketHttpListener.Net int count = _chunks.Count; for (int i = 0; i < count; i++) { - Chunk ch = _chunks[i]; + var ch = _chunks[i]; if (ch == null || ch.Bytes == null) continue; if (ch.Bytes.Length > 0 && ch.Offset < ch.Bytes.Length) @@ -203,15 +199,9 @@ namespace SocketHttpListener.Net } } - public int TotalDataSize - { - get { return _totalWritten; } - } + public int TotalDataSize => _totalWritten; - public int ChunkLeft - { - get { return _chunkSize - _chunkRead; } - } + public int ChunkLeft => _chunkSize - _chunkRead; private State ReadBody(byte[] buffer, ref int offset, int size) { @@ -378,7 +368,7 @@ namespace SocketHttpListener.Net return State.Trailer; } - StringReader reader = new StringReader(_saved.ToString()); + var reader = new StringReader(_saved.ToString()); string line; while ((line = reader.ReadLine()) != null && line != "") _headers.Add(line); @@ -388,7 +378,7 @@ namespace SocketHttpListener.Net private static void ThrowProtocolViolation(string message) { - WebException we = new WebException(message, null, WebExceptionStatus.ServerProtocolViolation, null); + var we = new WebException(message, null, WebExceptionStatus.ServerProtocolViolation, null); throw we; } } diff --git a/SocketHttpListener/Net/ChunkedInputStream.cs b/SocketHttpListener/Net/ChunkedInputStream.cs index 4d6d96a6c..06dcb3a17 100644 --- a/SocketHttpListener/Net/ChunkedInputStream.cs +++ b/SocketHttpListener/Net/ChunkedInputStream.cs @@ -1,8 +1,6 @@ -using System; +using System; using System.IO; using System.Net; -using System.Runtime.InteropServices; -using SocketHttpListener.Primitives; namespace SocketHttpListener.Net { @@ -63,14 +61,14 @@ namespace SocketHttpListener.Net : base(stream, buffer, offset, length) { _context = context; - WebHeaderCollection coll = (WebHeaderCollection)context.Request.Headers; + var coll = (WebHeaderCollection)context.Request.Headers; _decoder = new ChunkStream(coll); } public ChunkStream Decoder { - get { return _decoder; } - set { _decoder = value; } + get => _decoder; + set => _decoder = value; } protected override int ReadCore(byte[] buffer, int offset, int count) @@ -81,7 +79,7 @@ namespace SocketHttpListener.Net protected override IAsyncResult BeginReadCore(byte[] buffer, int offset, int size, AsyncCallback cback, object state) { - HttpStreamAsyncResult ares = new HttpStreamAsyncResult(this); + var ares = new HttpStreamAsyncResult(this); ares._callback = cback; ares._state = state; if (_no_more_data || size == 0 || _closed) @@ -109,7 +107,7 @@ namespace SocketHttpListener.Net ares._buffer = new byte[8192]; ares._offset = 0; ares._count = 8192; - ReadBufferState rb = new ReadBufferState(buffer, offset, size, ares); + var rb = new ReadBufferState(buffer, offset, size, ares); rb.InitialCount += nread; base.BeginReadCore(ares._buffer, ares._offset, ares._count, OnRead, rb); return ares; @@ -118,7 +116,7 @@ namespace SocketHttpListener.Net private void OnRead(IAsyncResult base_ares) { ReadBufferState rb = (ReadBufferState)base_ares.AsyncState; - HttpStreamAsyncResult ares = rb.Ares; + var ares = rb.Ares; try { int nread = base.EndRead(base_ares); @@ -157,7 +155,7 @@ namespace SocketHttpListener.Net if (asyncResult == null) throw new ArgumentNullException(nameof(asyncResult)); - HttpStreamAsyncResult ares = asyncResult as HttpStreamAsyncResult; + var ares = asyncResult as HttpStreamAsyncResult; if (ares == null || !ReferenceEquals(this, ares._parent)) { throw new ArgumentException("Invalid async result"); diff --git a/SocketHttpListener/Net/CookieHelper.cs b/SocketHttpListener/Net/CookieHelper.cs index 6c1764e09..3ad76ff23 100644 --- a/SocketHttpListener/Net/CookieHelper.cs +++ b/SocketHttpListener/Net/CookieHelper.cs @@ -1,9 +1,8 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.Net; using System.Text; -using System.Threading.Tasks; namespace SocketHttpListener.Net { @@ -44,13 +43,12 @@ namespace SocketHttpListener.Net if (i < pairs.Length - 1) buffer.AppendFormat(", {0}", pairs[++i].Trim()); - DateTime expires; if (!DateTime.TryParseExact( buffer.ToString(), new[] { "ddd, dd'-'MMM'-'yyyy HH':'mm':'ss 'GMT'", "r" }, new CultureInfo("en-US"), DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, - out expires)) + out var expires)) expires = DateTime.Now; if (cookie != null && cookie.Expires == DateTime.MinValue) diff --git a/SocketHttpListener/Net/EntitySendFormat.cs b/SocketHttpListener/Net/EntitySendFormat.cs index 9caee3e11..3ed981084 100644 --- a/SocketHttpListener/Net/EntitySendFormat.cs +++ b/SocketHttpListener/Net/EntitySendFormat.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - namespace SocketHttpListener.Net { internal enum EntitySendFormat diff --git a/SocketHttpListener/Net/HttpConnection.cs b/SocketHttpListener/Net/HttpConnection.cs index 4fc9a468c..af1c081d9 100644 --- a/SocketHttpListener/Net/HttpConnection.cs +++ b/SocketHttpListener/Net/HttpConnection.cs @@ -3,19 +3,17 @@ using System.IO; using System.Net; using System.Net.Security; using System.Net.Sockets; +using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; using System.Text; +using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.IO; -using Microsoft.Extensions.Logging; -using MediaBrowser.Model.Net; using MediaBrowser.Model.System; using MediaBrowser.Model.Text; +using Microsoft.Extensions.Logging; using SocketHttpListener.Primitives; -using System.Security.Authentication; - -using System.Threading; namespace SocketHttpListener.Net { sealed class HttpConnection @@ -91,13 +89,7 @@ namespace SocketHttpListener.Net } } - public Stream Stream - { - get - { - return _stream; - } - } + public Stream Stream => _stream; public async Task Init() { @@ -133,15 +125,9 @@ namespace SocketHttpListener.Net _context = new HttpListenerContext(this, _textEncoding); } - public bool IsClosed - { - get { return (_socket == null); } - } + public bool IsClosed => (_socket == null); - public int Reuses - { - get { return _reuses; } - } + public int Reuses => _reuses; public IPEndPoint LocalEndPoint { @@ -155,20 +141,14 @@ namespace SocketHttpListener.Net } } - public IPEndPoint RemoteEndPoint - { - get { return _socket.RemoteEndPoint as IPEndPoint; } - } + public IPEndPoint RemoteEndPoint => _socket.RemoteEndPoint as IPEndPoint; - public bool IsSecure - { - get { return secure; } - } + public bool IsSecure => secure; public ListenerPrefix Prefix { - get { return _prefix; } - set { _prefix = value; } + get => _prefix; + set => _prefix = value; } private void OnTimeout(object unused) @@ -232,7 +212,7 @@ namespace SocketHttpListener.Net private static void OnRead(IAsyncResult ares) { - HttpConnection cnc = (HttpConnection)ares.AsyncState; + var cnc = (HttpConnection)ares.AsyncState; cnc.OnReadInternal(ares); } diff --git a/SocketHttpListener/Net/HttpEndPointListener.cs b/SocketHttpListener/Net/HttpEndPointListener.cs index a108e7dd4..ea7d8fd2d 100644 --- a/SocketHttpListener/Net/HttpEndPointListener.cs +++ b/SocketHttpListener/Net/HttpEndPointListener.cs @@ -1,21 +1,15 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.IO; using System.Net; using System.Net.Sockets; using System.Security.Cryptography.X509Certificates; using System.Threading; using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.IO; -using Microsoft.Extensions.Logging; using MediaBrowser.Model.Net; using MediaBrowser.Model.System; using MediaBrowser.Model.Text; -using SocketHttpListener.Primitives; -using ProtocolType = MediaBrowser.Model.Net.ProtocolType; -using SocketType = MediaBrowser.Model.Net.SocketType; -using System.Threading.Tasks; +using Microsoft.Extensions.Logging; namespace SocketHttpListener.Net { @@ -64,13 +58,7 @@ namespace SocketHttpListener.Net CreateSocket(); } - internal HttpListener Listener - { - get - { - return _listener; - } - } + internal HttpListener Listener => _listener; private void CreateSocket() { @@ -172,7 +160,7 @@ namespace SocketHttpListener.Net } catch (Exception ex) { - HttpEndPointListener epl = (HttpEndPointListener)acceptEventArg.UserToken; + var epl = (HttpEndPointListener)acceptEventArg.UserToken; epl._logger.LogError(ex, "Error in socket.AcceptAsync"); } @@ -188,7 +176,7 @@ namespace SocketHttpListener.Net private static async void ProcessAccept(SocketAsyncEventArgs args) { - HttpEndPointListener epl = (HttpEndPointListener)args.UserToken; + var epl = (HttpEndPointListener)args.UserToken; if (epl._closed) { @@ -209,7 +197,7 @@ namespace SocketHttpListener.Net return; } - if(accepted == null) + if (accepted == null) { return; } @@ -226,7 +214,7 @@ namespace SocketHttpListener.Net var localEndPointString = accepted.LocalEndPoint == null ? string.Empty : accepted.LocalEndPoint.ToString(); //_logger.LogInformation("HttpEndPointListener Accepting connection from {0} to {1} secure connection requested: {2}", remoteEndPointString, localEndPointString, _secure); - HttpConnection conn = new HttpConnection(epl._logger, accepted, epl, epl._secure, epl._cert, epl._cryptoProvider, epl._streamHelper, epl._textEncoding, epl._fileSystem, epl._environment); + var conn = new HttpConnection(epl._logger, accepted, epl, epl._secure, epl._cert, epl._cryptoProvider, epl._streamHelper, epl._textEncoding, epl._fileSystem, epl._environment); await conn.Init().ConfigureAwait(false); @@ -288,9 +276,8 @@ namespace SocketHttpListener.Net public bool BindContext(HttpListenerContext context) { - HttpListenerRequest req = context.Request; - ListenerPrefix prefix; - HttpListener listener = SearchListener(req.Url, out prefix); + var req = context.Request; + HttpListener listener = SearchListener(req.Url, out var prefix); if (listener == null) return false; @@ -323,7 +310,7 @@ namespace SocketHttpListener.Net if (host != null && host != "") { Dictionary<ListenerPrefix, HttpListener> localPrefixes = _prefixes; - foreach (ListenerPrefix p in localPrefixes.Keys) + foreach (var p in localPrefixes.Keys) { string ppath = p.Path; if (ppath.Length < bestLength) diff --git a/SocketHttpListener/Net/HttpEndPointManager.cs b/SocketHttpListener/Net/HttpEndPointManager.cs index 01b5ae9bd..a75af5f5d 100644 --- a/SocketHttpListener/Net/HttpEndPointManager.cs +++ b/SocketHttpListener/Net/HttpEndPointManager.cs @@ -3,12 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Net; using System.Net.Sockets; -using System.Reflection; -using System.Threading.Tasks; -using MediaBrowser.Model.IO; using Microsoft.Extensions.Logging; -using MediaBrowser.Model.Net; -using SocketHttpListener.Primitives; namespace SocketHttpListener.Net { @@ -22,7 +17,7 @@ namespace SocketHttpListener.Net public static void AddListener(ILogger logger, HttpListener listener) { - List<string> added = new List<string>(); + var added = new List<string>(); try { lock ((s_ipEndPoints as ICollection).SyncRoot) @@ -62,14 +57,13 @@ namespace SocketHttpListener.Net int root = p.IndexOf('/', colon, p.Length - colon); string portString = p.Substring(colon + 1, root - colon - 1); - int port; - if (!int.TryParse(portString, out port) || port <= 0 || port >= 65536) + if (!int.TryParse(portString, out var port) || port <= 0 || port >= 65536) { throw new HttpListenerException((int)HttpStatusCode.BadRequest, "net_invalid_port"); } } - ListenerPrefix lp = new ListenerPrefix(p); + var lp = new ListenerPrefix(p); if (lp.Host != "*" && lp.Host != "+" && Uri.CheckHostName(lp.Host) == UriHostNameType.Unknown) throw new HttpListenerException((int)HttpStatusCode.BadRequest, "net_listener_host"); @@ -184,7 +178,7 @@ namespace SocketHttpListener.Net private static void RemovePrefixInternal(ILogger logger, string prefix, HttpListener listener) { - ListenerPrefix lp = new ListenerPrefix(prefix); + var lp = new ListenerPrefix(prefix); if (lp.Path.IndexOf('%') != -1) return; diff --git a/SocketHttpListener/Net/HttpKnownHeaderNames.cs b/SocketHttpListener/Net/HttpKnownHeaderNames.cs index ea4695850..dc6f2ce41 100644 --- a/SocketHttpListener/Net/HttpKnownHeaderNames.cs +++ b/SocketHttpListener/Net/HttpKnownHeaderNames.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace SocketHttpListener.Net { internal static partial class HttpKnownHeaderNames diff --git a/SocketHttpListener/Net/HttpListener.cs b/SocketHttpListener/Net/HttpListener.cs index a159cd273..8ec6b89aa 100644 --- a/SocketHttpListener/Net/HttpListener.cs +++ b/SocketHttpListener/Net/HttpListener.cs @@ -1,17 +1,15 @@ using System; using System.Collections; using System.Collections.Generic; -using System.IO; using System.Net; using System.Security.Cryptography.X509Certificates; using MediaBrowser.Common.Net; using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.IO; -using Microsoft.Extensions.Logging; using MediaBrowser.Model.Net; using MediaBrowser.Model.System; using MediaBrowser.Model.Text; -using SocketHttpListener.Primitives; +using Microsoft.Extensions.Logging; namespace SocketHttpListener.Net { @@ -72,7 +70,7 @@ namespace SocketHttpListener.Net // TODO: Digest, NTLM and Negotiate require ControlPrincipal public AuthenticationSchemes AuthenticationSchemes { - get { return auth_schemes; } + get => auth_schemes; set { CheckDisposed(); @@ -82,7 +80,7 @@ namespace SocketHttpListener.Net public AuthenticationSchemeSelector AuthenticationSchemeSelectorDelegate { - get { return auth_selector; } + get => auth_selector; set { CheckDisposed(); @@ -90,15 +88,9 @@ namespace SocketHttpListener.Net } } - public bool IsListening - { - get { return listening; } - } + public bool IsListening => listening; - public static bool IsSupported - { - get { return true; } - } + public static bool IsSupported => true; public HttpListenerPrefixCollection Prefixes { @@ -112,7 +104,7 @@ namespace SocketHttpListener.Net // TODO: use this public string Realm { - get { return realm; } + get => realm; set { CheckDisposed(); @@ -122,7 +114,7 @@ namespace SocketHttpListener.Net public bool UnsafeConnectionNtlmAuthentication { - get { return unsafe_ntlm_auth; } + get => unsafe_ntlm_auth; set { CheckDisposed(); @@ -144,10 +136,7 @@ namespace SocketHttpListener.Net // } //} - internal X509Certificate Certificate - { - get { return _certificate; } - } + internal X509Certificate Certificate => _certificate; public void Abort() { diff --git a/SocketHttpListener/Net/HttpListenerBasicIdentity.cs b/SocketHttpListener/Net/HttpListenerBasicIdentity.cs index d20e72777..5f6ec44b9 100644 --- a/SocketHttpListener/Net/HttpListenerBasicIdentity.cs +++ b/SocketHttpListener/Net/HttpListenerBasicIdentity.cs @@ -1,4 +1,4 @@ -using System.Security.Principal; +using System.Security.Principal; namespace SocketHttpListener.Net { @@ -12,10 +12,7 @@ namespace SocketHttpListener.Net this.password = password; } - public virtual string Password - { - get { return password; } - } + public virtual string Password => password; } public class GenericIdentity : IIdentity @@ -43,28 +40,10 @@ namespace SocketHttpListener.Net m_type = type; } - public virtual string Name - { - get - { - return m_name; - } - } + public virtual string Name => m_name; - public virtual string AuthenticationType - { - get - { - return m_type; - } - } + public virtual string AuthenticationType => m_type; - public virtual bool IsAuthenticated - { - get - { - return !m_name.Equals(""); - } - } + public virtual bool IsAuthenticated => !m_name.Equals(""); } } diff --git a/SocketHttpListener/Net/HttpListenerContext.Managed.cs b/SocketHttpListener/Net/HttpListenerContext.Managed.cs index db795f742..a6622c479 100644 --- a/SocketHttpListener/Net/HttpListenerContext.Managed.cs +++ b/SocketHttpListener/Net/HttpListenerContext.Managed.cs @@ -1,8 +1,8 @@ -using System.ComponentModel; +using System; +using System.ComponentModel; using System.Security.Principal; using System.Text; using System.Threading.Tasks; -using System; using MediaBrowser.Model.Text; using SocketHttpListener.Net.WebSockets; diff --git a/SocketHttpListener/Net/HttpListenerContext.cs b/SocketHttpListener/Net/HttpListenerContext.cs index e3e6eb906..8045299c6 100644 --- a/SocketHttpListener/Net/HttpListenerContext.cs +++ b/SocketHttpListener/Net/HttpListenerContext.cs @@ -1,12 +1,8 @@ using System; using System.Net; using System.Security.Principal; -using MediaBrowser.Model.Cryptography; -using MediaBrowser.Model.IO; -using Microsoft.Extensions.Logging; -using MediaBrowser.Model.Text; -using SocketHttpListener.Net.WebSockets; using System.Threading.Tasks; +using SocketHttpListener.Net.WebSockets; namespace SocketHttpListener.Net { @@ -22,13 +18,7 @@ namespace SocketHttpListener.Net // This can be used to cache the results of HttpListener.AuthenticationSchemeSelectorDelegate. internal AuthenticationSchemes AuthenticationSchemes { get; set; } - public HttpListenerResponse Response - { - get - { - return _response; - } - } + public HttpListenerResponse Response => _response; public Task<HttpListenerWebSocketContext> AcceptWebSocketAsync(string subProtocol) { @@ -66,13 +56,7 @@ namespace SocketHttpListener.Net } } - public virtual IIdentity Identity - { - get - { - return m_identity; - } - } + public virtual IIdentity Identity => m_identity; public virtual bool IsInRole(string role) { diff --git a/SocketHttpListener/Net/HttpListenerPrefixCollection.cs b/SocketHttpListener/Net/HttpListenerPrefixCollection.cs index f0e496a5a..97dc6797c 100644 --- a/SocketHttpListener/Net/HttpListenerPrefixCollection.cs +++ b/SocketHttpListener/Net/HttpListenerPrefixCollection.cs @@ -18,20 +18,11 @@ namespace SocketHttpListener.Net this.listener = listener; } - public int Count - { - get { return prefixes.Count; } - } + public int Count => prefixes.Count; - public bool IsReadOnly - { - get { return false; } - } + public bool IsReadOnly => false; - public bool IsSynchronized - { - get { return false; } - } + public bool IsSynchronized => false; public void Add(string uriPrefix) { diff --git a/SocketHttpListener/Net/HttpListenerRequest.Managed.cs b/SocketHttpListener/Net/HttpListenerRequest.Managed.cs index 8b68afe33..3f9e32f08 100644 --- a/SocketHttpListener/Net/HttpListenerRequest.Managed.cs +++ b/SocketHttpListener/Net/HttpListenerRequest.Managed.cs @@ -1,12 +1,7 @@ -using System; -using System.Text; -using System.Collections.Specialized; -using System.Globalization; +using System; using System.IO; -using System.Security.Authentication.ExtendedProtection; -using System.Security.Cryptography.X509Certificates; +using System.Text; using MediaBrowser.Model.Services; -using MediaBrowser.Model.Text; namespace SocketHttpListener.Net { diff --git a/SocketHttpListener/Net/HttpListenerRequest.cs b/SocketHttpListener/Net/HttpListenerRequest.cs index 16e245611..1c832367e 100644 --- a/SocketHttpListener/Net/HttpListenerRequest.cs +++ b/SocketHttpListener/Net/HttpListenerRequest.cs @@ -1,17 +1,11 @@ using System; -using System.Collections.Specialized; +using System.Collections.Generic; using System.Globalization; -using System.IO; using System.Net; -using System.Security.Cryptography.X509Certificates; using System.Text; -using System.Threading.Tasks; -using MediaBrowser.Model.Net; using MediaBrowser.Model.Services; -using MediaBrowser.Model.Text; -using SocketHttpListener.Primitives; -using System.Collections.Generic; using SocketHttpListener.Net.WebSockets; +using SocketHttpListener.Primitives; namespace SocketHttpListener.Net { @@ -29,7 +23,7 @@ namespace SocketHttpListener.Net private static CookieCollection ParseCookies(Uri uri, string setCookieHeader) { - CookieCollection cookies = new CookieCollection(); + var cookies = new CookieCollection(); return cookies; } @@ -177,7 +171,7 @@ namespace SocketHttpListener.Net { get { - QueryParamCollection queryString = new QueryParamCollection(); + var queryString = new QueryParamCollection(); Helpers.FillFromString(queryString, Url.Query, true, ContentEncoding); return queryString; } @@ -203,7 +197,7 @@ namespace SocketHttpListener.Net return null; } - bool success = Uri.TryCreate(referrer, UriKind.RelativeOrAbsolute, out Uri urlReferrer); + bool success = Uri.TryCreate(referrer, UriKind.RelativeOrAbsolute, out var urlReferrer); return success ? urlReferrer : null; } } @@ -302,7 +296,7 @@ namespace SocketHttpListener.Net // collect comma-separated values into list - List<string> values = new List<string>(); + var values = new List<string>(); int i = 0; while (i < l) @@ -347,7 +341,7 @@ namespace SocketHttpListener.Net private static string UrlDecodeStringFromStringInternal(string s, Encoding e) { int count = s.Length; - UrlDecoder helper = new UrlDecoder(count, e); + var helper = new UrlDecoder(count, e); // go through the string's chars collapsing %XX and %uXXXX and // appending each char as char, with exception of %XX constructs diff --git a/SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs b/SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs index 63790d796..7b4b619e6 100644 --- a/SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs +++ b/SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs @@ -1,8 +1,8 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; -using System.Text; using System.Globalization; +using System.Text; namespace SocketHttpListener.Net { @@ -54,7 +54,7 @@ namespace SocketHttpListener.Net public static Uri GetRequestUri(string rawUri, string cookedUriScheme, string cookedUriHost, string cookedUriPath, string cookedUriQuery) { - HttpListenerRequestUriBuilder builder = new HttpListenerRequestUriBuilder(rawUri, + var builder = new HttpListenerRequestUriBuilder(rawUri, cookedUriScheme, cookedUriHost, cookedUriPath, cookedUriQuery); return builder.Build(); @@ -232,8 +232,7 @@ namespace SocketHttpListener.Net { // http.sys only supports %uXXXX (4 hex-digits), even though unicode code points could have up to // 6 hex digits. Therefore we parse always 4 characters after %u and convert them to an int. - int codePointValue; - if (!int.TryParse(codePoint, NumberStyles.HexNumber, null, out codePointValue)) + if (!int.TryParse(codePoint, NumberStyles.HexNumber, null, out var codePointValue)) { //if (NetEventSource.IsEnabled) // NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_percent_value, codePoint)); @@ -264,8 +263,7 @@ namespace SocketHttpListener.Net private bool AddPercentEncodedOctetToRawOctetsList(Encoding encoding, string escapedCharacter) { - byte encodedValue; - if (!byte.TryParse(escapedCharacter, NumberStyles.HexNumber, null, out encodedValue)) + if (!byte.TryParse(escapedCharacter, NumberStyles.HexNumber, null, out byte encodedValue)) { //if (NetEventSource.IsEnabled) NetEventSource.Error(this, SR.Format(SR.net_log_listener_cant_convert_percent_value, escapedCharacter)); return false; @@ -327,7 +325,7 @@ namespace SocketHttpListener.Net private static string GetOctetsAsString(IEnumerable<byte> octets) { - StringBuilder octetString = new StringBuilder(); + var octetString = new StringBuilder(); bool first = true; foreach (byte octet in octets) diff --git a/SocketHttpListener/Net/HttpListenerResponse.Managed.cs b/SocketHttpListener/Net/HttpListenerResponse.Managed.cs index 8fb4518a1..9f9b8384d 100644 --- a/SocketHttpListener/Net/HttpListenerResponse.Managed.cs +++ b/SocketHttpListener/Net/HttpListenerResponse.Managed.cs @@ -1,14 +1,13 @@ -using System; -using System.Collections.Generic; +using System; using System.Globalization; using System.IO; using System.Net; using System.Text; +using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Model.IO; using MediaBrowser.Model.Text; using SocketHttpListener.Primitives; -using System.Threading; -using MediaBrowser.Model.IO; namespace SocketHttpListener.Net { @@ -39,7 +38,7 @@ namespace SocketHttpListener.Net public Version ProtocolVersion { - get { return _version; } + get => _version; set { CheckDisposed(); @@ -58,7 +57,7 @@ namespace SocketHttpListener.Net public int StatusCode { - get { return _statusCode; } + get => _statusCode; set { CheckDisposed(); @@ -264,8 +263,8 @@ namespace SocketHttpListener.Net ComputeCookies(); } - Encoding encoding = _textEncoding.GetDefaultEncoding(); - StreamWriter writer = new StreamWriter(ms, encoding, 256); + var encoding = _textEncoding.GetDefaultEncoding(); + var writer = new StreamWriter(ms, encoding, 256); writer.Write("HTTP/1.1 {0} ", _statusCode); // "1.1" matches Windows implementation, which ignores the response version writer.Flush(); byte[] statusDescriptionBytes = WebHeaderEncoding.GetBytes(StatusDescription); diff --git a/SocketHttpListener/Net/HttpListenerResponse.cs b/SocketHttpListener/Net/HttpListenerResponse.cs index 351a206ee..a32aca043 100644 --- a/SocketHttpListener/Net/HttpListenerResponse.cs +++ b/SocketHttpListener/Net/HttpListenerResponse.cs @@ -1,14 +1,7 @@ using System; -using System.Collections.Generic; using System.IO; using System.Net; using System.Text; -using System.Threading.Tasks; -using System.Globalization; -using System.Runtime.InteropServices; -using System.ComponentModel; -using System.Diagnostics; -using Microsoft.Win32.SafeHandles; namespace SocketHttpListener.Net { @@ -22,16 +15,13 @@ namespace SocketHttpListener.Net private string _statusDescription; private WebHeaderCollection _webHeaders = new WebHeaderCollection(); - public WebHeaderCollection Headers - { - get { return _webHeaders; } - } + public WebHeaderCollection Headers => _webHeaders; public Encoding ContentEncoding { get; set; } public string ContentType { - get { return Headers["Content-Type"]; } + get => Headers["Content-Type"]; set { CheckDisposed(); @@ -46,13 +36,13 @@ namespace SocketHttpListener.Net } } - private HttpListenerContext HttpListenerContext { get { return _httpContext; } } + private HttpListenerContext HttpListenerContext => _httpContext; - private HttpListenerRequest HttpListenerRequest { get { return HttpListenerContext.Request; } } + private HttpListenerRequest HttpListenerRequest => HttpListenerContext.Request; internal EntitySendFormat EntitySendFormat { - get { return (EntitySendFormat)_boundaryType; } + get => (EntitySendFormat)_boundaryType; set { CheckDisposed(); @@ -71,8 +61,8 @@ namespace SocketHttpListener.Net public bool SendChunked { - get { return EntitySendFormat == EntitySendFormat.Chunked; } - set { EntitySendFormat = value ? EntitySendFormat.Chunked : EntitySendFormat.ContentLength; } + get => EntitySendFormat == EntitySendFormat.Chunked; + set => EntitySendFormat = value ? EntitySendFormat.Chunked : EntitySendFormat.ContentLength; } // We MUST NOT send message-body when we send responses with these Status codes @@ -92,7 +82,7 @@ namespace SocketHttpListener.Net public long ContentLength64 { - get { return _contentLength; } + get => _contentLength; set { CheckDisposed(); @@ -111,13 +101,13 @@ namespace SocketHttpListener.Net public CookieCollection Cookies { - get { return _cookies ?? (_cookies = new CookieCollection()); } - set { _cookies = value; } + get => _cookies ?? (_cookies = new CookieCollection()); + set => _cookies = value; } public bool KeepAlive { - get { return _keepAlive; } + get => _keepAlive; set { CheckDisposed(); @@ -137,7 +127,7 @@ namespace SocketHttpListener.Net public string RedirectLocation { - get { return Headers["Location"]; } + get => Headers["Location"]; set { // note that this doesn't set the status code to a redirect one diff --git a/SocketHttpListener/Net/HttpRequestStream.Managed.cs b/SocketHttpListener/Net/HttpRequestStream.Managed.cs index 493e2673b..42fc4d97c 100644 --- a/SocketHttpListener/Net/HttpRequestStream.Managed.cs +++ b/SocketHttpListener/Net/HttpRequestStream.Managed.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; +using System; using System.IO; -using System.Runtime.ExceptionServices; -using System.Text; -using System.Threading.Tasks; namespace SocketHttpListener.Net { @@ -128,7 +124,7 @@ namespace SocketHttpListener.Net { if (size == 0 || _closed) { - HttpStreamAsyncResult ares = new HttpStreamAsyncResult(this); + var ares = new HttpStreamAsyncResult(this); ares._callback = cback; ares._state = state; ares.Complete(); @@ -138,7 +134,7 @@ namespace SocketHttpListener.Net int nread = FillFromBuffer(buffer, offset, size); if (nread > 0 || nread == -1) { - HttpStreamAsyncResult ares = new HttpStreamAsyncResult(this); + var ares = new HttpStreamAsyncResult(this); ares._buffer = buffer; ares._offset = offset; ares._count = size; diff --git a/SocketHttpListener/Net/HttpRequestStream.cs b/SocketHttpListener/Net/HttpRequestStream.cs index c9a1d5a2d..1c554df20 100644 --- a/SocketHttpListener/Net/HttpRequestStream.cs +++ b/SocketHttpListener/Net/HttpRequestStream.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; +using System; using System.IO; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -86,25 +84,13 @@ namespace SocketHttpListener.Net public override void Flush() { } public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask; - public override long Length - { - get - { - throw new NotImplementedException(); - } - } + public override long Length => throw new NotImplementedException(); public override long Position { - get - { - throw new NotImplementedException(); - } + get => throw new NotImplementedException(); - set - { - throw new NotImplementedException(); - } + set => throw new NotImplementedException(); } public override long Seek(long offset, SeekOrigin origin) diff --git a/SocketHttpListener/Net/HttpResponseStream.Managed.cs b/SocketHttpListener/Net/HttpResponseStream.Managed.cs index 719dfcc12..5d02a9c95 100644 --- a/SocketHttpListener/Net/HttpResponseStream.Managed.cs +++ b/SocketHttpListener/Net/HttpResponseStream.Managed.cs @@ -1,15 +1,13 @@ -using System; -using System.Collections.Generic; +using System; using System.IO; using System.Net; using System.Net.Sockets; -using System.Runtime.ExceptionServices; using System.Text; using System.Threading; using System.Threading.Tasks; using MediaBrowser.Model.IO; -using Microsoft.Extensions.Logging; using MediaBrowser.Model.System; +using Microsoft.Extensions.Logging; namespace SocketHttpListener.Net { @@ -228,7 +226,7 @@ namespace SocketHttpListener.Net { if (_closed) { - HttpStreamAsyncResult ares = new HttpStreamAsyncResult(this); + var ares = new HttpStreamAsyncResult(this); ares._callback = cback; ares._state = state; ares.Complete(); diff --git a/SocketHttpListener/Net/HttpResponseStream.cs b/SocketHttpListener/Net/HttpResponseStream.cs index 5b7fa417f..085c2ad0c 100644 --- a/SocketHttpListener/Net/HttpResponseStream.cs +++ b/SocketHttpListener/Net/HttpResponseStream.cs @@ -1,7 +1,5 @@ -using System; -using System.Collections.Generic; +using System; using System.IO; -using System.Text; using System.Threading; using System.Threading.Tasks; @@ -19,25 +17,13 @@ namespace SocketHttpListener.Net public override void Flush() { } public override Task FlushAsync(CancellationToken cancellationToken) => Task.CompletedTask; - public override long Length - { - get - { - throw new NotImplementedException(); - } - } + public override long Length => throw new NotImplementedException(); public override long Position { - get - { - throw new NotImplementedException(); - } + get => throw new NotImplementedException(); - set - { - throw new NotImplementedException(); - } + set => throw new NotImplementedException(); } public override long Seek(long offset, SeekOrigin origin) diff --git a/SocketHttpListener/Net/HttpStatusCode.cs b/SocketHttpListener/Net/HttpStatusCode.cs index 93da82ba0..d4bb61b8a 100644 --- a/SocketHttpListener/Net/HttpStatusCode.cs +++ b/SocketHttpListener/Net/HttpStatusCode.cs @@ -1,321 +1,321 @@ namespace SocketHttpListener.Net { - /// <summary> - /// Contains the values of the HTTP status codes. - /// </summary> - /// <remarks> - /// The HttpStatusCode enumeration contains the values of the HTTP status codes defined in - /// <see href="http://tools.ietf.org/html/rfc2616#section-10">RFC 2616</see> for HTTP 1.1. - /// </remarks> - public enum HttpStatusCode - { /// <summary> - /// Equivalent to status code 100. - /// Indicates that the client should continue with its request. - /// </summary> - Continue = 100, - /// <summary> - /// Equivalent to status code 101. - /// Indicates that the server is switching the HTTP version or protocol on the connection. - /// </summary> - SwitchingProtocols = 101, - /// <summary> - /// Equivalent to status code 200. - /// Indicates that the client's request has succeeded. - /// </summary> - OK = 200, - /// <summary> - /// Equivalent to status code 201. - /// Indicates that the client's request has been fulfilled and resulted in a new resource being - /// created. - /// </summary> - Created = 201, - /// <summary> - /// Equivalent to status code 202. - /// Indicates that the client's request has been accepted for processing, but the processing - /// hasn't been completed. - /// </summary> - Accepted = 202, - /// <summary> - /// Equivalent to status code 203. - /// Indicates that the returned metainformation is from a local or a third-party copy instead of - /// the origin server. - /// </summary> - NonAuthoritativeInformation = 203, - /// <summary> - /// Equivalent to status code 204. - /// Indicates that the server has fulfilled the client's request but doesn't need to return - /// an entity-body. - /// </summary> - NoContent = 204, - /// <summary> - /// Equivalent to status code 205. - /// Indicates that the server has fulfilled the client's request, and the user agent should - /// reset the document view which caused the request to be sent. - /// </summary> - ResetContent = 205, - /// <summary> - /// Equivalent to status code 206. - /// Indicates that the server has fulfilled the partial GET request for the resource. - /// </summary> - PartialContent = 206, - /// <summary> - /// <para> - /// Equivalent to status code 300. - /// Indicates that the requested resource corresponds to any of multiple representations. - /// </para> - /// <para> - /// MultipleChoices is a synonym for Ambiguous. - /// </para> - /// </summary> - MultipleChoices = 300, - /// <summary> - /// <para> - /// Equivalent to status code 300. - /// Indicates that the requested resource corresponds to any of multiple representations. - /// </para> - /// <para> - /// Ambiguous is a synonym for MultipleChoices. - /// </para> - /// </summary> - Ambiguous = 300, - /// <summary> - /// <para> - /// Equivalent to status code 301. - /// Indicates that the requested resource has been assigned a new permanent URI and - /// any future references to this resource should use one of the returned URIs. - /// </para> - /// <para> - /// MovedPermanently is a synonym for Moved. - /// </para> - /// </summary> - MovedPermanently = 301, - /// <summary> - /// <para> - /// Equivalent to status code 301. - /// Indicates that the requested resource has been assigned a new permanent URI and - /// any future references to this resource should use one of the returned URIs. - /// </para> - /// <para> - /// Moved is a synonym for MovedPermanently. - /// </para> - /// </summary> - Moved = 301, - /// <summary> - /// <para> - /// Equivalent to status code 302. - /// Indicates that the requested resource is located temporarily under a different URI. - /// </para> - /// <para> - /// Found is a synonym for Redirect. - /// </para> - /// </summary> - Found = 302, - /// <summary> - /// <para> - /// Equivalent to status code 302. - /// Indicates that the requested resource is located temporarily under a different URI. - /// </para> - /// <para> - /// Redirect is a synonym for Found. - /// </para> - /// </summary> - Redirect = 302, - /// <summary> - /// <para> - /// Equivalent to status code 303. - /// Indicates that the response to the request can be found under a different URI and - /// should be retrieved using a GET method on that resource. - /// </para> - /// <para> - /// SeeOther is a synonym for RedirectMethod. - /// </para> - /// </summary> - SeeOther = 303, - /// <summary> - /// <para> - /// Equivalent to status code 303. - /// Indicates that the response to the request can be found under a different URI and - /// should be retrieved using a GET method on that resource. - /// </para> - /// <para> - /// RedirectMethod is a synonym for SeeOther. - /// </para> - /// </summary> - RedirectMethod = 303, - /// <summary> - /// Equivalent to status code 304. - /// Indicates that the client has performed a conditional GET request and access is allowed, - /// but the document hasn't been modified. - /// </summary> - NotModified = 304, - /// <summary> - /// Equivalent to status code 305. - /// Indicates that the requested resource must be accessed through the proxy given by - /// the Location field. - /// </summary> - UseProxy = 305, - /// <summary> - /// Equivalent to status code 306. - /// This status code was used in a previous version of the specification, is no longer used, - /// and is reserved for future use. - /// </summary> - Unused = 306, - /// <summary> - /// <para> - /// Equivalent to status code 307. - /// Indicates that the requested resource is located temporarily under a different URI. - /// </para> - /// <para> - /// TemporaryRedirect is a synonym for RedirectKeepVerb. - /// </para> - /// </summary> - TemporaryRedirect = 307, - /// <summary> - /// <para> - /// Equivalent to status code 307. - /// Indicates that the requested resource is located temporarily under a different URI. - /// </para> - /// <para> - /// RedirectKeepVerb is a synonym for TemporaryRedirect. - /// </para> - /// </summary> - RedirectKeepVerb = 307, - /// <summary> - /// Equivalent to status code 400. - /// Indicates that the client's request couldn't be understood by the server due to - /// malformed syntax. - /// </summary> - BadRequest = 400, - /// <summary> - /// Equivalent to status code 401. - /// Indicates that the client's request requires user authentication. - /// </summary> - Unauthorized = 401, - /// <summary> - /// Equivalent to status code 402. - /// This status code is reserved for future use. - /// </summary> - PaymentRequired = 402, - /// <summary> - /// Equivalent to status code 403. - /// Indicates that the server understood the client's request but is refusing to fulfill it. - /// </summary> - Forbidden = 403, - /// <summary> - /// Equivalent to status code 404. - /// Indicates that the server hasn't found anything matching the request URI. - /// </summary> - NotFound = 404, - /// <summary> - /// Equivalent to status code 405. - /// Indicates that the method specified in the request line isn't allowed for the resource - /// identified by the request URI. - /// </summary> - MethodNotAllowed = 405, - /// <summary> - /// Equivalent to status code 406. - /// Indicates that the server doesn't have the appropriate resource to respond to the Accept - /// headers in the client's request. - /// </summary> - NotAcceptable = 406, - /// <summary> - /// Equivalent to status code 407. - /// Indicates that the client must first authenticate itself with the proxy. - /// </summary> - ProxyAuthenticationRequired = 407, - /// <summary> - /// Equivalent to status code 408. - /// Indicates that the client didn't produce a request within the time that the server was - /// prepared to wait. - /// </summary> - RequestTimeout = 408, - /// <summary> - /// Equivalent to status code 409. - /// Indicates that the client's request couldn't be completed due to a conflict on the server. - /// </summary> - Conflict = 409, - /// <summary> - /// Equivalent to status code 410. - /// Indicates that the requested resource is no longer available at the server and - /// no forwarding address is known. - /// </summary> - Gone = 410, - /// <summary> - /// Equivalent to status code 411. - /// Indicates that the server refuses to accept the client's request without a defined - /// Content-Length. - /// </summary> - LengthRequired = 411, - /// <summary> - /// Equivalent to status code 412. - /// Indicates that the precondition given in one or more of the request headers evaluated to - /// false when it was tested on the server. - /// </summary> - PreconditionFailed = 412, - /// <summary> - /// Equivalent to status code 413. - /// Indicates that the entity of the client's request is larger than the server is willing or - /// able to process. - /// </summary> - RequestEntityTooLarge = 413, - /// <summary> - /// Equivalent to status code 414. - /// Indicates that the request URI is longer than the server is willing to interpret. - /// </summary> - RequestUriTooLong = 414, - /// <summary> - /// Equivalent to status code 415. - /// Indicates that the entity of the client's request is in a format not supported by - /// the requested resource for the requested method. - /// </summary> - UnsupportedMediaType = 415, - /// <summary> - /// Equivalent to status code 416. - /// Indicates that none of the range specifier values in a Range request header overlap - /// the current extent of the selected resource. - /// </summary> - RequestedRangeNotSatisfiable = 416, - /// <summary> - /// Equivalent to status code 417. - /// Indicates that the expectation given in an Expect request header couldn't be met by - /// the server. - /// </summary> - ExpectationFailed = 417, - /// <summary> - /// Equivalent to status code 500. - /// Indicates that the server encountered an unexpected condition which prevented it from - /// fulfilling the client's request. - /// </summary> - InternalServerError = 500, - /// <summary> - /// Equivalent to status code 501. - /// Indicates that the server doesn't support the functionality required to fulfill the client's - /// request. - /// </summary> - NotImplemented = 501, - /// <summary> - /// Equivalent to status code 502. - /// Indicates that a gateway or proxy server received an invalid response from the upstream - /// server. - /// </summary> - BadGateway = 502, - /// <summary> - /// Equivalent to status code 503. - /// Indicates that the server is currently unable to handle the client's request due to - /// a temporary overloading or maintenance of the server. - /// </summary> - ServiceUnavailable = 503, - /// <summary> - /// Equivalent to status code 504. - /// Indicates that a gateway or proxy server didn't receive a timely response from the upstream - /// server or some other auxiliary server. - /// </summary> - GatewayTimeout = 504, - /// <summary> - /// Equivalent to status code 505. - /// Indicates that the server doesn't support the HTTP version used in the client's request. - /// </summary> - HttpVersionNotSupported = 505, - } + /// Contains the values of the HTTP status codes. + /// </summary> + /// <remarks> + /// The HttpStatusCode enumeration contains the values of the HTTP status codes defined in + /// <see href="http://tools.ietf.org/html/rfc2616#section-10">RFC 2616</see> for HTTP 1.1. + /// </remarks> + public enum HttpStatusCode + { + /// <summary> + /// Equivalent to status code 100. + /// Indicates that the client should continue with its request. + /// </summary> + Continue = 100, + /// <summary> + /// Equivalent to status code 101. + /// Indicates that the server is switching the HTTP version or protocol on the connection. + /// </summary> + SwitchingProtocols = 101, + /// <summary> + /// Equivalent to status code 200. + /// Indicates that the client's request has succeeded. + /// </summary> + OK = 200, + /// <summary> + /// Equivalent to status code 201. + /// Indicates that the client's request has been fulfilled and resulted in a new resource being + /// created. + /// </summary> + Created = 201, + /// <summary> + /// Equivalent to status code 202. + /// Indicates that the client's request has been accepted for processing, but the processing + /// hasn't been completed. + /// </summary> + Accepted = 202, + /// <summary> + /// Equivalent to status code 203. + /// Indicates that the returned metainformation is from a local or a third-party copy instead of + /// the origin server. + /// </summary> + NonAuthoritativeInformation = 203, + /// <summary> + /// Equivalent to status code 204. + /// Indicates that the server has fulfilled the client's request but doesn't need to return + /// an entity-body. + /// </summary> + NoContent = 204, + /// <summary> + /// Equivalent to status code 205. + /// Indicates that the server has fulfilled the client's request, and the user agent should + /// reset the document view which caused the request to be sent. + /// </summary> + ResetContent = 205, + /// <summary> + /// Equivalent to status code 206. + /// Indicates that the server has fulfilled the partial GET request for the resource. + /// </summary> + PartialContent = 206, + /// <summary> + /// <para> + /// Equivalent to status code 300. + /// Indicates that the requested resource corresponds to any of multiple representations. + /// </para> + /// <para> + /// MultipleChoices is a synonym for Ambiguous. + /// </para> + /// </summary> + MultipleChoices = 300, + /// <summary> + /// <para> + /// Equivalent to status code 300. + /// Indicates that the requested resource corresponds to any of multiple representations. + /// </para> + /// <para> + /// Ambiguous is a synonym for MultipleChoices. + /// </para> + /// </summary> + Ambiguous = 300, + /// <summary> + /// <para> + /// Equivalent to status code 301. + /// Indicates that the requested resource has been assigned a new permanent URI and + /// any future references to this resource should use one of the returned URIs. + /// </para> + /// <para> + /// MovedPermanently is a synonym for Moved. + /// </para> + /// </summary> + MovedPermanently = 301, + /// <summary> + /// <para> + /// Equivalent to status code 301. + /// Indicates that the requested resource has been assigned a new permanent URI and + /// any future references to this resource should use one of the returned URIs. + /// </para> + /// <para> + /// Moved is a synonym for MovedPermanently. + /// </para> + /// </summary> + Moved = 301, + /// <summary> + /// <para> + /// Equivalent to status code 302. + /// Indicates that the requested resource is located temporarily under a different URI. + /// </para> + /// <para> + /// Found is a synonym for Redirect. + /// </para> + /// </summary> + Found = 302, + /// <summary> + /// <para> + /// Equivalent to status code 302. + /// Indicates that the requested resource is located temporarily under a different URI. + /// </para> + /// <para> + /// Redirect is a synonym for Found. + /// </para> + /// </summary> + Redirect = 302, + /// <summary> + /// <para> + /// Equivalent to status code 303. + /// Indicates that the response to the request can be found under a different URI and + /// should be retrieved using a GET method on that resource. + /// </para> + /// <para> + /// SeeOther is a synonym for RedirectMethod. + /// </para> + /// </summary> + SeeOther = 303, + /// <summary> + /// <para> + /// Equivalent to status code 303. + /// Indicates that the response to the request can be found under a different URI and + /// should be retrieved using a GET method on that resource. + /// </para> + /// <para> + /// RedirectMethod is a synonym for SeeOther. + /// </para> + /// </summary> + RedirectMethod = 303, + /// <summary> + /// Equivalent to status code 304. + /// Indicates that the client has performed a conditional GET request and access is allowed, + /// but the document hasn't been modified. + /// </summary> + NotModified = 304, + /// <summary> + /// Equivalent to status code 305. + /// Indicates that the requested resource must be accessed through the proxy given by + /// the Location field. + /// </summary> + UseProxy = 305, + /// <summary> + /// Equivalent to status code 306. + /// This status code was used in a previous version of the specification, is no longer used, + /// and is reserved for future use. + /// </summary> + Unused = 306, + /// <summary> + /// <para> + /// Equivalent to status code 307. + /// Indicates that the requested resource is located temporarily under a different URI. + /// </para> + /// <para> + /// TemporaryRedirect is a synonym for RedirectKeepVerb. + /// </para> + /// </summary> + TemporaryRedirect = 307, + /// <summary> + /// <para> + /// Equivalent to status code 307. + /// Indicates that the requested resource is located temporarily under a different URI. + /// </para> + /// <para> + /// RedirectKeepVerb is a synonym for TemporaryRedirect. + /// </para> + /// </summary> + RedirectKeepVerb = 307, + /// <summary> + /// Equivalent to status code 400. + /// Indicates that the client's request couldn't be understood by the server due to + /// malformed syntax. + /// </summary> + BadRequest = 400, + /// <summary> + /// Equivalent to status code 401. + /// Indicates that the client's request requires user authentication. + /// </summary> + Unauthorized = 401, + /// <summary> + /// Equivalent to status code 402. + /// This status code is reserved for future use. + /// </summary> + PaymentRequired = 402, + /// <summary> + /// Equivalent to status code 403. + /// Indicates that the server understood the client's request but is refusing to fulfill it. + /// </summary> + Forbidden = 403, + /// <summary> + /// Equivalent to status code 404. + /// Indicates that the server hasn't found anything matching the request URI. + /// </summary> + NotFound = 404, + /// <summary> + /// Equivalent to status code 405. + /// Indicates that the method specified in the request line isn't allowed for the resource + /// identified by the request URI. + /// </summary> + MethodNotAllowed = 405, + /// <summary> + /// Equivalent to status code 406. + /// Indicates that the server doesn't have the appropriate resource to respond to the Accept + /// headers in the client's request. + /// </summary> + NotAcceptable = 406, + /// <summary> + /// Equivalent to status code 407. + /// Indicates that the client must first authenticate itself with the proxy. + /// </summary> + ProxyAuthenticationRequired = 407, + /// <summary> + /// Equivalent to status code 408. + /// Indicates that the client didn't produce a request within the time that the server was + /// prepared to wait. + /// </summary> + RequestTimeout = 408, + /// <summary> + /// Equivalent to status code 409. + /// Indicates that the client's request couldn't be completed due to a conflict on the server. + /// </summary> + Conflict = 409, + /// <summary> + /// Equivalent to status code 410. + /// Indicates that the requested resource is no longer available at the server and + /// no forwarding address is known. + /// </summary> + Gone = 410, + /// <summary> + /// Equivalent to status code 411. + /// Indicates that the server refuses to accept the client's request without a defined + /// Content-Length. + /// </summary> + LengthRequired = 411, + /// <summary> + /// Equivalent to status code 412. + /// Indicates that the precondition given in one or more of the request headers evaluated to + /// false when it was tested on the server. + /// </summary> + PreconditionFailed = 412, + /// <summary> + /// Equivalent to status code 413. + /// Indicates that the entity of the client's request is larger than the server is willing or + /// able to process. + /// </summary> + RequestEntityTooLarge = 413, + /// <summary> + /// Equivalent to status code 414. + /// Indicates that the request URI is longer than the server is willing to interpret. + /// </summary> + RequestUriTooLong = 414, + /// <summary> + /// Equivalent to status code 415. + /// Indicates that the entity of the client's request is in a format not supported by + /// the requested resource for the requested method. + /// </summary> + UnsupportedMediaType = 415, + /// <summary> + /// Equivalent to status code 416. + /// Indicates that none of the range specifier values in a Range request header overlap + /// the current extent of the selected resource. + /// </summary> + RequestedRangeNotSatisfiable = 416, + /// <summary> + /// Equivalent to status code 417. + /// Indicates that the expectation given in an Expect request header couldn't be met by + /// the server. + /// </summary> + ExpectationFailed = 417, + /// <summary> + /// Equivalent to status code 500. + /// Indicates that the server encountered an unexpected condition which prevented it from + /// fulfilling the client's request. + /// </summary> + InternalServerError = 500, + /// <summary> + /// Equivalent to status code 501. + /// Indicates that the server doesn't support the functionality required to fulfill the client's + /// request. + /// </summary> + NotImplemented = 501, + /// <summary> + /// Equivalent to status code 502. + /// Indicates that a gateway or proxy server received an invalid response from the upstream + /// server. + /// </summary> + BadGateway = 502, + /// <summary> + /// Equivalent to status code 503. + /// Indicates that the server is currently unable to handle the client's request due to + /// a temporary overloading or maintenance of the server. + /// </summary> + ServiceUnavailable = 503, + /// <summary> + /// Equivalent to status code 504. + /// Indicates that a gateway or proxy server didn't receive a timely response from the upstream + /// server or some other auxiliary server. + /// </summary> + GatewayTimeout = 504, + /// <summary> + /// Equivalent to status code 505. + /// Indicates that the server doesn't support the HTTP version used in the client's request. + /// </summary> + HttpVersionNotSupported = 505, + } } diff --git a/SocketHttpListener/Net/HttpStatusDescription.cs b/SocketHttpListener/Net/HttpStatusDescription.cs index 9cc4a8e8c..a4e42560b 100644 --- a/SocketHttpListener/Net/HttpStatusDescription.cs +++ b/SocketHttpListener/Net/HttpStatusDescription.cs @@ -1,8 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - namespace SocketHttpListener.Net { internal static class HttpStatusDescription diff --git a/SocketHttpListener/Net/HttpStreamAsyncResult.cs b/SocketHttpListener/Net/HttpStreamAsyncResult.cs index d96988fce..46944c624 100644 --- a/SocketHttpListener/Net/HttpStreamAsyncResult.cs +++ b/SocketHttpListener/Net/HttpStreamAsyncResult.cs @@ -47,10 +47,7 @@ namespace SocketHttpListener.Net } } - public object AsyncState - { - get { return _state; } - } + public object AsyncState => _state; public WaitHandle AsyncWaitHandle { diff --git a/SocketHttpListener/Net/ListenerPrefix.cs b/SocketHttpListener/Net/ListenerPrefix.cs index 99bb118e5..edfcb8904 100644 --- a/SocketHttpListener/Net/ListenerPrefix.cs +++ b/SocketHttpListener/Net/ListenerPrefix.cs @@ -1,6 +1,5 @@ using System; using System.Net; -using MediaBrowser.Model.Net; namespace SocketHttpListener.Net { @@ -27,33 +26,21 @@ namespace SocketHttpListener.Net public IPAddress[] Addresses { - get { return _addresses; } - set { _addresses = value; } - } - public bool Secure - { - get { return _secure; } + get => _addresses; + set => _addresses = value; } + public bool Secure => _secure; - public string Host - { - get { return _host; } - } + public string Host => _host; - public int Port - { - get { return _port; } - } + public int Port => _port; - public string Path - { - get { return _path; } - } + public string Path => _path; // Equals and GetHashCode are required to detect duplicates in HttpListenerPrefixCollection. public override bool Equals(object o) { - ListenerPrefix other = o as ListenerPrefix; + var other = o as ListenerPrefix; if (other == null) return false; diff --git a/SocketHttpListener/Net/UriScheme.cs b/SocketHttpListener/Net/UriScheme.cs index 732fc0e7d..33d1f09db 100644 --- a/SocketHttpListener/Net/UriScheme.cs +++ b/SocketHttpListener/Net/UriScheme.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Text; - namespace SocketHttpListener.Net { internal static class UriScheme diff --git a/SocketHttpListener/Net/WebHeaderCollection.cs b/SocketHttpListener/Net/WebHeaderCollection.cs index ed3cb921c..34fca808b 100644 --- a/SocketHttpListener/Net/WebHeaderCollection.cs +++ b/SocketHttpListener/Net/WebHeaderCollection.cs @@ -1,13 +1,8 @@ using System; -using System.Collections; using System.Collections.Generic; -using System.Collections.Specialized; -using System.Net; using System.Runtime.InteropServices; -using System.Runtime.Serialization; using System.Text; using MediaBrowser.Model.Services; -using MediaBrowser.Model.Extensions; namespace SocketHttpListener.Net { @@ -213,8 +208,7 @@ namespace SocketHttpListener.Net if (!IsHeaderName(headerName)) throw new ArgumentException("Invalid character in header"); - HeaderInfo info; - if (!headers.TryGetValue(headerName, out info)) + if (!headers.TryGetValue(headerName, out HeaderInfo info)) return false; var flag = response ? HeaderInfo.Response : HeaderInfo.Request; @@ -239,7 +233,7 @@ namespace SocketHttpListener.Net internal string ToStringMultiValue() { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); int count = base.Count; for (int i = 0; i < count; i++) @@ -268,7 +262,7 @@ namespace SocketHttpListener.Net public override string ToString() { - StringBuilder sb = new StringBuilder(); + var sb = new StringBuilder(); int count = base.Count; for (int i = 0; i < count; i++) @@ -318,8 +312,7 @@ namespace SocketHttpListener.Net if (headerName == null) return false; - HeaderInfo info; - return headers.TryGetValue(headerName, out info) && (info & HeaderInfo.MultiValue) != 0; + return headers.TryGetValue(headerName, out HeaderInfo info) && (info & HeaderInfo.MultiValue) != 0; } internal static bool IsHeaderValue(string value) diff --git a/SocketHttpListener/Net/WebHeaderEncoding.cs b/SocketHttpListener/Net/WebHeaderEncoding.cs index 7290bfc63..b65ff3c0d 100644 --- a/SocketHttpListener/Net/WebHeaderEncoding.cs +++ b/SocketHttpListener/Net/WebHeaderEncoding.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; using System.Text; -using System.Threading.Tasks; namespace SocketHttpListener.Net { 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 f72a139f3..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.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); diff --git a/SocketHttpListener/Net/WebSockets/WebSocketCloseStatus.cs b/SocketHttpListener/Net/WebSockets/WebSocketCloseStatus.cs index b83b6cd0f..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 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 |
