aboutsummaryrefslogtreecommitdiff
path: root/SocketHttpListener
diff options
context:
space:
mode:
Diffstat (limited to 'SocketHttpListener')
-rw-r--r--SocketHttpListener/ByteOrder.cs24
-rw-r--r--SocketHttpListener/CloseEventArgs.cs131
-rw-r--r--SocketHttpListener/CloseStatusCode.cs178
-rw-r--r--SocketHttpListener/CompressionMethod.cs36
-rw-r--r--SocketHttpListener/ErrorEventArgs.cs62
-rw-r--r--SocketHttpListener/Ext.cs33
-rw-r--r--SocketHttpListener/Fin.cs10
-rw-r--r--SocketHttpListener/HttpBase.cs26
-rw-r--r--SocketHttpListener/HttpResponse.cs54
-rw-r--r--SocketHttpListener/Mask.cs10
-rw-r--r--SocketHttpListener/MessageEventArgs.cs140
-rw-r--r--SocketHttpListener/Net/AuthenticationSchemeSelector.cs2
-rw-r--r--SocketHttpListener/Net/AuthenticationTypes.cs4
-rw-r--r--SocketHttpListener/Net/BoundaryType.cs5
-rw-r--r--SocketHttpListener/Net/ChunkStream.cs34
-rw-r--r--SocketHttpListener/Net/ChunkedInputStream.cs22
-rw-r--r--SocketHttpListener/Net/CookieHelper.cs12
-rw-r--r--SocketHttpListener/Net/EntitySendFormat.cs5
-rw-r--r--SocketHttpListener/Net/HttpConnection.cs54
-rw-r--r--SocketHttpListener/Net/HttpEndPointListener.cs45
-rw-r--r--SocketHttpListener/Net/HttpEndPointManager.cs16
-rw-r--r--SocketHttpListener/Net/HttpKnownHeaderNames.cs4
-rw-r--r--SocketHttpListener/Net/HttpListener.cs44
-rw-r--r--SocketHttpListener/Net/HttpListenerBasicIdentity.cs37
-rw-r--r--SocketHttpListener/Net/HttpListenerContext.Managed.cs9
-rw-r--r--SocketHttpListener/Net/HttpListenerContext.cs26
-rw-r--r--SocketHttpListener/Net/HttpListenerPrefixCollection.cs17
-rw-r--r--SocketHttpListener/Net/HttpListenerRequest.Managed.cs13
-rw-r--r--SocketHttpListener/Net/HttpListenerRequest.cs23
-rw-r--r--SocketHttpListener/Net/HttpListenerRequestUriBuilder.cs26
-rw-r--r--SocketHttpListener/Net/HttpListenerResponse.Managed.cs31
-rw-r--r--SocketHttpListener/Net/HttpListenerResponse.cs38
-rw-r--r--SocketHttpListener/Net/HttpRequestStream.Managed.cs16
-rw-r--r--SocketHttpListener/Net/HttpRequestStream.cs28
-rw-r--r--SocketHttpListener/Net/HttpResponseStream.Managed.cs16
-rw-r--r--SocketHttpListener/Net/HttpResponseStream.cs22
-rw-r--r--SocketHttpListener/Net/HttpStatusCode.cs634
-rw-r--r--SocketHttpListener/Net/HttpStatusDescription.cs5
-rw-r--r--SocketHttpListener/Net/HttpStreamAsyncResult.cs5
-rw-r--r--SocketHttpListener/Net/ListenerPrefix.cs27
-rw-r--r--SocketHttpListener/Net/UriScheme.cs4
-rw-r--r--SocketHttpListener/Net/WebHeaderCollection.cs155
-rw-r--r--SocketHttpListener/Net/WebHeaderEncoding.cs3
-rw-r--r--SocketHttpListener/Net/WebSockets/HttpListenerWebSocketContext.cs6
-rw-r--r--SocketHttpListener/Net/WebSockets/HttpWebSocket.Managed.cs13
-rw-r--r--SocketHttpListener/Net/WebSockets/HttpWebSocket.cs27
-rw-r--r--SocketHttpListener/Net/WebSockets/WebSocketCloseStatus.cs10
-rw-r--r--SocketHttpListener/Net/WebSockets/WebSocketContext.cs2
-rw-r--r--SocketHttpListener/Net/WebSockets/WebSocketValidate.cs6
-rw-r--r--SocketHttpListener/Opcode.cs76
-rw-r--r--SocketHttpListener/PayloadData.cs191
-rw-r--r--SocketHttpListener/Primitives/ITextEncoding.cs21
-rw-r--r--SocketHttpListener/Properties/AssemblyInfo.cs31
-rw-r--r--SocketHttpListener/Rsv.cs10
-rw-r--r--SocketHttpListener/SocketHttpListener.csproj2
-rw-r--r--SocketHttpListener/SocketStream.cs34
-rw-r--r--SocketHttpListener/WebSocket.cs24
-rw-r--r--SocketHttpListener/WebSocketException.cs105
-rw-r--r--SocketHttpListener/WebSocketFrame.cs195
59 files changed, 1148 insertions, 1691 deletions
diff --git a/SocketHttpListener/ByteOrder.cs b/SocketHttpListener/ByteOrder.cs
index f5db52fd7..c04150c74 100644
--- a/SocketHttpListener/ByteOrder.cs
+++ b/SocketHttpListener/ByteOrder.cs
@@ -1,17 +1,17 @@
namespace SocketHttpListener
{
- /// <summary>
- /// Contains the values that indicate whether the byte order is a Little-endian or Big-endian.
- /// </summary>
- public enum ByteOrder : byte
- {
/// <summary>
- /// Indicates a Little-endian.
+ /// Contains the values that indicate whether the byte order is a Little-endian or Big-endian.
/// </summary>
- Little,
- /// <summary>
- /// Indicates a Big-endian.
- /// </summary>
- Big
- }
+ public enum ByteOrder : byte
+ {
+ /// <summary>
+ /// Indicates a Little-endian.
+ /// </summary>
+ Little,
+ /// <summary>
+ /// Indicates a Big-endian.
+ /// </summary>
+ Big
+ }
}
diff --git a/SocketHttpListener/CloseEventArgs.cs b/SocketHttpListener/CloseEventArgs.cs
index b1bb4b196..c6460fd23 100644
--- a/SocketHttpListener/CloseEventArgs.cs
+++ b/SocketHttpListener/CloseEventArgs.cs
@@ -3,88 +3,77 @@ using System.Text;
namespace SocketHttpListener
{
- /// <summary>
- /// Contains the event data associated with a <see cref="WebSocket.OnClose"/> event.
- /// </summary>
- /// <remarks>
- /// A <see cref="WebSocket.OnClose"/> event occurs when the WebSocket connection has been closed.
- /// If you would like to get the reason for the close, you should access the <see cref="Code"/> or
- /// <see cref="Reason"/> property.
- /// </remarks>
- public class CloseEventArgs : EventArgs
- {
- #region Private Fields
+ /// <summary>
+ /// Contains the event data associated with a <see cref="WebSocket.OnClose"/> event.
+ /// </summary>
+ /// <remarks>
+ /// A <see cref="WebSocket.OnClose"/> event occurs when the WebSocket connection has been closed.
+ /// If you would like to get the reason for the close, you should access the <see cref="Code"/> or
+ /// <see cref="Reason"/> property.
+ /// </remarks>
+ public class CloseEventArgs : EventArgs
+ {
+ #region Private Fields
- private bool _clean;
- private ushort _code;
- private string _reason;
+ private bool _clean;
+ private ushort _code;
+ private string _reason;
- #endregion
+ #endregion
- #region Internal Constructors
+ #region Internal Constructors
- internal CloseEventArgs (PayloadData payload)
- {
- var data = payload.ApplicationData;
- var len = data.Length;
- _code = len > 1
- ? data.SubArray (0, 2).ToUInt16 (ByteOrder.Big)
- : (ushort) CloseStatusCode.NoStatusCode;
+ internal CloseEventArgs(PayloadData payload)
+ {
+ var data = payload.ApplicationData;
+ var len = data.Length;
+ _code = len > 1
+ ? data.SubArray(0, 2).ToUInt16(ByteOrder.Big)
+ : (ushort)CloseStatusCode.NoStatusCode;
- _reason = len > 2
- ? GetUtf8String(data.SubArray (2, len - 2))
- : String.Empty;
- }
+ _reason = len > 2
+ ? GetUtf8String(data.SubArray(2, len - 2))
+ : string.Empty;
+ }
- private string GetUtf8String(byte[] bytes)
- {
- return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
- }
+ private static string GetUtf8String(byte[] bytes)
+ {
+ return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
+ }
- #endregion
+ #endregion
- #region Public Properties
+ #region Public Properties
- /// <summary>
- /// Gets the status code for the close.
- /// </summary>
- /// <value>
- /// A <see cref="ushort"/> that represents the status code for the close if any.
- /// </value>
- public ushort Code {
- get {
- return _code;
- }
- }
+ /// <summary>
+ /// Gets the status code for the close.
+ /// </summary>
+ /// <value>
+ /// A <see cref="ushort"/> that represents the status code for the close if any.
+ /// </value>
+ public ushort Code => _code;
- /// <summary>
- /// Gets the reason for the close.
- /// </summary>
- /// <value>
- /// A <see cref="string"/> that represents the reason for the close if any.
- /// </value>
- public string Reason {
- get {
- return _reason;
- }
- }
+ /// <summary>
+ /// Gets the reason for the close.
+ /// </summary>
+ /// <value>
+ /// A <see cref="string"/> that represents the reason for the close if any.
+ /// </value>
+ public string Reason => _reason;
- /// <summary>
- /// Gets a value indicating whether the WebSocket connection has been closed cleanly.
- /// </summary>
- /// <value>
- /// <c>true</c> if the WebSocket connection has been closed cleanly; otherwise, <c>false</c>.
- /// </value>
- public bool WasClean {
- get {
- return _clean;
- }
+ /// <summary>
+ /// Gets a value indicating whether the WebSocket connection has been closed cleanly.
+ /// </summary>
+ /// <value>
+ /// <c>true</c> if the WebSocket connection has been closed cleanly; otherwise, <c>false</c>.
+ /// </value>
+ public bool WasClean
+ {
+ get => _clean;
- internal set {
- _clean = value;
- }
- }
+ internal set => _clean = value;
+ }
- #endregion
- }
+ #endregion
+ }
}
diff --git a/SocketHttpListener/CloseStatusCode.cs b/SocketHttpListener/CloseStatusCode.cs
index 62a268bce..428595bb0 100644
--- a/SocketHttpListener/CloseStatusCode.cs
+++ b/SocketHttpListener/CloseStatusCode.cs
@@ -1,94 +1,94 @@
namespace SocketHttpListener
{
- /// <summary>
- /// Contains the values of the status code for the WebSocket connection close.
- /// </summary>
- /// <remarks>
- /// <para>
- /// The values of the status code are defined in
- /// <see href="http://tools.ietf.org/html/rfc6455#section-7.4">Section 7.4</see>
- /// of RFC 6455.
- /// </para>
- /// <para>
- /// "Reserved value" must not be set as a status code in a close control frame
- /// by an endpoint. It's designated for use in applications expecting a status
- /// code to indicate that the connection was closed due to the system grounds.
- /// </para>
- /// </remarks>
- public enum CloseStatusCode : ushort
- {
/// <summary>
- /// Equivalent to close status 1000.
- /// Indicates a normal close.
+ /// Contains the values of the status code for the WebSocket connection close.
/// </summary>
- Normal = 1000,
- /// <summary>
- /// Equivalent to close status 1001.
- /// Indicates that an endpoint is going away.
- /// </summary>
- Away = 1001,
- /// <summary>
- /// Equivalent to close status 1002.
- /// Indicates that an endpoint is terminating the connection due to a protocol error.
- /// </summary>
- ProtocolError = 1002,
- /// <summary>
- /// Equivalent to close status 1003.
- /// Indicates that an endpoint is terminating the connection because it has received
- /// an unacceptable type message.
- /// </summary>
- IncorrectData = 1003,
- /// <summary>
- /// Equivalent to close status 1004.
- /// Still undefined. Reserved value.
- /// </summary>
- Undefined = 1004,
- /// <summary>
- /// Equivalent to close status 1005.
- /// Indicates that no status code was actually present. Reserved value.
- /// </summary>
- NoStatusCode = 1005,
- /// <summary>
- /// Equivalent to close status 1006.
- /// Indicates that the connection was closed abnormally. Reserved value.
- /// </summary>
- Abnormal = 1006,
- /// <summary>
- /// Equivalent to close status 1007.
- /// Indicates that an endpoint is terminating the connection because it has received
- /// a message that contains a data that isn't consistent with the type of the message.
- /// </summary>
- InconsistentData = 1007,
- /// <summary>
- /// Equivalent to close status 1008.
- /// Indicates that an endpoint is terminating the connection because it has received
- /// a message that violates its policy.
- /// </summary>
- PolicyViolation = 1008,
- /// <summary>
- /// Equivalent to close status 1009.
- /// Indicates that an endpoint is terminating the connection because it has received
- /// a message that is too big to process.
- /// </summary>
- TooBig = 1009,
- /// <summary>
- /// Equivalent to close status 1010.
- /// Indicates that the client is terminating the connection because it has expected
- /// the server to negotiate one or more extension, but the server didn't return them
- /// in the handshake response.
- /// </summary>
- IgnoreExtension = 1010,
- /// <summary>
- /// Equivalent to close status 1011.
- /// Indicates that the server is terminating the connection because it has encountered
- /// an unexpected condition that prevented it from fulfilling the request.
- /// </summary>
- ServerError = 1011,
- /// <summary>
- /// Equivalent to close status 1015.
- /// Indicates that the connection was closed due to a failure to perform a TLS handshake.
- /// Reserved value.
- /// </summary>
- TlsHandshakeFailure = 1015
- }
+ /// <remarks>
+ /// <para>
+ /// The values of the status code are defined in
+ /// <see href="http://tools.ietf.org/html/rfc6455#section-7.4">Section 7.4</see>
+ /// of RFC 6455.
+ /// </para>
+ /// <para>
+ /// "Reserved value" must not be set as a status code in a close control frame
+ /// by an endpoint. It's designated for use in applications expecting a status
+ /// code to indicate that the connection was closed due to the system grounds.
+ /// </para>
+ /// </remarks>
+ public enum CloseStatusCode : ushort
+ {
+ /// <summary>
+ /// Equivalent to close status 1000.
+ /// Indicates a normal close.
+ /// </summary>
+ Normal = 1000,
+ /// <summary>
+ /// Equivalent to close status 1001.
+ /// Indicates that an endpoint is going away.
+ /// </summary>
+ Away = 1001,
+ /// <summary>
+ /// Equivalent to close status 1002.
+ /// Indicates that an endpoint is terminating the connection due to a protocol error.
+ /// </summary>
+ ProtocolError = 1002,
+ /// <summary>
+ /// Equivalent to close status 1003.
+ /// Indicates that an endpoint is terminating the connection because it has received
+ /// an unacceptable type message.
+ /// </summary>
+ IncorrectData = 1003,
+ /// <summary>
+ /// Equivalent to close status 1004.
+ /// Still undefined. Reserved value.
+ /// </summary>
+ Undefined = 1004,
+ /// <summary>
+ /// Equivalent to close status 1005.
+ /// Indicates that no status code was actually present. Reserved value.
+ /// </summary>
+ NoStatusCode = 1005,
+ /// <summary>
+ /// Equivalent to close status 1006.
+ /// Indicates that the connection was closed abnormally. Reserved value.
+ /// </summary>
+ Abnormal = 1006,
+ /// <summary>
+ /// Equivalent to close status 1007.
+ /// Indicates that an endpoint is terminating the connection because it has received
+ /// a message that contains a data that isn't consistent with the type of the message.
+ /// </summary>
+ InconsistentData = 1007,
+ /// <summary>
+ /// Equivalent to close status 1008.
+ /// Indicates that an endpoint is terminating the connection because it has received
+ /// a message that violates its policy.
+ /// </summary>
+ PolicyViolation = 1008,
+ /// <summary>
+ /// Equivalent to close status 1009.
+ /// Indicates that an endpoint is terminating the connection because it has received
+ /// a message that is too big to process.
+ /// </summary>
+ TooBig = 1009,
+ /// <summary>
+ /// Equivalent to close status 1010.
+ /// Indicates that the client is terminating the connection because it has expected
+ /// the server to negotiate one or more extension, but the server didn't return them
+ /// in the handshake response.
+ /// </summary>
+ IgnoreExtension = 1010,
+ /// <summary>
+ /// Equivalent to close status 1011.
+ /// Indicates that the server is terminating the connection because it has encountered
+ /// an unexpected condition that prevented it from fulfilling the request.
+ /// </summary>
+ ServerError = 1011,
+ /// <summary>
+ /// Equivalent to close status 1015.
+ /// Indicates that the connection was closed due to a failure to perform a TLS handshake.
+ /// Reserved value.
+ /// </summary>
+ TlsHandshakeFailure = 1015
+ }
}
diff --git a/SocketHttpListener/CompressionMethod.cs b/SocketHttpListener/CompressionMethod.cs
index 36a48d94c..d6bcd63d8 100644
--- a/SocketHttpListener/CompressionMethod.cs
+++ b/SocketHttpListener/CompressionMethod.cs
@@ -1,23 +1,23 @@
namespace SocketHttpListener
{
- /// <summary>
- /// Contains the values of the compression method used to compress the message on the WebSocket
- /// connection.
- /// </summary>
- /// <remarks>
- /// The values of the compression method are defined in
- /// <see href="http://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-09">Compression
- /// Extensions for WebSocket</see>.
- /// </remarks>
- public enum CompressionMethod : byte
- {
/// <summary>
- /// Indicates non compression.
+ /// Contains the values of the compression method used to compress the message on the WebSocket
+ /// connection.
/// </summary>
- None,
- /// <summary>
- /// Indicates using DEFLATE.
- /// </summary>
- Deflate
- }
+ /// <remarks>
+ /// The values of the compression method are defined in
+ /// <see href="http://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-09">Compression
+ /// Extensions for WebSocket</see>.
+ /// </remarks>
+ public enum CompressionMethod : byte
+ {
+ /// <summary>
+ /// Indicates non compression.
+ /// </summary>
+ None,
+ /// <summary>
+ /// Indicates using DEFLATE.
+ /// </summary>
+ Deflate
+ }
}
diff --git a/SocketHttpListener/ErrorEventArgs.cs b/SocketHttpListener/ErrorEventArgs.cs
index bf1d6fc95..9502d2a15 100644
--- a/SocketHttpListener/ErrorEventArgs.cs
+++ b/SocketHttpListener/ErrorEventArgs.cs
@@ -2,45 +2,41 @@ using System;
namespace SocketHttpListener
{
- /// <summary>
- /// Contains the event data associated with a <see cref="WebSocket.OnError"/> event.
- /// </summary>
- /// <remarks>
- /// A <see cref="WebSocket.OnError"/> event occurs when the <see cref="WebSocket"/> gets an error.
- /// If you would like to get the error message, you should access the <see cref="Message"/>
- /// property.
- /// </remarks>
- public class ErrorEventArgs : EventArgs
- {
- #region Private Fields
+ /// <summary>
+ /// Contains the event data associated with a <see cref="WebSocket.OnError"/> event.
+ /// </summary>
+ /// <remarks>
+ /// A <see cref="WebSocket.OnError"/> event occurs when the <see cref="WebSocket"/> gets an error.
+ /// If you would like to get the error message, you should access the <see cref="Message"/>
+ /// property.
+ /// </remarks>
+ public class ErrorEventArgs : EventArgs
+ {
+ #region Private Fields
- private string _message;
+ private string _message;
- #endregion
+ #endregion
- #region Internal Constructors
+ #region Internal Constructors
- internal ErrorEventArgs (string message)
- {
- _message = message;
- }
+ internal ErrorEventArgs(string message)
+ {
+ _message = message;
+ }
- #endregion
+ #endregion
- #region Public Properties
+ #region Public Properties
- /// <summary>
- /// Gets the error message.
- /// </summary>
- /// <value>
- /// A <see cref="string"/> that represents the error message.
- /// </value>
- public string Message {
- get {
- return _message;
- }
- }
+ /// <summary>
+ /// Gets the error message.
+ /// </summary>
+ /// <value>
+ /// A <see cref="string"/> that represents the error message.
+ /// </value>
+ public string Message => _message;
- #endregion
- }
+ #endregion
+ }
}
diff --git a/SocketHttpListener/Ext.cs b/SocketHttpListener/Ext.cs
index 125775180..b051b6718 100644
--- a/SocketHttpListener/Ext.cs
+++ b/SocketHttpListener/Ext.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Collections.Specialized;
using System.IO;
using System.IO.Compression;
using System.Net;
@@ -149,7 +148,7 @@ namespace SocketHttpListener
internal static string CheckIfValidControlData(this byte[] data, string paramName)
{
return data.Length > 125
- ? String.Format("'{0}' length must be less.", paramName)
+ ? string.Format("'{0}' length must be less.", paramName)
: null;
}
@@ -222,7 +221,7 @@ namespace SocketHttpListener
internal static bool EqualsWith(this int value, char c, Action<int> action)
{
if (value < 0 || value > 255)
- throw new ArgumentOutOfRangeException("value");
+ throw new ArgumentOutOfRangeException(nameof(value));
action(value);
return value == c - 0;
@@ -248,7 +247,7 @@ namespace SocketHttpListener
? "WebSocket server got an internal error."
: code == CloseStatusCode.TlsHandshakeFailure
? "An error has occurred while handshaking."
- : String.Empty;
+ : string.Empty;
}
internal static string GetNameInternal(this string nameAndValue, string separator)
@@ -329,7 +328,7 @@ namespace SocketHttpListener
{
return value.IsToken()
? value
- : String.Format("\"{0}\"", value.Replace("\"", "\\\""));
+ : string.Format("\"{0}\"", value.Replace("\"", "\\\""));
}
internal static byte[] ReadBytes(this Stream stream, int length)
@@ -441,7 +440,8 @@ namespace SocketHttpListener
continue;
}
}
- else {
+ else
+ {
}
buffer.Append(c);
@@ -484,13 +484,13 @@ namespace SocketHttpListener
this CompressionMethod method, params string[] parameters)
{
if (method == CompressionMethod.None)
- return String.Empty;
+ return string.Empty;
- var m = String.Format("permessage-{0}", method.ToString().ToLower());
+ var m = string.Format("permessage-{0}", method.ToString().ToLower());
if (parameters == null || parameters.Length == 0)
return m;
- return String.Format("{0}; {1}", m, parameters.ToString("; "));
+ return string.Format("{0}; {1}", m, parameters.ToString("; "));
}
internal static List<TSource> ToList<TSource>(this IEnumerable<TSource> source)
@@ -715,7 +715,7 @@ namespace SocketHttpListener
case 507: return "Insufficient Storage";
}
- return String.Empty;
+ return string.Empty;
}
/// <summary>
@@ -855,7 +855,7 @@ namespace SocketHttpListener
public static byte[] ToHostOrder(this byte[] src, ByteOrder srcOrder)
{
if (src == null)
- throw new ArgumentNullException("src");
+ throw new ArgumentNullException(nameof(src));
return src.Length > 1 && !srcOrder.IsHostOrder()
? src.Reverse()
@@ -886,14 +886,14 @@ namespace SocketHttpListener
public static string ToString<T>(this T[] array, string separator)
{
if (array == null)
- throw new ArgumentNullException("array");
+ throw new ArgumentNullException(nameof(array));
var len = array.Length;
if (len == 0)
- return String.Empty;
+ return string.Empty;
if (separator == null)
- separator = String.Empty;
+ separator = string.Empty;
var buff = new StringBuilder(64);
(len - 1).Times(i => buff.AppendFormat("{0}{1}", array[i].ToString(), separator));
@@ -932,9 +932,8 @@ namespace SocketHttpListener
/// </param>
public static Uri ToUri(this string uriString)
{
- Uri res;
return Uri.TryCreate(
- uriString, uriString.MaybeUri() ? UriKind.Absolute : UriKind.Relative, out res)
+ uriString, uriString.MaybeUri() ? UriKind.Absolute : UriKind.Relative, out var res)
? res
: null;
}
@@ -958,4 +957,4 @@ namespace SocketHttpListener
#endregion
}
-} \ No newline at end of file
+}
diff --git a/SocketHttpListener/Fin.cs b/SocketHttpListener/Fin.cs
index f91401b99..c8ffbf2b2 100644
--- a/SocketHttpListener/Fin.cs
+++ b/SocketHttpListener/Fin.cs
@@ -1,8 +1,8 @@
namespace SocketHttpListener
{
- internal enum Fin : byte
- {
- More = 0x0,
- Final = 0x1
- }
+ internal enum Fin : byte
+ {
+ More = 0x0,
+ Final = 0x1
+ }
}
diff --git a/SocketHttpListener/HttpBase.cs b/SocketHttpListener/HttpBase.cs
index 5172ba497..fea91d84b 100644
--- a/SocketHttpListener/HttpBase.cs
+++ b/SocketHttpListener/HttpBase.cs
@@ -1,9 +1,5 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.Specialized;
-using System.IO;
+using System;
using System.Text;
-using System.Threading;
using MediaBrowser.Model.Services;
namespace SocketHttpListener
@@ -49,25 +45,13 @@ namespace SocketHttpListener
return data != null && data.Length > 0
? getEncoding(_headers["Content-Type"]).GetString(data, 0, data.Length)
- : String.Empty;
+ : string.Empty;
}
}
- public QueryParamCollection Headers
- {
- get
- {
- return _headers;
- }
- }
+ public QueryParamCollection Headers => _headers;
- public Version ProtocolVersion
- {
- get
- {
- return _version;
- }
- }
+ public Version ProtocolVersion => _version;
#endregion
@@ -101,4 +85,4 @@ namespace SocketHttpListener
#endregion
}
-} \ No newline at end of file
+}
diff --git a/SocketHttpListener/HttpResponse.cs b/SocketHttpListener/HttpResponse.cs
index 154a3d8e9..bcfa4a906 100644
--- a/SocketHttpListener/HttpResponse.cs
+++ b/SocketHttpListener/HttpResponse.cs
@@ -1,13 +1,11 @@
-using System;
-using System.Collections.Specialized;
-using System.IO;
+using System;
+using System.Linq;
using System.Net;
using System.Text;
-using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
-using HttpVersion = SocketHttpListener.Net.HttpVersion;
-using System.Linq;
using MediaBrowser.Model.Services;
using SocketHttpListener.Net;
+using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
+using HttpVersion = SocketHttpListener.Net.HttpVersion;
namespace SocketHttpListener
{
@@ -48,15 +46,9 @@ namespace SocketHttpListener
#region Public Properties
- public CookieCollection Cookies
- {
- get
- {
- return GetCookies(Headers, true);
- }
- }
+ public CookieCollection Cookies => GetCookies(Headers, true);
- private CookieCollection GetCookies(QueryParamCollection headers, bool response)
+ private static CookieCollection GetCookies(QueryParamCollection headers, bool response)
{
var name = response ? "Set-Cookie" : "Cookie";
return headers == null || !headers.Contains(name)
@@ -64,21 +56,9 @@ namespace SocketHttpListener
: CookieHelper.Parse(headers[name], response);
}
- public bool IsProxyAuthenticationRequired
- {
- get
- {
- return _code == "407";
- }
- }
+ public bool IsProxyAuthenticationRequired => _code == "407";
- public bool IsUnauthorized
- {
- get
- {
- return _code == "401";
- }
- }
+ public bool IsUnauthorized => _code == "401";
public bool IsWebSocketResponse
{
@@ -92,21 +72,9 @@ namespace SocketHttpListener
}
}
- public string Reason
- {
- get
- {
- return _reason;
- }
- }
+ public string Reason => _reason;
- public string StatusCode
- {
- get
- {
- return _code;
- }
- }
+ public string StatusCode => _code;
#endregion
@@ -156,4 +124,4 @@ namespace SocketHttpListener
#endregion
}
-} \ No newline at end of file
+}
diff --git a/SocketHttpListener/Mask.cs b/SocketHttpListener/Mask.cs
index adc2f098e..c56f5b08c 100644
--- a/SocketHttpListener/Mask.cs
+++ b/SocketHttpListener/Mask.cs
@@ -1,8 +1,8 @@
namespace SocketHttpListener
{
- internal enum Mask : byte
- {
- Unmask = 0x0,
- Mask = 0x1
- }
+ internal enum Mask : byte
+ {
+ Unmask = 0x0,
+ Mask = 0x1
+ }
}
diff --git a/SocketHttpListener/MessageEventArgs.cs b/SocketHttpListener/MessageEventArgs.cs
index 9dbadb9ab..8e2151cb7 100644
--- a/SocketHttpListener/MessageEventArgs.cs
+++ b/SocketHttpListener/MessageEventArgs.cs
@@ -3,94 +3,82 @@ using System.Text;
namespace SocketHttpListener
{
- /// <summary>
- /// Contains the event data associated with a <see cref="WebSocket.OnMessage"/> event.
- /// </summary>
- /// <remarks>
- /// A <see cref="WebSocket.OnMessage"/> event occurs when the <see cref="WebSocket"/> receives
- /// a text or binary data frame.
- /// If you want to get the received data, you access the <see cref="MessageEventArgs.Data"/> or
- /// <see cref="MessageEventArgs.RawData"/> property.
- /// </remarks>
- public class MessageEventArgs : EventArgs
- {
- #region Private Fields
+ /// <summary>
+ /// Contains the event data associated with a <see cref="WebSocket.OnMessage"/> event.
+ /// </summary>
+ /// <remarks>
+ /// A <see cref="WebSocket.OnMessage"/> event occurs when the <see cref="WebSocket"/> receives
+ /// a text or binary data frame.
+ /// If you want to get the received data, you access the <see cref="Data"/> or
+ /// <see cref="RawData"/> property.
+ /// </remarks>
+ public class MessageEventArgs : EventArgs
+ {
+ #region Private Fields
- private string _data;
- private Opcode _opcode;
- private byte[] _rawData;
+ private string _data;
+ private Opcode _opcode;
+ private byte[] _rawData;
- #endregion
+ #endregion
- #region Internal Constructors
+ #region Internal Constructors
- internal MessageEventArgs (Opcode opcode, byte[] data)
- {
- _opcode = opcode;
- _rawData = data;
- _data = convertToString (opcode, data);
- }
+ internal MessageEventArgs(Opcode opcode, byte[] data)
+ {
+ _opcode = opcode;
+ _rawData = data;
+ _data = convertToString(opcode, data);
+ }
- internal MessageEventArgs (Opcode opcode, PayloadData payload)
- {
- _opcode = opcode;
- _rawData = payload.ApplicationData;
- _data = convertToString (opcode, _rawData);
- }
+ internal MessageEventArgs(Opcode opcode, PayloadData payload)
+ {
+ _opcode = opcode;
+ _rawData = payload.ApplicationData;
+ _data = convertToString(opcode, _rawData);
+ }
- #endregion
+ #endregion
- #region Public Properties
+ #region Public Properties
- /// <summary>
- /// Gets the received data as a <see cref="string"/>.
- /// </summary>
- /// <value>
- /// A <see cref="string"/> that contains the received data.
- /// </value>
- public string Data {
- get {
- return _data;
- }
- }
+ /// <summary>
+ /// Gets the received data as a <see cref="string"/>.
+ /// </summary>
+ /// <value>
+ /// A <see cref="string"/> that contains the received data.
+ /// </value>
+ public string Data => _data;
- /// <summary>
- /// Gets the received data as an array of <see cref="byte"/>.
- /// </summary>
- /// <value>
- /// An array of <see cref="byte"/> that contains the received data.
- /// </value>
- public byte [] RawData {
- get {
- return _rawData;
- }
- }
+ /// <summary>
+ /// Gets the received data as an array of <see cref="byte"/>.
+ /// </summary>
+ /// <value>
+ /// An array of <see cref="byte"/> that contains the received data.
+ /// </value>
+ public byte[] RawData => _rawData;
- /// <summary>
- /// Gets the type of the received data.
- /// </summary>
- /// <value>
- /// One of the <see cref="Opcode"/> values, indicates the type of the received data.
- /// </value>
- public Opcode Type {
- get {
- return _opcode;
- }
- }
+ /// <summary>
+ /// Gets the type of the received data.
+ /// </summary>
+ /// <value>
+ /// One of the <see cref="Opcode"/> values, indicates the type of the received data.
+ /// </value>
+ public Opcode Type => _opcode;
- #endregion
+ #endregion
- #region Private Methods
+ #region Private Methods
- private static string convertToString (Opcode opcode, byte [] data)
- {
- return data.Length == 0
- ? String.Empty
- : opcode == Opcode.Text
- ? Encoding.UTF8.GetString (data, 0, data.Length)
- : opcode.ToString ();
- }
+ private static string convertToString(Opcode opcode, byte[] data)
+ {
+ return data.Length == 0
+ ? string.Empty
+ : opcode == Opcode.Text
+ ? Encoding.UTF8.GetString(data, 0, data.Length)
+ : opcode.ToString();
+ }
- #endregion
- }
+ #endregion
+ }
}
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 b41285dbc..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;
@@ -14,7 +13,7 @@ namespace SocketHttpListener.Net
// System.Net.ResponseStream
//
// Author:
- // Gonzalo Paniagua Javier (gonzalo@novell.com)
+ // Gonzalo Paniagua Javier (gonzalo@novell.com)
//
// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
//
@@ -25,10 +24,10 @@ namespace SocketHttpListener.Net
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
- //
+ //
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
- //
+ //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -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)
{
@@ -271,7 +261,7 @@ namespace SocketHttpListener.Net
{
if (_saved.Length > 0)
{
- _chunkSize = Int32.Parse(RemoveChunkExtension(_saved.ToString()), NumberStyles.HexNumber);
+ _chunkSize = int.Parse(RemoveChunkExtension(_saved.ToString()), NumberStyles.HexNumber);
}
}
catch (Exception)
@@ -285,7 +275,7 @@ namespace SocketHttpListener.Net
_chunkRead = 0;
try
{
- _chunkSize = Int32.Parse(RemoveChunkExtension(_saved.ToString()), NumberStyles.HexNumber);
+ _chunkSize = int.Parse(RemoveChunkExtension(_saved.ToString()), NumberStyles.HexNumber);
}
catch (Exception)
{
@@ -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 919bd95ea..7aa8529e3 100644
--- a/SocketHttpListener/Net/ChunkedInputStream.cs
+++ b/SocketHttpListener/Net/ChunkedInputStream.cs
@@ -1,8 +1,6 @@
using System;
using System.IO;
using System.Net;
-using System.Runtime.InteropServices;
-using SocketHttpListener.Primitives;
namespace SocketHttpListener.Net
{
@@ -12,7 +10,7 @@ namespace SocketHttpListener.Net
// System.Net.ResponseStream
//
// Author:
- // Gonzalo Paniagua Javier (gonzalo@novell.com)
+ // Gonzalo Paniagua Javier (gonzalo@novell.com)
//
// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
//
@@ -23,10 +21,10 @@ namespace SocketHttpListener.Net
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
- //
+ //
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
- //
+ //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -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 a32131956..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
{
@@ -36,7 +35,7 @@ namespace SocketHttpListener.Net
if (pair.StartsWith("version", StringComparison.OrdinalIgnoreCase))
{
if (cookie != null)
- cookie.Version = Int32.Parse(pair.GetValueInternal("=").Trim('"'));
+ cookie.Version = int.Parse(pair.GetValueInternal("=").Trim('"'));
}
else if (pair.StartsWith("expires", StringComparison.OrdinalIgnoreCase))
{
@@ -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)
@@ -58,7 +56,7 @@ namespace SocketHttpListener.Net
}
else if (pair.StartsWith("max-age", StringComparison.OrdinalIgnoreCase))
{
- var max = Int32.Parse(pair.GetValueInternal("=").Trim('"'));
+ var max = int.Parse(pair.GetValueInternal("=").Trim('"'));
var expires = DateTime.Now.AddSeconds((double)max);
if (cookie != null)
cookie.Expires = expires;
@@ -113,7 +111,7 @@ namespace SocketHttpListener.Net
cookies.Add(cookie);
string name;
- string val = String.Empty;
+ string val = string.Empty;
var pos = pair.IndexOf('=');
if (pos == -1)
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..f11cb0725 100644
--- a/SocketHttpListener/Net/HttpConnection.cs
+++ b/SocketHttpListener/Net/HttpConnection.cs
@@ -3,19 +3,15 @@ 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 SocketHttpListener.Primitives;
-using System.Security.Authentication;
-
-using System.Threading;
+using Microsoft.Extensions.Logging;
namespace SocketHttpListener.Net
{
sealed class HttpConnection
@@ -46,11 +42,12 @@ namespace SocketHttpListener.Net
private readonly ILogger _logger;
private readonly ICryptoProvider _cryptoProvider;
private readonly IStreamHelper _streamHelper;
- private readonly ITextEncoding _textEncoding;
private readonly IFileSystem _fileSystem;
private readonly IEnvironmentInfo _environment;
- public HttpConnection(ILogger logger, Socket socket, HttpEndPointListener epl, bool secure, X509Certificate cert, ICryptoProvider cryptoProvider, IStreamHelper streamHelper, ITextEncoding textEncoding, IFileSystem fileSystem, IEnvironmentInfo environment)
+ public HttpConnection(ILogger logger, Socket socket, HttpEndPointListener epl, bool secure,
+ X509Certificate cert, ICryptoProvider cryptoProvider, IStreamHelper streamHelper, IFileSystem fileSystem,
+ IEnvironmentInfo environment)
{
_logger = logger;
this._socket = socket;
@@ -59,7 +56,6 @@ namespace SocketHttpListener.Net
this.cert = cert;
_cryptoProvider = cryptoProvider;
_streamHelper = streamHelper;
- _textEncoding = textEncoding;
_fileSystem = fileSystem;
_environment = environment;
@@ -91,13 +87,7 @@ namespace SocketHttpListener.Net
}
}
- public Stream Stream
- {
- get
- {
- return _stream;
- }
- }
+ public Stream Stream => _stream;
public async Task Init()
{
@@ -130,18 +120,12 @@ namespace SocketHttpListener.Net
_position = 0;
_inputState = InputState.RequestLine;
_lineState = LineState.None;
- _context = new HttpListenerContext(this, _textEncoding);
+ _context = new HttpListenerContext(this);
}
- 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 +139,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 +210,7 @@ namespace SocketHttpListener.Net
private static void OnRead(IAsyncResult ares)
{
- HttpConnection cnc = (HttpConnection)ares.AsyncState;
+ var cnc = (HttpConnection)ares.AsyncState;
cnc.OnReadInternal(ares);
}
@@ -447,7 +425,7 @@ namespace SocketHttpListener.Net
else
str = string.Format("<h1>{0}</h1>", description);
- byte[] error = _textEncoding.GetDefaultEncoding().GetBytes(str);
+ byte[] error = Encoding.UTF8.GetBytes(str);
response.Close(error, false);
}
catch
diff --git a/SocketHttpListener/Net/HttpEndPointListener.cs b/SocketHttpListener/Net/HttpEndPointListener.cs
index fb093314c..35d1af648 100644
--- a/SocketHttpListener/Net/HttpEndPointListener.cs
+++ b/SocketHttpListener/Net/HttpEndPointListener.cs
@@ -1,21 +1,14 @@
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
{
@@ -36,19 +29,19 @@ namespace SocketHttpListener.Net
private bool _enableDualMode;
private readonly ICryptoProvider _cryptoProvider;
private readonly ISocketFactory _socketFactory;
- private readonly ITextEncoding _textEncoding;
private readonly IStreamHelper _streamHelper;
private readonly IFileSystem _fileSystem;
private readonly IEnvironmentInfo _environment;
- public HttpEndPointListener(HttpListener listener, IPAddress addr, int port, bool secure, X509Certificate cert, ILogger logger, ICryptoProvider cryptoProvider, ISocketFactory socketFactory, IStreamHelper streamHelper, ITextEncoding textEncoding, IFileSystem fileSystem, IEnvironmentInfo environment)
+ public HttpEndPointListener(HttpListener listener, IPAddress addr, int port, bool secure, X509Certificate cert,
+ ILogger logger, ICryptoProvider cryptoProvider, ISocketFactory socketFactory, IStreamHelper streamHelper,
+ IFileSystem fileSystem, IEnvironmentInfo environment)
{
this._listener = listener;
_logger = logger;
_cryptoProvider = cryptoProvider;
_socketFactory = socketFactory;
_streamHelper = streamHelper;
- _textEncoding = textEncoding;
_fileSystem = fileSystem;
_environment = environment;
@@ -64,13 +57,7 @@ namespace SocketHttpListener.Net
CreateSocket();
}
- internal HttpListener Listener
- {
- get
- {
- return _listener;
- }
- }
+ internal HttpListener Listener => _listener;
private void CreateSocket()
{
@@ -168,18 +155,19 @@ namespace SocketHttpListener.Net
}
catch (ObjectDisposedException)
{
+ // TODO Investigate or properly fix.
}
catch (Exception ex)
{
- HttpEndPointListener epl = (HttpEndPointListener)acceptEventArg.UserToken;
+ var epl = (HttpEndPointListener)acceptEventArg.UserToken;
epl._logger.LogError(ex, "Error in socket.AcceptAsync");
}
}
- // This method is the callback method associated with Socket.AcceptAsync
- // operations and is invoked when an accept operation is complete
- //
+ // This method is the callback method associated with Socket.AcceptAsync
+ // operations and is invoked when an accept operation is complete
+ //
private static void OnAccept(object sender, SocketAsyncEventArgs e)
{
ProcessAccept(e);
@@ -187,7 +175,7 @@ namespace SocketHttpListener.Net
private static async void ProcessAccept(SocketAsyncEventArgs args)
{
- HttpEndPointListener epl = (HttpEndPointListener)args.UserToken;
+ var epl = (HttpEndPointListener)args.UserToken;
if (epl._closed)
{
@@ -208,7 +196,7 @@ namespace SocketHttpListener.Net
return;
}
- if(accepted == null)
+ if (accepted == null)
{
return;
}
@@ -225,7 +213,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._fileSystem, epl._environment);
await conn.Init().ConfigureAwait(false);
@@ -287,9 +275,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;
@@ -322,7 +309,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..27b4244a6 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");
@@ -136,7 +130,7 @@ namespace SocketHttpListener.Net
{
try
{
- epl = new HttpEndPointListener(listener, addr, port, secure, listener.Certificate, logger, listener.CryptoProvider, listener.SocketFactory, listener.StreamHelper, listener.TextEncoding, listener.FileSystem, listener.EnvironmentInfo);
+ epl = new HttpEndPointListener(listener, addr, port, secure, listener.Certificate, logger, listener.CryptoProvider, listener.SocketFactory, listener.StreamHelper, listener.FileSystem, listener.EnvironmentInfo);
}
catch (SocketException ex)
{
@@ -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 941b99f35..b80180679 100644
--- a/SocketHttpListener/Net/HttpListener.cs
+++ b/SocketHttpListener/Net/HttpListener.cs
@@ -1,17 +1,14 @@
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
{
@@ -20,7 +17,6 @@ namespace SocketHttpListener.Net
internal ICryptoProvider CryptoProvider { get; private set; }
internal ISocketFactory SocketFactory { get; private set; }
internal IFileSystem FileSystem { get; private set; }
- internal ITextEncoding TextEncoding { get; private set; }
internal IStreamHelper StreamHelper { get; private set; }
internal INetworkManager NetworkManager { get; private set; }
internal IEnvironmentInfo EnvironmentInfo { get; private set; }
@@ -35,20 +31,21 @@ namespace SocketHttpListener.Net
bool listening;
bool disposed;
- Dictionary<HttpListenerContext, HttpListenerContext> registry; // Dictionary<HttpListenerContext,HttpListenerContext>
+ Dictionary<HttpListenerContext, HttpListenerContext> registry; // Dictionary<HttpListenerContext,HttpListenerContext>
Dictionary<HttpConnection, HttpConnection> connections;
private ILogger _logger;
private X509Certificate _certificate;
public Action<HttpListenerContext> OnContext { get; set; }
- public HttpListener(ILogger logger, ICryptoProvider cryptoProvider, ISocketFactory socketFactory, INetworkManager networkManager, ITextEncoding textEncoding, IStreamHelper streamHelper, IFileSystem fileSystem, IEnvironmentInfo environmentInfo)
+ public HttpListener(ILogger logger, ICryptoProvider cryptoProvider, ISocketFactory socketFactory,
+ INetworkManager networkManager, IStreamHelper streamHelper, IFileSystem fileSystem,
+ IEnvironmentInfo environmentInfo)
{
_logger = logger;
CryptoProvider = cryptoProvider;
SocketFactory = socketFactory;
NetworkManager = networkManager;
- TextEncoding = textEncoding;
StreamHelper = streamHelper;
FileSystem = fileSystem;
EnvironmentInfo = environmentInfo;
@@ -58,8 +55,10 @@ namespace SocketHttpListener.Net
auth_schemes = AuthenticationSchemes.Anonymous;
}
- public HttpListener(ILogger logger, X509Certificate certificate, ICryptoProvider cryptoProvider, ISocketFactory socketFactory, INetworkManager networkManager, ITextEncoding textEncoding, IStreamHelper streamHelper, IFileSystem fileSystem, IEnvironmentInfo environmentInfo)
- : this(logger, cryptoProvider, socketFactory, networkManager, textEncoding, streamHelper, fileSystem, environmentInfo)
+ public HttpListener(ILogger logger, X509Certificate certificate, ICryptoProvider cryptoProvider,
+ ISocketFactory socketFactory, INetworkManager networkManager, IStreamHelper streamHelper,
+ IFileSystem fileSystem, IEnvironmentInfo environmentInfo)
+ : this(logger, cryptoProvider, socketFactory, networkManager, streamHelper, fileSystem, environmentInfo)
{
_certificate = certificate;
}
@@ -72,7 +71,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 +81,7 @@ namespace SocketHttpListener.Net
public AuthenticationSchemeSelector AuthenticationSchemeSelectorDelegate
{
- get { return auth_selector; }
+ get => auth_selector;
set
{
CheckDisposed();
@@ -90,15 +89,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 +105,7 @@ namespace SocketHttpListener.Net
// TODO: use this
public string Realm
{
- get { return realm; }
+ get => realm;
set
{
CheckDisposed();
@@ -122,7 +115,7 @@ namespace SocketHttpListener.Net
public bool UnsafeConnectionNtlmAuthentication
{
- get { return unsafe_ntlm_auth; }
+ get => unsafe_ntlm_auth;
set
{
CheckDisposed();
@@ -144,10 +137,7 @@ namespace SocketHttpListener.Net
// }
//}
- internal X509Certificate Certificate
- {
- get { return _certificate; }
- }
+ internal X509Certificate Certificate => _certificate;
public void Abort()
{
@@ -248,7 +238,7 @@ namespace SocketHttpListener.Net
internal void CheckDisposed()
{
if (disposed)
- throw new ObjectDisposedException(GetType().ToString());
+ throw new ObjectDisposedException(GetType().Name);
}
internal void RegisterContext(HttpListenerContext context)
diff --git a/SocketHttpListener/Net/HttpListenerBasicIdentity.cs b/SocketHttpListener/Net/HttpListenerBasicIdentity.cs
index faa26693d..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
@@ -26,7 +23,7 @@ namespace SocketHttpListener.Net
public GenericIdentity(string name)
{
if (name == null)
- throw new System.ArgumentNullException("name");
+ throw new System.ArgumentNullException(nameof(name));
m_name = name;
m_type = "";
@@ -35,36 +32,18 @@ namespace SocketHttpListener.Net
public GenericIdentity(string name, string type)
{
if (name == null)
- throw new System.ArgumentNullException("name");
+ throw new System.ArgumentNullException(nameof(name));
if (type == null)
- throw new System.ArgumentNullException("type");
+ throw new System.ArgumentNullException(nameof(type));
m_name = name;
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..29b0a7ae2 100644
--- a/SocketHttpListener/Net/HttpListenerContext.Managed.cs
+++ b/SocketHttpListener/Net/HttpListenerContext.Managed.cs
@@ -1,9 +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;
namespace SocketHttpListener.Net
@@ -12,10 +11,10 @@ namespace SocketHttpListener.Net
{
private HttpConnection _connection;
- internal HttpListenerContext(HttpConnection connection, ITextEncoding textEncoding)
+ internal HttpListenerContext(HttpConnection connection)
{
_connection = connection;
- _response = new HttpListenerResponse(this, textEncoding);
+ _response = new HttpListenerResponse(this);
Request = new HttpListenerRequest(this);
ErrorStatus = 400;
}
diff --git a/SocketHttpListener/Net/HttpListenerContext.cs b/SocketHttpListener/Net/HttpListenerContext.cs
index 0aaac1ad5..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)
{
@@ -49,7 +39,7 @@ namespace SocketHttpListener.Net
public GenericPrincipal(IIdentity identity, string[] roles)
{
if (identity == null)
- throw new ArgumentNullException("identity");
+ throw new ArgumentNullException(nameof(identity));
m_identity = identity;
if (roles != null)
@@ -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)
{
@@ -81,7 +65,7 @@ namespace SocketHttpListener.Net
for (int i = 0; i < m_roles.Length; ++i)
{
- if (m_roles[i] != null && String.Compare(m_roles[i], role, StringComparison.OrdinalIgnoreCase) == 0)
+ if (m_roles[i] != null && string.Compare(m_roles[i], role, StringComparison.OrdinalIgnoreCase) == 0)
return true;
}
return false;
diff --git a/SocketHttpListener/Net/HttpListenerPrefixCollection.cs b/SocketHttpListener/Net/HttpListenerPrefixCollection.cs
index ed99af1a6..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)
{
@@ -85,7 +76,7 @@ namespace SocketHttpListener.Net
{
listener.CheckDisposed();
if (uriPrefix == null)
- throw new ArgumentNullException("uriPrefix");
+ throw new ArgumentNullException(nameof(uriPrefix));
bool result = prefixes.Remove(uriPrefix);
if (result && listener.IsListening)
diff --git a/SocketHttpListener/Net/HttpListenerRequest.Managed.cs b/SocketHttpListener/Net/HttpListenerRequest.Managed.cs
index 47a6dfcfd..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
{
@@ -183,14 +178,14 @@ namespace SocketHttpListener.Net
}
}
- if (String.Compare(Headers[HttpKnownHeaderNames.Expect], "100-continue", StringComparison.OrdinalIgnoreCase) == 0)
+ if (string.Compare(Headers[HttpKnownHeaderNames.Expect], "100-continue", StringComparison.OrdinalIgnoreCase) == 0)
{
HttpResponseStream output = _context.Connection.GetResponseStream();
output.InternalWrite(s_100continue, 0, s_100continue.Length);
}
}
- internal static string Unquote(String str)
+ internal static string Unquote(string str)
{
int start = str.IndexOf('\"');
int end = str.LastIndexOf('\"');
diff --git a/SocketHttpListener/Net/HttpListenerRequest.cs b/SocketHttpListener/Net/HttpListenerRequest.cs
index 1b369dfa8..4924a7fa8 100644
--- a/SocketHttpListener/Net/HttpListenerRequest.cs
+++ b/SocketHttpListener/Net/HttpListenerRequest.cs
@@ -1,16 +1,9 @@
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;
namespace SocketHttpListener.Net
@@ -27,9 +20,9 @@ namespace SocketHttpListener.Net
public string[] UserLanguages => Helpers.ParseMultivalueHeader(Headers[HttpKnownHeaderNames.AcceptLanguage]);
- private CookieCollection ParseCookies(Uri uri, string setCookieHeader)
+ private static CookieCollection ParseCookies(Uri uri, string setCookieHeader)
{
- CookieCollection cookies = new CookieCollection();
+ var cookies = new CookieCollection();
return cookies;
}
@@ -88,7 +81,7 @@ namespace SocketHttpListener.Net
}
}
}
- return TextEncodingExtensions.GetDefaultEncoding();
+ return Encoding.UTF8;
}
}
@@ -177,7 +170,7 @@ namespace SocketHttpListener.Net
{
get
{
- QueryParamCollection queryString = new QueryParamCollection();
+ var queryString = new QueryParamCollection();
Helpers.FillFromString(queryString, Url.Query, true, ContentEncoding);
return queryString;
}
@@ -203,7 +196,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 +295,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 +340,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 34b5eaf74..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
{
@@ -28,11 +28,11 @@ namespace SocketHttpListener.Net
// The raw path is parsed by looping through all characters from left to right. 'rawOctets'
// is used to store consecutive percent encoded octets as actual byte values: e.g. for path /pa%C3%84th%2F/
// rawOctets will be set to { 0xC3, 0x84 } when we reach character 't' and it will be { 0x2F } when
- // we reach the final '/'. I.e. after a sequence of percent encoded octets ends, we use rawOctets as
+ // we reach the final '/'. I.e. after a sequence of percent encoded octets ends, we use rawOctets as
// input to the encoding and percent encode the resulting string into UTF-8 octets.
//
// When parsing ANSI (Latin 1) encoded path '/pa%C4th/', %C4 will be added to rawOctets and when
- // we reach 't', the content of rawOctets { 0xC4 } will be fed into the ANSI encoding. The resulting
+ // we reach 't', the content of rawOctets { 0xC4 } will be fed into the ANSI encoding. The resulting
// string 'Ä' will be percent encoded into UTF-8 octets and appended to requestUriString. The final
// path will be '/pa%C3%84th/', where '%C3%84' is the UTF-8 percent encoded character 'Ä'.
private List<byte> _rawOctets;
@@ -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();
@@ -146,7 +146,7 @@ namespace SocketHttpListener.Net
if (!Uri.TryCreate(_requestUriString.ToString(), UriKind.Absolute, out _requestUri))
{
- // If we can't create a Uri from the string, this is an invalid string and it doesn't make
+ // If we can't create a Uri from the string, this is an invalid string and it doesn't make
// sense to try another encoding.
result = ParsingResult.InvalidString;
}
@@ -196,7 +196,7 @@ namespace SocketHttpListener.Net
}
else
{
- // We found '%', but not followed by 'u', i.e. we have a percent encoded octed: %XX
+ // We found '%', but not followed by 'u', i.e. we have a percent encoded octed: %XX
if (!AddPercentEncodedOctetToRawOctetsList(encoding, _rawPath.Substring(index, 2)))
{
return ParsingResult.InvalidString;
@@ -207,7 +207,7 @@ namespace SocketHttpListener.Net
else
{
// We found a non-'%' character: decode the content of rawOctets into percent encoded
- // UTF-8 characters and append it to the result.
+ // UTF-8 characters and append it to the result.
if (!EmptyDecodeAndAppendRawOctetsList(encoding))
{
return ParsingResult.EncodingError;
@@ -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)
@@ -402,7 +400,7 @@ namespace SocketHttpListener.Net
// Find end of path: The path is terminated by
// - the first '?' character
- // - the first '#' character: This is never the case here, since http.sys won't accept
+ // - the first '#' character: This is never the case here, since http.sys won't accept
// Uris containing fragments. Also, RFC2616 doesn't allow fragments in request Uris.
// - end of Uri string
int queryIndex = uriString.IndexOf('?');
diff --git a/SocketHttpListener/Net/HttpListenerResponse.Managed.cs b/SocketHttpListener/Net/HttpListenerResponse.Managed.cs
index 34953b569..f595fce7c 100644
--- a/SocketHttpListener/Net/HttpListenerResponse.Managed.cs
+++ b/SocketHttpListener/Net/HttpListenerResponse.Managed.cs
@@ -1,13 +1,10 @@
using System;
-using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
-using System.Threading.Tasks;
-using MediaBrowser.Model.Text;
-using SocketHttpListener.Primitives;
using System.Threading;
+using System.Threading.Tasks;
using MediaBrowser.Model.IO;
namespace SocketHttpListener.Net
@@ -19,12 +16,10 @@ namespace SocketHttpListener.Net
private int _statusCode = 200;
internal object _headersLock = new object();
private bool _forceCloseChunked;
- private ITextEncoding _textEncoding;
- internal HttpListenerResponse(HttpListenerContext context, ITextEncoding textEncoding)
+ internal HttpListenerResponse(HttpListenerContext context)
{
_httpContext = context;
- _textEncoding = textEncoding;
}
internal bool ForceCloseChunked => _forceCloseChunked;
@@ -39,7 +34,7 @@ namespace SocketHttpListener.Net
public Version ProtocolVersion
{
- get { return _version; }
+ get => _version;
set
{
CheckDisposed();
@@ -58,7 +53,7 @@ namespace SocketHttpListener.Net
public int StatusCode
{
- get { return _statusCode; }
+ get => _statusCode;
set
{
CheckDisposed();
@@ -207,13 +202,13 @@ namespace SocketHttpListener.Net
}
/* Apache forces closing the connection for these status codes:
- * HttpStatusCode.BadRequest 400
- * HttpStatusCode.RequestTimeout 408
- * HttpStatusCode.LengthRequired 411
- * HttpStatusCode.RequestEntityTooLarge 413
- * HttpStatusCode.RequestUriTooLong 414
- * HttpStatusCode.InternalServerError 500
- * HttpStatusCode.ServiceUnavailable 503
+ * HttpStatusCode.BadRequest 400
+ * HttpStatusCode.RequestTimeout 408
+ * HttpStatusCode.LengthRequired 411
+ * HttpStatusCode.RequestEntityTooLarge 413
+ * HttpStatusCode.RequestUriTooLong 414
+ * HttpStatusCode.InternalServerError 500
+ * HttpStatusCode.ServiceUnavailable 503
*/
bool conn_close = (_statusCode == (int)HttpStatusCode.BadRequest || _statusCode == (int)HttpStatusCode.RequestTimeout
|| _statusCode == (int)HttpStatusCode.LengthRequired || _statusCode == (int)HttpStatusCode.RequestEntityTooLarge
@@ -264,8 +259,8 @@ namespace SocketHttpListener.Net
ComputeCookies();
}
- Encoding encoding = _textEncoding.GetDefaultEncoding();
- StreamWriter writer = new StreamWriter(ms, encoding, 256);
+ var encoding = Encoding.UTF8;
+ 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 1cbd6165e..a32aca043 100644
--- a/SocketHttpListener/Net/HttpListenerResponse.cs
+++ b/SocketHttpListener/Net/HttpListenerResponse.cs
@@ -1,14 +1,7 @@
-using System;
-using System.Collections.Generic;
+using System;
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();
@@ -104,20 +94,20 @@ namespace SocketHttpListener.Net
}
else
{
- throw new ArgumentOutOfRangeException("net_clsmall");
+ throw new ArgumentOutOfRangeException(nameof(value));
}
}
}
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 c9c148b15..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
{
@@ -13,7 +9,7 @@ namespace SocketHttpListener.Net
// System.Net.ResponseStream
//
// Author:
- // Gonzalo Paniagua Javier (gonzalo@novell.com)
+ // Gonzalo Paniagua Javier (gonzalo@novell.com)
//
// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
//
@@ -24,10 +20,10 @@ namespace SocketHttpListener.Net
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
- //
+ //
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
- //
+ //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -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 f10c04a4f..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;
@@ -13,7 +11,7 @@ namespace SocketHttpListener.Net
// System.Net.ResponseStream
//
// Author:
- // Gonzalo Paniagua Javier (gonzalo@novell.com)
+ // Gonzalo Paniagua Javier (gonzalo@novell.com)
//
// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
//
@@ -24,10 +22,10 @@ namespace SocketHttpListener.Net
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
- //
+ //
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
- //
+ //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -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 e727f1b4a..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
{
@@ -19,7 +17,7 @@ namespace SocketHttpListener.Net
// System.Net.ResponseStream
//
// Author:
- // Gonzalo Paniagua Javier (gonzalo@novell.com)
+ // Gonzalo Paniagua Javier (gonzalo@novell.com)
//
// Copyright (c) 2005 Novell, Inc. (http://www.novell.com)
//
@@ -30,10 +28,10 @@ namespace SocketHttpListener.Net
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
- //
+ //
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
- //
+ //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -157,7 +155,7 @@ namespace SocketHttpListener.Net
private static byte[] s_crlf = new byte[] { 13, 10 };
private static byte[] GetChunkSizeBytes(int size, bool final)
{
- string str = String.Format("{0:x}\r\n{1}", size, final ? "\r\n" : "");
+ string str = string.Format("{0:x}\r\n{1}", size, final ? "\r\n" : "");
return Encoding.ASCII.GetBytes(str);
}
@@ -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 4bed81404..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
{
@@ -23,69 +18,69 @@ namespace SocketHttpListener.Net
}
static readonly bool[] allowed_chars = {
- false, false, false, false, false, false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, false, false, false, false, false, false, false, false, false,
- false, false, false, false, false, true, false, true, true, true, true, false, false, false, true,
- true, false, true, true, false, true, true, true, true, true, true, true, true, true, true, false,
- false, false, false, false, false, false, true, true, true, true, true, true, true, true, true,
- true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
- false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true,
- true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
- false, true, false
- };
+ false, false, false, false, false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, false, false, false, false, false, false, false, false, false,
+ false, false, false, false, false, true, false, true, true, true, true, false, false, false, true,
+ true, false, true, true, false, true, true, true, true, true, true, true, true, true, true, false,
+ false, false, false, false, false, false, true, true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
+ false, false, false, true, true, true, true, true, true, true, true, true, true, true, true, true,
+ true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,
+ false, true, false
+ };
static readonly Dictionary<string, HeaderInfo> headers;
static WebHeaderCollection()
{
headers = new Dictionary<string, HeaderInfo>(StringComparer.OrdinalIgnoreCase) {
- { "Allow", HeaderInfo.MultiValue },
- { "Accept", HeaderInfo.Request | HeaderInfo.MultiValue },
- { "Accept-Charset", HeaderInfo.MultiValue },
- { "Accept-Encoding", HeaderInfo.MultiValue },
- { "Accept-Language", HeaderInfo.MultiValue },
- { "Accept-Ranges", HeaderInfo.MultiValue },
- { "Age", HeaderInfo.Response },
- { "Authorization", HeaderInfo.MultiValue },
- { "Cache-Control", HeaderInfo.MultiValue },
- { "Cookie", HeaderInfo.MultiValue },
- { "Connection", HeaderInfo.Request | HeaderInfo.MultiValue },
- { "Content-Encoding", HeaderInfo.MultiValue },
- { "Content-Length", HeaderInfo.Request | HeaderInfo.Response },
- { "Content-Type", HeaderInfo.Request },
- { "Content-Language", HeaderInfo.MultiValue },
- { "Date", HeaderInfo.Request },
- { "Expect", HeaderInfo.Request | HeaderInfo.MultiValue},
- { "Host", HeaderInfo.Request },
- { "If-Match", HeaderInfo.MultiValue },
- { "If-Modified-Since", HeaderInfo.Request },
- { "If-None-Match", HeaderInfo.MultiValue },
- { "Keep-Alive", HeaderInfo.Response },
- { "Pragma", HeaderInfo.MultiValue },
- { "Proxy-Authenticate", HeaderInfo.MultiValue },
- { "Proxy-Authorization", HeaderInfo.MultiValue },
- { "Proxy-Connection", HeaderInfo.Request | HeaderInfo.MultiValue },
- { "Range", HeaderInfo.Request | HeaderInfo.MultiValue },
- { "Referer", HeaderInfo.Request },
- { "Set-Cookie", HeaderInfo.MultiValue },
- { "Set-Cookie2", HeaderInfo.MultiValue },
- { "Server", HeaderInfo.Response },
- { "TE", HeaderInfo.MultiValue },
- { "Trailer", HeaderInfo.MultiValue },
- { "Transfer-Encoding", HeaderInfo.Request | HeaderInfo.Response | HeaderInfo.MultiValue },
- { "Translate", HeaderInfo.Request | HeaderInfo.Response },
- { "Upgrade", HeaderInfo.MultiValue },
- { "User-Agent", HeaderInfo.Request },
- { "Vary", HeaderInfo.MultiValue },
- { "Via", HeaderInfo.MultiValue },
- { "Warning", HeaderInfo.MultiValue },
- { "WWW-Authenticate", HeaderInfo.Response | HeaderInfo. MultiValue },
- { "SecWebSocketAccept", HeaderInfo.Response },
- { "SecWebSocketExtensions", HeaderInfo.Request | HeaderInfo.Response | HeaderInfo. MultiValue },
- { "SecWebSocketKey", HeaderInfo.Request },
- { "Sec-WebSocket-Protocol", HeaderInfo.Request | HeaderInfo.Response | HeaderInfo. MultiValue },
- { "SecWebSocketVersion", HeaderInfo.Response | HeaderInfo. MultiValue }
- };
+ { "Allow", HeaderInfo.MultiValue },
+ { "Accept", HeaderInfo.Request | HeaderInfo.MultiValue },
+ { "Accept-Charset", HeaderInfo.MultiValue },
+ { "Accept-Encoding", HeaderInfo.MultiValue },
+ { "Accept-Language", HeaderInfo.MultiValue },
+ { "Accept-Ranges", HeaderInfo.MultiValue },
+ { "Age", HeaderInfo.Response },
+ { "Authorization", HeaderInfo.MultiValue },
+ { "Cache-Control", HeaderInfo.MultiValue },
+ { "Cookie", HeaderInfo.MultiValue },
+ { "Connection", HeaderInfo.Request | HeaderInfo.MultiValue },
+ { "Content-Encoding", HeaderInfo.MultiValue },
+ { "Content-Length", HeaderInfo.Request | HeaderInfo.Response },
+ { "Content-Type", HeaderInfo.Request },
+ { "Content-Language", HeaderInfo.MultiValue },
+ { "Date", HeaderInfo.Request },
+ { "Expect", HeaderInfo.Request | HeaderInfo.MultiValue},
+ { "Host", HeaderInfo.Request },
+ { "If-Match", HeaderInfo.MultiValue },
+ { "If-Modified-Since", HeaderInfo.Request },
+ { "If-None-Match", HeaderInfo.MultiValue },
+ { "Keep-Alive", HeaderInfo.Response },
+ { "Pragma", HeaderInfo.MultiValue },
+ { "Proxy-Authenticate", HeaderInfo.MultiValue },
+ { "Proxy-Authorization", HeaderInfo.MultiValue },
+ { "Proxy-Connection", HeaderInfo.Request | HeaderInfo.MultiValue },
+ { "Range", HeaderInfo.Request | HeaderInfo.MultiValue },
+ { "Referer", HeaderInfo.Request },
+ { "Set-Cookie", HeaderInfo.MultiValue },
+ { "Set-Cookie2", HeaderInfo.MultiValue },
+ { "Server", HeaderInfo.Response },
+ { "TE", HeaderInfo.MultiValue },
+ { "Trailer", HeaderInfo.MultiValue },
+ { "Transfer-Encoding", HeaderInfo.Request | HeaderInfo.Response | HeaderInfo.MultiValue },
+ { "Translate", HeaderInfo.Request | HeaderInfo.Response },
+ { "Upgrade", HeaderInfo.MultiValue },
+ { "User-Agent", HeaderInfo.Request },
+ { "Vary", HeaderInfo.MultiValue },
+ { "Via", HeaderInfo.MultiValue },
+ { "Warning", HeaderInfo.MultiValue },
+ { "WWW-Authenticate", HeaderInfo.Response | HeaderInfo. MultiValue },
+ { "SecWebSocketAccept", HeaderInfo.Response },
+ { "SecWebSocketExtensions", HeaderInfo.Request | HeaderInfo.Response | HeaderInfo. MultiValue },
+ { "SecWebSocketKey", HeaderInfo.Request },
+ { "Sec-WebSocket-Protocol", HeaderInfo.Request | HeaderInfo.Response | HeaderInfo. MultiValue },
+ { "SecWebSocketVersion", HeaderInfo.Response | HeaderInfo. MultiValue }
+ };
}
// Methods
@@ -93,10 +88,10 @@ namespace SocketHttpListener.Net
public void Add(string header)
{
if (header == null)
- throw new ArgumentNullException("header");
+ throw new ArgumentNullException(nameof(header));
int pos = header.IndexOf(':');
if (pos == -1)
- throw new ArgumentException("no colon found", "header");
+ throw new ArgumentException("no colon found", nameof(header));
this.Add(header.Substring(0, pos), header.Substring(pos + 1));
}
@@ -104,7 +99,7 @@ namespace SocketHttpListener.Net
public override void Add(string name, string value)
{
if (name == null)
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
this.AddWithoutValidate(name, value);
}
@@ -112,13 +107,13 @@ namespace SocketHttpListener.Net
protected void AddWithoutValidate(string headerName, string headerValue)
{
if (!IsHeaderName(headerName))
- throw new ArgumentException("invalid header name: " + headerName, "headerName");
+ throw new ArgumentException("invalid header name: " + headerName, nameof(headerName));
if (headerValue == null)
- headerValue = String.Empty;
+ headerValue = string.Empty;
else
headerValue = headerValue.Trim();
if (!IsHeaderValue(headerValue))
- throw new ArgumentException("invalid header value: " + headerValue, "headerValue");
+ throw new ArgumentException("invalid header value: " + headerValue, nameof(headerValue));
AddValue(headerName, headerValue);
}
@@ -131,7 +126,7 @@ namespace SocketHttpListener.Net
internal List<string> GetValues_internal(string header, bool split)
{
if (header == null)
- throw new ArgumentNullException("header");
+ throw new ArgumentNullException(nameof(header));
var values = base.GetValues(header);
if (values == null || values.Count == 0)
@@ -205,16 +200,15 @@ namespace SocketHttpListener.Net
public static bool IsRestricted(string headerName, bool response)
{
if (headerName == null)
- throw new ArgumentNullException("headerName");
+ throw new ArgumentNullException(nameof(headerName));
if (headerName.Length == 0)
- throw new ArgumentException("empty string", "headerName");
+ throw new ArgumentException("empty string", nameof(headerName));
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;
@@ -224,11 +218,11 @@ namespace SocketHttpListener.Net
public override void Set(string name, string value)
{
if (name == null)
- throw new ArgumentNullException("name");
+ throw new ArgumentNullException(nameof(name));
if (!IsHeaderName(name))
throw new ArgumentException("invalid header name");
if (value == null)
- value = String.Empty;
+ value = string.Empty;
else
value = value.Trim();
if (!IsHeaderValue(value))
@@ -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++)
@@ -288,7 +282,7 @@ namespace SocketHttpListener.Net
{
int pos = header.IndexOf(':');
if (pos == -1)
- throw new ArgumentException("no colon found", "header");
+ throw new ArgumentException("no colon found", nameof(header));
SetInternal(header.Substring(0, pos), header.Substring(pos + 1));
}
@@ -296,7 +290,7 @@ namespace SocketHttpListener.Net
internal void SetInternal(string name, string value)
{
if (value == null)
- value = String.Empty;
+ value = string.Empty;
else
value = value.Trim();
if (!IsHeaderValue(value))
@@ -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 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
diff --git a/SocketHttpListener/Opcode.cs b/SocketHttpListener/Opcode.cs
index 62b7d8585..69cf3f372 100644
--- a/SocketHttpListener/Opcode.cs
+++ b/SocketHttpListener/Opcode.cs
@@ -1,43 +1,43 @@
namespace SocketHttpListener
{
- /// <summary>
- /// Contains the values of the opcode that indicates the type of a WebSocket frame.
- /// </summary>
- /// <remarks>
- /// The values of the opcode are defined in
- /// <see href="http://tools.ietf.org/html/rfc6455#section-5.2">Section 5.2</see> of RFC 6455.
- /// </remarks>
- public enum Opcode : byte
- {
/// <summary>
- /// Equivalent to numeric value 0.
- /// Indicates a continuation frame.
+ /// Contains the values of the opcode that indicates the type of a WebSocket frame.
/// </summary>
- Cont = 0x0,
- /// <summary>
- /// Equivalent to numeric value 1.
- /// Indicates a text frame.
- /// </summary>
- Text = 0x1,
- /// <summary>
- /// Equivalent to numeric value 2.
- /// Indicates a binary frame.
- /// </summary>
- Binary = 0x2,
- /// <summary>
- /// Equivalent to numeric value 8.
- /// Indicates a connection close frame.
- /// </summary>
- Close = 0x8,
- /// <summary>
- /// Equivalent to numeric value 9.
- /// Indicates a ping frame.
- /// </summary>
- Ping = 0x9,
- /// <summary>
- /// Equivalent to numeric value 10.
- /// Indicates a pong frame.
- /// </summary>
- Pong = 0xa
- }
+ /// <remarks>
+ /// The values of the opcode are defined in
+ /// <see href="http://tools.ietf.org/html/rfc6455#section-5.2">Section 5.2</see> of RFC 6455.
+ /// </remarks>
+ public enum Opcode : byte
+ {
+ /// <summary>
+ /// Equivalent to numeric value 0.
+ /// Indicates a continuation frame.
+ /// </summary>
+ Cont = 0x0,
+ /// <summary>
+ /// Equivalent to numeric value 1.
+ /// Indicates a text frame.
+ /// </summary>
+ Text = 0x1,
+ /// <summary>
+ /// Equivalent to numeric value 2.
+ /// Indicates a binary frame.
+ /// </summary>
+ Binary = 0x2,
+ /// <summary>
+ /// Equivalent to numeric value 8.
+ /// Indicates a connection close frame.
+ /// </summary>
+ Close = 0x8,
+ /// <summary>
+ /// Equivalent to numeric value 9.
+ /// Indicates a ping frame.
+ /// </summary>
+ Ping = 0x9,
+ /// <summary>
+ /// Equivalent to numeric value 10.
+ /// Indicates a pong frame.
+ /// </summary>
+ Pong = 0xa
+ }
}
diff --git a/SocketHttpListener/PayloadData.cs b/SocketHttpListener/PayloadData.cs
index a6318da2b..6d15a6bcb 100644
--- a/SocketHttpListener/PayloadData.cs
+++ b/SocketHttpListener/PayloadData.cs
@@ -5,145 +5,126 @@ using System.Text;
namespace SocketHttpListener
{
- internal class PayloadData : IEnumerable<byte>
- {
- #region Private Fields
+ internal class PayloadData : IEnumerable<byte>
+ {
+ #region Private Fields
- private byte [] _applicationData;
- private byte [] _extensionData;
- private bool _masked;
+ private byte[] _applicationData;
+ private byte[] _extensionData;
+ private bool _masked;
- #endregion
+ #endregion
- #region Public Const Fields
+ #region Public Const Fields
- public const ulong MaxLength = long.MaxValue;
+ public const ulong MaxLength = long.MaxValue;
- #endregion
+ #endregion
- #region Public Constructors
+ #region Public Constructors
- public PayloadData ()
- : this (new byte [0], new byte [0], false)
- {
- }
+ public PayloadData()
+ : this(new byte[0], new byte[0], false)
+ {
+ }
- public PayloadData (byte [] applicationData)
- : this (new byte [0], applicationData, false)
- {
- }
+ public PayloadData(byte[] applicationData)
+ : this(new byte[0], applicationData, false)
+ {
+ }
- public PayloadData (string applicationData)
- : this (new byte [0], Encoding.UTF8.GetBytes (applicationData), false)
- {
- }
+ public PayloadData(string applicationData)
+ : this(new byte[0], Encoding.UTF8.GetBytes(applicationData), false)
+ {
+ }
- public PayloadData (byte [] applicationData, bool masked)
- : this (new byte [0], applicationData, masked)
- {
- }
+ public PayloadData(byte[] applicationData, bool masked)
+ : this(new byte[0], applicationData, masked)
+ {
+ }
- public PayloadData (byte [] extensionData, byte [] applicationData, bool masked)
- {
- _extensionData = extensionData;
- _applicationData = applicationData;
- _masked = masked;
- }
+ public PayloadData(byte[] extensionData, byte[] applicationData, bool masked)
+ {
+ _extensionData = extensionData;
+ _applicationData = applicationData;
+ _masked = masked;
+ }
- #endregion
+ #endregion
- #region Internal Properties
+ #region Internal Properties
- internal bool ContainsReservedCloseStatusCode {
- get {
- return _applicationData.Length > 1 &&
- _applicationData.SubArray (0, 2).ToUInt16 (ByteOrder.Big).IsReserved ();
- }
- }
+ internal bool ContainsReservedCloseStatusCode =>
+ _applicationData.Length > 1 &&
+ _applicationData.SubArray(0, 2).ToUInt16(ByteOrder.Big).IsReserved();
- #endregion
+ #endregion
- #region Public Properties
+ #region Public Properties
- public byte [] ApplicationData {
- get {
- return _applicationData;
- }
- }
+ public byte[] ApplicationData => _applicationData;
- public byte [] ExtensionData {
- get {
- return _extensionData;
- }
- }
+ public byte[] ExtensionData => _extensionData;
- public bool IsMasked {
- get {
- return _masked;
- }
- }
+ public bool IsMasked => _masked;
- public ulong Length {
- get {
- return (ulong) (_extensionData.Length + _applicationData.Length);
- }
- }
+ public ulong Length => (ulong)(_extensionData.Length + _applicationData.Length);
- #endregion
+ #endregion
- #region Private Methods
+ #region Private Methods
- private static void mask (byte [] src, byte [] key)
- {
- for (long i = 0; i < src.Length; i++)
- src [i] = (byte) (src [i] ^ key [i % 4]);
- }
+ private static void mask(byte[] src, byte[] key)
+ {
+ for (long i = 0; i < src.Length; i++)
+ src[i] = (byte)(src[i] ^ key[i % 4]);
+ }
- #endregion
+ #endregion
- #region Public Methods
+ #region Public Methods
- public IEnumerator<byte> GetEnumerator ()
- {
- foreach (byte b in _extensionData)
- yield return b;
+ public IEnumerator<byte> GetEnumerator()
+ {
+ foreach (byte b in _extensionData)
+ yield return b;
- foreach (byte b in _applicationData)
- yield return b;
- }
+ foreach (byte b in _applicationData)
+ yield return b;
+ }
- public void Mask (byte [] maskingKey)
- {
- if (_extensionData.Length > 0)
- mask (_extensionData, maskingKey);
+ public void Mask(byte[] maskingKey)
+ {
+ if (_extensionData.Length > 0)
+ mask(_extensionData, maskingKey);
- if (_applicationData.Length > 0)
- mask (_applicationData, maskingKey);
+ if (_applicationData.Length > 0)
+ mask(_applicationData, maskingKey);
- _masked = !_masked;
- }
+ _masked = !_masked;
+ }
- public byte [] ToByteArray ()
- {
- return _extensionData.Length > 0
- ? new List<byte> (this).ToArray ()
- : _applicationData;
- }
+ public byte[] ToByteArray()
+ {
+ return _extensionData.Length > 0
+ ? new List<byte>(this).ToArray()
+ : _applicationData;
+ }
- public override string ToString ()
- {
- return BitConverter.ToString (ToByteArray ());
- }
+ public override string ToString()
+ {
+ return BitConverter.ToString(ToByteArray());
+ }
- #endregion
+ #endregion
- #region Explicitly Implemented Interface Members
+ #region Explicitly Implemented Interface Members
- IEnumerator IEnumerable.GetEnumerator ()
- {
- return GetEnumerator ();
- }
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
- #endregion
- }
+ #endregion
+ }
}
diff --git a/SocketHttpListener/Primitives/ITextEncoding.cs b/SocketHttpListener/Primitives/ITextEncoding.cs
deleted file mode 100644
index a256a077d..000000000
--- a/SocketHttpListener/Primitives/ITextEncoding.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.Threading.Tasks;
-using MediaBrowser.Model.Text;
-
-namespace SocketHttpListener.Primitives
-{
- public static class TextEncodingExtensions
- {
- public static Encoding GetDefaultEncoding(this ITextEncoding encoding)
- {
- return Encoding.UTF8;
- }
-
- public static Encoding GetDefaultEncoding()
- {
- return Encoding.UTF8;
- }
- }
-}
diff --git a/SocketHttpListener/Properties/AssemblyInfo.cs b/SocketHttpListener/Properties/AssemblyInfo.cs
index 8876cea4f..a69bd176f 100644
--- a/SocketHttpListener/Properties/AssemblyInfo.cs
+++ b/SocketHttpListener/Properties/AssemblyInfo.cs
@@ -1,34 +1,21 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
+using System.Reflection;
+using System.Resources;
using System.Runtime.InteropServices;
-// General Information about an assembly is controlled through the following
+// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SocketHttpListener")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("SocketHttpListener")]
-[assembly: AssemblyCopyright("Copyright © 2017")]
+[assembly: AssemblyCompany("Jellyfin Project")]
+[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
+[assembly: AssemblyCopyright("Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
+[assembly: NeutralResourcesLanguage("en")]
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("1d74413b-e7cf-455b-b021-f52bdf881542")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
diff --git a/SocketHttpListener/Rsv.cs b/SocketHttpListener/Rsv.cs
index 668059b8a..87283791e 100644
--- a/SocketHttpListener/Rsv.cs
+++ b/SocketHttpListener/Rsv.cs
@@ -1,8 +1,8 @@
namespace SocketHttpListener
{
- internal enum Rsv : byte
- {
- Off = 0x0,
- On = 0x1
- }
+ internal enum Rsv : byte
+ {
+ Off = 0x0,
+ On = 0x1
+ }
}
diff --git a/SocketHttpListener/SocketHttpListener.csproj b/SocketHttpListener/SocketHttpListener.csproj
index ca9056a6a..e700540a9 100644
--- a/SocketHttpListener/SocketHttpListener.csproj
+++ b/SocketHttpListener/SocketHttpListener.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
diff --git a/SocketHttpListener/SocketStream.cs b/SocketHttpListener/SocketStream.cs
index a4f31eab9..f51fde97e 100644
--- a/SocketHttpListener/SocketStream.cs
+++ b/SocketHttpListener/SocketStream.cs
@@ -1,10 +1,6 @@
-using System;
-using System.Collections.Generic;
+using System;
using System.IO;
-using System.Linq;
using System.Net.Sockets;
-using System.Text;
-using System.Threading.Tasks;
namespace SocketHttpListener
{
@@ -21,26 +17,18 @@ namespace SocketHttpListener
{
}
- public override bool CanRead
- {
- get { return true; }
- }
- public override bool CanSeek
- {
- get { return false; }
- }
- public override bool CanWrite
- {
- get { return true; }
- }
- public override long Length
- {
- get { throw new NotImplementedException(); }
- }
+ public override bool CanRead => true;
+
+ public override bool CanSeek => false;
+
+ public override bool CanWrite => true;
+
+ public override long Length => throw new NotImplementedException();
+
public override long Position
{
- get { throw new NotImplementedException(); }
- set { throw new NotImplementedException(); }
+ get => throw new NotImplementedException();
+ set => throw new NotImplementedException();
}
public override void Write(byte[] buffer, int offset, int count)
diff --git a/SocketHttpListener/WebSocket.cs b/SocketHttpListener/WebSocket.cs
index 7d61850e6..bf400599d 100644
--- a/SocketHttpListener/WebSocket.cs
+++ b/SocketHttpListener/WebSocket.cs
@@ -3,15 +3,12 @@ using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
+using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
-using MediaBrowser.Model.Cryptography;
-using MediaBrowser.Model.IO;
using SocketHttpListener.Net.WebSockets;
-using SocketHttpListener.Primitives;
using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
-using System.Net.Sockets;
using WebSocketState = System.Net.WebSockets.WebSocketState;
namespace SocketHttpListener
@@ -81,11 +78,8 @@ namespace SocketHttpListener
init();
}
- public static TimeSpan DefaultKeepAliveInterval
- {
- // In the .NET Framework, this pulls the value from a P/Invoke. Here we just hardcode it to a reasonable default.
- get { return TimeSpan.FromSeconds(30); }
- }
+ // In the .NET Framework, this pulls the value from a P/Invoke. Here we just hardcode it to a reasonable default.
+ public static TimeSpan DefaultKeepAliveInterval => TimeSpan.FromSeconds(30);
#endregion
@@ -96,13 +90,7 @@ namespace SocketHttpListener
/// One of the <see cref="WebSocketState"/> enum values, indicates the state of the WebSocket
/// connection. The default value is <see cref="WebSocketState.Connecting"/>.
/// </value>
- public WebSocketState ReadyState
- {
- get
- {
- return _readyState;
- }
- }
+ public WebSocketState ReadyState => _readyState;
#region Public Events
@@ -740,7 +728,7 @@ namespace SocketHttpListener
{
if (data == null)
{
- throw new ArgumentNullException("data");
+ throw new ArgumentNullException(nameof(data));
}
var msg = _readyState.CheckIfOpen();
@@ -765,7 +753,7 @@ namespace SocketHttpListener
{
if (data == null)
{
- throw new ArgumentNullException("data");
+ throw new ArgumentNullException(nameof(data));
}
var msg = _readyState.CheckIfOpen();
diff --git a/SocketHttpListener/WebSocketException.cs b/SocketHttpListener/WebSocketException.cs
index 260721317..e86c46d0f 100644
--- a/SocketHttpListener/WebSocketException.cs
+++ b/SocketHttpListener/WebSocketException.cs
@@ -2,59 +2,60 @@ using System;
namespace SocketHttpListener
{
- /// <summary>
- /// The exception that is thrown when a <see cref="WebSocket"/> gets a fatal error.
- /// </summary>
- public class WebSocketException : Exception
- {
- #region Internal Constructors
-
- internal WebSocketException ()
- : this (CloseStatusCode.Abnormal, null, null)
- {
- }
-
- internal WebSocketException (string message)
- : this (CloseStatusCode.Abnormal, message, null)
- {
- }
-
- internal WebSocketException (CloseStatusCode code)
- : this (code, null, null)
- {
- }
-
- internal WebSocketException (string message, Exception innerException)
- : this (CloseStatusCode.Abnormal, message, innerException)
- {
- }
-
- internal WebSocketException (CloseStatusCode code, string message)
- : this (code, message, null)
- {
- }
-
- internal WebSocketException (CloseStatusCode code, string message, Exception innerException)
- : base (message ?? code.GetMessage (), innerException)
- {
- Code = code;
- }
-
- #endregion
-
- #region Public Properties
-
/// <summary>
- /// Gets the status code indicating the cause for the exception.
+ /// The exception that is thrown when a <see cref="WebSocket"/> gets a fatal error.
/// </summary>
- /// <value>
- /// One of the <see cref="CloseStatusCode"/> enum values, represents the status code indicating
- /// the cause for the exception.
- /// </value>
- public CloseStatusCode Code {
- get; private set;
+ public class WebSocketException : Exception
+ {
+ #region Internal Constructors
+
+ internal WebSocketException()
+ : this(CloseStatusCode.Abnormal, null, null)
+ {
+ }
+
+ internal WebSocketException(string message)
+ : this(CloseStatusCode.Abnormal, message, null)
+ {
+ }
+
+ internal WebSocketException(CloseStatusCode code)
+ : this(code, null, null)
+ {
+ }
+
+ internal WebSocketException(string message, Exception innerException)
+ : this(CloseStatusCode.Abnormal, message, innerException)
+ {
+ }
+
+ internal WebSocketException(CloseStatusCode code, string message)
+ : this(code, message, null)
+ {
+ }
+
+ internal WebSocketException(CloseStatusCode code, string message, Exception innerException)
+ : base(message ?? code.GetMessage(), innerException)
+ {
+ Code = code;
+ }
+
+ #endregion
+
+ #region Public Properties
+
+ /// <summary>
+ /// Gets the status code indicating the cause for the exception.
+ /// </summary>
+ /// <value>
+ /// One of the <see cref="CloseStatusCode"/> enum values, represents the status code indicating
+ /// the cause for the exception.
+ /// </value>
+ public CloseStatusCode Code
+ {
+ get; private set;
+ }
+
+ #endregion
}
-
- #endregion
- }
}
diff --git a/SocketHttpListener/WebSocketFrame.cs b/SocketHttpListener/WebSocketFrame.cs
index 44fa4a5dc..74ed23c45 100644
--- a/SocketHttpListener/WebSocketFrame.cs
+++ b/SocketHttpListener/WebSocketFrame.cs
@@ -2,7 +2,6 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
-using System.Text;
namespace SocketHttpListener
{
@@ -107,197 +106,53 @@ namespace SocketHttpListener
#region Public Properties
- public byte[] ExtendedPayloadLength
- {
- get
- {
- return _extPayloadLength;
- }
- }
+ public byte[] ExtendedPayloadLength => _extPayloadLength;
- public Fin Fin
- {
- get
- {
- return _fin;
- }
- }
+ public Fin Fin => _fin;
- public bool IsBinary
- {
- get
- {
- return _opcode == Opcode.Binary;
- }
- }
+ public bool IsBinary => _opcode == Opcode.Binary;
- public bool IsClose
- {
- get
- {
- return _opcode == Opcode.Close;
- }
- }
+ public bool IsClose => _opcode == Opcode.Close;
- public bool IsCompressed
- {
- get
- {
- return _rsv1 == Rsv.On;
- }
- }
+ public bool IsCompressed => _rsv1 == Rsv.On;
- public bool IsContinuation
- {
- get
- {
- return _opcode == Opcode.Cont;
- }
- }
+ public bool IsContinuation => _opcode == Opcode.Cont;
- public bool IsControl
- {
- get
- {
- return _opcode == Opcode.Close || _opcode == Opcode.Ping || _opcode == Opcode.Pong;
- }
- }
+ public bool IsControl => _opcode == Opcode.Close || _opcode == Opcode.Ping || _opcode == Opcode.Pong;
- public bool IsData
- {
- get
- {
- return _opcode == Opcode.Binary || _opcode == Opcode.Text;
- }
- }
+ public bool IsData => _opcode == Opcode.Binary || _opcode == Opcode.Text;
- public bool IsFinal
- {
- get
- {
- return _fin == Fin.Final;
- }
- }
+ public bool IsFinal => _fin == Fin.Final;
- public bool IsFragmented
- {
- get
- {
- return _fin == Fin.More || _opcode == Opcode.Cont;
- }
- }
+ public bool IsFragmented => _fin == Fin.More || _opcode == Opcode.Cont;
- public bool IsMasked
- {
- get
- {
- return _mask == Mask.Mask;
- }
- }
+ public bool IsMasked => _mask == Mask.Mask;
- public bool IsPerMessageCompressed
- {
- get
- {
- return (_opcode == Opcode.Binary || _opcode == Opcode.Text) && _rsv1 == Rsv.On;
- }
- }
+ public bool IsPerMessageCompressed => (_opcode == Opcode.Binary || _opcode == Opcode.Text) && _rsv1 == Rsv.On;
- public bool IsPing
- {
- get
- {
- return _opcode == Opcode.Ping;
- }
- }
+ public bool IsPing => _opcode == Opcode.Ping;
- public bool IsPong
- {
- get
- {
- return _opcode == Opcode.Pong;
- }
- }
+ public bool IsPong => _opcode == Opcode.Pong;
- public bool IsText
- {
- get
- {
- return _opcode == Opcode.Text;
- }
- }
+ public bool IsText => _opcode == Opcode.Text;
- public ulong Length
- {
- get
- {
- return 2 + (ulong)(_extPayloadLength.Length + _maskingKey.Length) + _payloadData.Length;
- }
- }
+ public ulong Length => 2 + (ulong)(_extPayloadLength.Length + _maskingKey.Length) + _payloadData.Length;
- public Mask Mask
- {
- get
- {
- return _mask;
- }
- }
+ public Mask Mask => _mask;
- public byte[] MaskingKey
- {
- get
- {
- return _maskingKey;
- }
- }
+ public byte[] MaskingKey => _maskingKey;
- public Opcode Opcode
- {
- get
- {
- return _opcode;
- }
- }
+ public Opcode Opcode => _opcode;
- public PayloadData PayloadData
- {
- get
- {
- return _payloadData;
- }
- }
+ public PayloadData PayloadData => _payloadData;
- public byte PayloadLength
- {
- get
- {
- return _payloadLength;
- }
- }
+ public byte PayloadLength => _payloadLength;
- public Rsv Rsv1
- {
- get
- {
- return _rsv1;
- }
- }
+ public Rsv Rsv1 => _rsv1;
- public Rsv Rsv2
- {
- get
- {
- return _rsv2;
- }
- }
+ public Rsv Rsv2 => _rsv2;
- public Rsv Rsv3
- {
- get
- {
- return _rsv3;
- }
- }
+ public Rsv Rsv3 => _rsv3;
#endregion
@@ -575,4 +430,4 @@ namespace SocketHttpListener
#endregion
}
-} \ No newline at end of file
+}