Visual Studio Reformat: SocketHttpListener

This commit is contained in:
Erwin de Haan 2019-01-13 20:27:29 +01:00
parent 9014e16037
commit 8fd0bc63b9
53 changed files with 946 additions and 1042 deletions

View file

@ -1,17 +1,17 @@
namespace SocketHttpListener 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> /// <summary>
/// Indicates a Little-endian. /// Contains the values that indicate whether the byte order is a Little-endian or Big-endian.
/// </summary> /// </summary>
Little, public enum ByteOrder : byte
/// <summary> {
/// Indicates a Big-endian. /// <summary>
/// </summary> /// Indicates a Little-endian.
Big /// </summary>
} Little,
/// <summary>
/// Indicates a Big-endian.
/// </summary>
Big
}
} }

View file

@ -3,88 +3,95 @@ using System.Text;
namespace SocketHttpListener namespace SocketHttpListener
{ {
/// <summary> /// <summary>
/// Contains the event data associated with a <see cref="WebSocket.OnClose"/> event. /// Contains the event data associated with a <see cref="WebSocket.OnClose"/> event.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// A <see cref="WebSocket.OnClose"/> event occurs when the WebSocket connection has been closed. /// 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 /// If you would like to get the reason for the close, you should access the <see cref="Code"/> or
/// <see cref="Reason"/> property. /// <see cref="Reason"/> property.
/// </remarks> /// </remarks>
public class CloseEventArgs : EventArgs public class CloseEventArgs : EventArgs
{
#region Private Fields
private bool _clean;
private ushort _code;
private string _reason;
#endregion
#region Internal Constructors
internal CloseEventArgs (PayloadData payload)
{ {
var data = payload.ApplicationData; #region Private Fields
var len = data.Length;
_code = len > 1
? data.SubArray (0, 2).ToUInt16 (ByteOrder.Big)
: (ushort) CloseStatusCode.NoStatusCode;
_reason = len > 2 private bool _clean;
? GetUtf8String(data.SubArray (2, len - 2)) private ushort _code;
: string.Empty; private string _reason;
#endregion
#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;
_reason = len > 2
? GetUtf8String(data.SubArray(2, len - 2))
: string.Empty;
}
private static string GetUtf8String(byte[] bytes)
{
return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
}
#endregion
#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 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 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;
}
internal set
{
_clean = value;
}
}
#endregion
} }
private static string GetUtf8String(byte[] bytes)
{
return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
}
#endregion
#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 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 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;
}
internal set {
_clean = value;
}
}
#endregion
}
} }

View file

@ -1,94 +1,94 @@
namespace SocketHttpListener 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> /// <summary>
/// Equivalent to close status 1000. /// Contains the values of the status code for the WebSocket connection close.
/// Indicates a normal close.
/// </summary> /// </summary>
Normal = 1000, /// <remarks>
/// <summary> /// <para>
/// Equivalent to close status 1001. /// The values of the status code are defined in
/// Indicates that an endpoint is going away. /// <see href="http://tools.ietf.org/html/rfc6455#section-7.4">Section 7.4</see>
/// </summary> /// of RFC 6455.
Away = 1001, /// </para>
/// <summary> /// <para>
/// Equivalent to close status 1002. /// "Reserved value" must not be set as a status code in a close control frame
/// Indicates that an endpoint is terminating the connection due to a protocol error. /// by an endpoint. It's designated for use in applications expecting a status
/// </summary> /// code to indicate that the connection was closed due to the system grounds.
ProtocolError = 1002, /// </para>
/// <summary> /// </remarks>
/// Equivalent to close status 1003. public enum CloseStatusCode : ushort
/// Indicates that an endpoint is terminating the connection because it has received {
/// an unacceptable type message. /// <summary>
/// </summary> /// Equivalent to close status 1000.
IncorrectData = 1003, /// Indicates a normal close.
/// <summary> /// </summary>
/// Equivalent to close status 1004. Normal = 1000,
/// Still undefined. Reserved value. /// <summary>
/// </summary> /// Equivalent to close status 1001.
Undefined = 1004, /// Indicates that an endpoint is going away.
/// <summary> /// </summary>
/// Equivalent to close status 1005. Away = 1001,
/// Indicates that no status code was actually present. Reserved value. /// <summary>
/// </summary> /// Equivalent to close status 1002.
NoStatusCode = 1005, /// Indicates that an endpoint is terminating the connection due to a protocol error.
/// <summary> /// </summary>
/// Equivalent to close status 1006. ProtocolError = 1002,
/// Indicates that the connection was closed abnormally. Reserved value. /// <summary>
/// </summary> /// Equivalent to close status 1003.
Abnormal = 1006, /// Indicates that an endpoint is terminating the connection because it has received
/// <summary> /// an unacceptable type message.
/// Equivalent to close status 1007. /// </summary>
/// Indicates that an endpoint is terminating the connection because it has received IncorrectData = 1003,
/// a message that contains a data that isn't consistent with the type of the message. /// <summary>
/// </summary> /// Equivalent to close status 1004.
InconsistentData = 1007, /// Still undefined. Reserved value.
/// <summary> /// </summary>
/// Equivalent to close status 1008. Undefined = 1004,
/// Indicates that an endpoint is terminating the connection because it has received /// <summary>
/// a message that violates its policy. /// Equivalent to close status 1005.
/// </summary> /// Indicates that no status code was actually present. Reserved value.
PolicyViolation = 1008, /// </summary>
/// <summary> NoStatusCode = 1005,
/// Equivalent to close status 1009. /// <summary>
/// Indicates that an endpoint is terminating the connection because it has received /// Equivalent to close status 1006.
/// a message that is too big to process. /// Indicates that the connection was closed abnormally. Reserved value.
/// </summary> /// </summary>
TooBig = 1009, Abnormal = 1006,
/// <summary> /// <summary>
/// Equivalent to close status 1010. /// Equivalent to close status 1007.
/// Indicates that the client is terminating the connection because it has expected /// Indicates that an endpoint is terminating the connection because it has received
/// the server to negotiate one or more extension, but the server didn't return them /// a message that contains a data that isn't consistent with the type of the message.
/// in the handshake response. /// </summary>
/// </summary> InconsistentData = 1007,
IgnoreExtension = 1010, /// <summary>
/// <summary> /// Equivalent to close status 1008.
/// Equivalent to close status 1011. /// Indicates that an endpoint is terminating the connection because it has received
/// Indicates that the server is terminating the connection because it has encountered /// a message that violates its policy.
/// an unexpected condition that prevented it from fulfilling the request. /// </summary>
/// </summary> PolicyViolation = 1008,
ServerError = 1011, /// <summary>
/// <summary> /// Equivalent to close status 1009.
/// Equivalent to close status 1015. /// Indicates that an endpoint is terminating the connection because it has received
/// Indicates that the connection was closed due to a failure to perform a TLS handshake. /// a message that is too big to process.
/// Reserved value. /// </summary>
/// </summary> TooBig = 1009,
TlsHandshakeFailure = 1015 /// <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
}
} }

View file

@ -1,23 +1,23 @@
namespace SocketHttpListener 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> /// <summary>
/// Indicates non compression. /// Contains the values of the compression method used to compress the message on the WebSocket
/// connection.
/// </summary> /// </summary>
None, /// <remarks>
/// <summary> /// The values of the compression method are defined in
/// Indicates using DEFLATE. /// <see href="http://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-09">Compression
/// </summary> /// Extensions for WebSocket</see>.
Deflate /// </remarks>
} public enum CompressionMethod : byte
{
/// <summary>
/// Indicates non compression.
/// </summary>
None,
/// <summary>
/// Indicates using DEFLATE.
/// </summary>
Deflate
}
} }

View file

@ -2,45 +2,47 @@ using System;
namespace SocketHttpListener 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
private string _message;
#endregion
#region Internal Constructors
internal ErrorEventArgs (string message)
{
_message = message;
}
#endregion
#region Public Properties
/// <summary> /// <summary>
/// Gets the error message. /// Contains the event data associated with a <see cref="WebSocket.OnError"/> event.
/// </summary> /// </summary>
/// <value> /// <remarks>
/// A <see cref="string"/> that represents the error message. /// A <see cref="WebSocket.OnError"/> event occurs when the <see cref="WebSocket"/> gets an error.
/// </value> /// If you would like to get the error message, you should access the <see cref="Message"/>
public string Message { /// property.
get { /// </remarks>
return _message; public class ErrorEventArgs : EventArgs
} {
} #region Private Fields
#endregion private string _message;
}
#endregion
#region Internal Constructors
internal ErrorEventArgs(string message)
{
_message = message;
}
#endregion
#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;
}
}
#endregion
}
} }

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Net; using System.Net;
@ -441,7 +440,8 @@ namespace SocketHttpListener
continue; continue;
} }
} }
else { else
{
} }
buffer.Append(c); buffer.Append(c);

View file

@ -1,8 +1,8 @@
namespace SocketHttpListener namespace SocketHttpListener
{ {
internal enum Fin : byte internal enum Fin : byte
{ {
More = 0x0, More = 0x0,
Final = 0x1 Final = 0x1
} }
} }

View file

@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Text; using System.Text;
using System.Threading;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
namespace SocketHttpListener namespace SocketHttpListener

View file

@ -1,13 +1,11 @@
using System; using System;
using System.Collections.Specialized; using System.Linq;
using System.IO;
using System.Net; using System.Net;
using System.Text; using System.Text;
using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
using HttpVersion = SocketHttpListener.Net.HttpVersion;
using System.Linq;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using SocketHttpListener.Net; using SocketHttpListener.Net;
using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
using HttpVersion = SocketHttpListener.Net.HttpVersion;
namespace SocketHttpListener namespace SocketHttpListener
{ {

View file

@ -1,8 +1,8 @@
namespace SocketHttpListener namespace SocketHttpListener
{ {
internal enum Mask : byte internal enum Mask : byte
{ {
Unmask = 0x0, Unmask = 0x0,
Mask = 0x1 Mask = 0x1
} }
} }

View file

@ -3,94 +3,100 @@ using System.Text;
namespace SocketHttpListener 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
private string _data;
private Opcode _opcode;
private byte[] _rawData;
#endregion
#region Internal Constructors
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);
}
#endregion
#region Public Properties
/// <summary> /// <summary>
/// Gets the received data as a <see cref="string"/>. /// Contains the event data associated with a <see cref="WebSocket.OnMessage"/> event.
/// </summary> /// </summary>
/// <value> /// <remarks>
/// A <see cref="string"/> that contains the received data. /// A <see cref="WebSocket.OnMessage"/> event occurs when the <see cref="WebSocket"/> receives
/// </value> /// a text or binary data frame.
public string Data { /// If you want to get the received data, you access the <see cref="MessageEventArgs.Data"/> or
get { /// <see cref="MessageEventArgs.RawData"/> property.
return _data; /// </remarks>
} public class MessageEventArgs : EventArgs
}
/// <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 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;
}
}
#endregion
#region Private Methods
private static string convertToString (Opcode opcode, byte [] data)
{ {
return data.Length == 0 #region Private Fields
? string.Empty
: opcode == Opcode.Text
? Encoding.UTF8.GetString (data, 0, data.Length)
: opcode.ToString ();
}
#endregion private string _data;
} private Opcode _opcode;
private byte[] _rawData;
#endregion
#region Internal Constructors
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);
}
#endregion
#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 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 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;
}
}
#endregion
#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();
}
#endregion
}
} }

View file

@ -1,8 +1,4 @@
using System; namespace SocketHttpListener.Net
using System.Collections.Generic;
using System.Text;
namespace SocketHttpListener.Net
{ {
internal class AuthenticationTypes internal class AuthenticationTypes
{ {

View file

@ -1,9 +1,4 @@
using System; namespace SocketHttpListener.Net
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net
{ {
internal enum BoundaryType internal enum BoundaryType
{ {

View file

@ -1,5 +1,4 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;

View file

@ -1,8 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Runtime.InteropServices;
using SocketHttpListener.Primitives;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,9 +1,4 @@
using System; namespace SocketHttpListener.Net
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net
{ {
internal enum EntitySendFormat internal enum EntitySendFormat
{ {

View file

@ -3,19 +3,17 @@ using System.IO;
using System.Net; using System.Net;
using System.Net.Security; using System.Net.Security;
using System.Net.Sockets; using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.System; using MediaBrowser.Model.System;
using MediaBrowser.Model.Text; using MediaBrowser.Model.Text;
using Microsoft.Extensions.Logging;
using SocketHttpListener.Primitives; using SocketHttpListener.Primitives;
using System.Security.Authentication;
using System.Threading;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {
sealed class HttpConnection sealed class HttpConnection

View file

@ -1,21 +1,15 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Threading; using System.Threading;
using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Net; using MediaBrowser.Model.Net;
using MediaBrowser.Model.System; using MediaBrowser.Model.System;
using MediaBrowser.Model.Text; using MediaBrowser.Model.Text;
using SocketHttpListener.Primitives; using Microsoft.Extensions.Logging;
using ProtocolType = MediaBrowser.Model.Net.ProtocolType;
using SocketType = MediaBrowser.Model.Net.SocketType;
using System.Threading.Tasks;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {
@ -209,7 +203,7 @@ namespace SocketHttpListener.Net
return; return;
} }
if(accepted == null) if (accepted == null)
{ {
return; return;
} }

View file

@ -3,12 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Reflection;
using System.Threading.Tasks;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Net;
using SocketHttpListener.Primitives;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,8 +1,4 @@
using System; namespace SocketHttpListener.Net
using System.Collections.Generic;
using System.Text;
namespace SocketHttpListener.Net
{ {
internal static partial class HttpKnownHeaderNames internal static partial class HttpKnownHeaderNames
{ {

View file

@ -1,17 +1,15 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Net; using System.Net;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Model.Cryptography; using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Net; using MediaBrowser.Model.Net;
using MediaBrowser.Model.System; using MediaBrowser.Model.System;
using MediaBrowser.Model.Text; using MediaBrowser.Model.Text;
using SocketHttpListener.Primitives; using Microsoft.Extensions.Logging;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,8 +1,8 @@
using System.ComponentModel; using System;
using System.ComponentModel;
using System.Security.Principal; using System.Security.Principal;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System;
using MediaBrowser.Model.Text; using MediaBrowser.Model.Text;
using SocketHttpListener.Net.WebSockets; using SocketHttpListener.Net.WebSockets;

View file

@ -1,12 +1,8 @@
using System; using System;
using System.Net; using System.Net;
using System.Security.Principal; 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 System.Threading.Tasks;
using SocketHttpListener.Net.WebSockets;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,12 +1,7 @@
using System; using System;
using System.Text;
using System.Collections.Specialized;
using System.Globalization;
using System.IO; using System.IO;
using System.Security.Authentication.ExtendedProtection; using System.Text;
using System.Security.Cryptography.X509Certificates;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using MediaBrowser.Model.Text;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,17 +1,11 @@
using System; using System;
using System.Collections.Specialized;
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 System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Text;
using MediaBrowser.Model.Services;
using SocketHttpListener.Net.WebSockets; using SocketHttpListener.Net.WebSockets;
using SocketHttpListener.Primitives;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,8 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text;
using System.Globalization; using System.Globalization;
using System.Text;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,14 +1,13 @@
using System; using System;
using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Text; using MediaBrowser.Model.Text;
using SocketHttpListener.Primitives; using SocketHttpListener.Primitives;
using System.Threading;
using MediaBrowser.Model.IO;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,14 +1,7 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Text; 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 namespace SocketHttpListener.Net
{ {

View file

@ -1,9 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View file

@ -1,15 +1,13 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Runtime.ExceptionServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.System; using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;

View file

@ -1,321 +1,321 @@
namespace SocketHttpListener.Net 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> /// <summary>
/// Equivalent to status code 100. /// Contains the values of the HTTP status codes.
/// Indicates that the client should continue with its request.
/// </summary> /// </summary>
Continue = 100, /// <remarks>
/// <summary> /// The HttpStatusCode enumeration contains the values of the HTTP status codes defined in
/// Equivalent to status code 101. /// <see href="http://tools.ietf.org/html/rfc2616#section-10">RFC 2616</see> for HTTP 1.1.
/// Indicates that the server is switching the HTTP version or protocol on the connection. /// </remarks>
/// </summary> public enum HttpStatusCode
SwitchingProtocols = 101, {
/// <summary> /// <summary>
/// Equivalent to status code 200. /// Equivalent to status code 100.
/// Indicates that the client's request has succeeded. /// Indicates that the client should continue with its request.
/// </summary> /// </summary>
OK = 200, Continue = 100,
/// <summary> /// <summary>
/// Equivalent to status code 201. /// Equivalent to status code 101.
/// Indicates that the client's request has been fulfilled and resulted in a new resource being /// Indicates that the server is switching the HTTP version or protocol on the connection.
/// created. /// </summary>
/// </summary> SwitchingProtocols = 101,
Created = 201, /// <summary>
/// <summary> /// Equivalent to status code 200.
/// Equivalent to status code 202. /// Indicates that the client's request has succeeded.
/// Indicates that the client's request has been accepted for processing, but the processing /// </summary>
/// hasn't been completed. OK = 200,
/// </summary> /// <summary>
Accepted = 202, /// Equivalent to status code 201.
/// <summary> /// Indicates that the client's request has been fulfilled and resulted in a new resource being
/// Equivalent to status code 203. /// created.
/// Indicates that the returned metainformation is from a local or a third-party copy instead of /// </summary>
/// the origin server. Created = 201,
/// </summary> /// <summary>
NonAuthoritativeInformation = 203, /// Equivalent to status code 202.
/// <summary> /// Indicates that the client's request has been accepted for processing, but the processing
/// Equivalent to status code 204. /// hasn't been completed.
/// Indicates that the server has fulfilled the client's request but doesn't need to return /// </summary>
/// an entity-body. Accepted = 202,
/// </summary> /// <summary>
NoContent = 204, /// Equivalent to status code 203.
/// <summary> /// Indicates that the returned metainformation is from a local or a third-party copy instead of
/// Equivalent to status code 205. /// the origin server.
/// Indicates that the server has fulfilled the client's request, and the user agent should /// </summary>
/// reset the document view which caused the request to be sent. NonAuthoritativeInformation = 203,
/// </summary> /// <summary>
ResetContent = 205, /// Equivalent to status code 204.
/// <summary> /// Indicates that the server has fulfilled the client's request but doesn't need to return
/// Equivalent to status code 206. /// an entity-body.
/// Indicates that the server has fulfilled the partial GET request for the resource. /// </summary>
/// </summary> NoContent = 204,
PartialContent = 206, /// <summary>
/// <summary> /// Equivalent to status code 205.
/// <para> /// Indicates that the server has fulfilled the client's request, and the user agent should
/// Equivalent to status code 300. /// reset the document view which caused the request to be sent.
/// Indicates that the requested resource corresponds to any of multiple representations. /// </summary>
/// </para> ResetContent = 205,
/// <para> /// <summary>
/// MultipleChoices is a synonym for Ambiguous. /// Equivalent to status code 206.
/// </para> /// Indicates that the server has fulfilled the partial GET request for the resource.
/// </summary> /// </summary>
MultipleChoices = 300, PartialContent = 206,
/// <summary> /// <summary>
/// <para> /// <para>
/// Equivalent to status code 300. /// Equivalent to status code 300.
/// Indicates that the requested resource corresponds to any of multiple representations. /// Indicates that the requested resource corresponds to any of multiple representations.
/// </para> /// </para>
/// <para> /// <para>
/// Ambiguous is a synonym for MultipleChoices. /// MultipleChoices is a synonym for Ambiguous.
/// </para> /// </para>
/// </summary> /// </summary>
Ambiguous = 300, MultipleChoices = 300,
/// <summary> /// <summary>
/// <para> /// <para>
/// Equivalent to status code 301. /// Equivalent to status code 300.
/// Indicates that the requested resource has been assigned a new permanent URI and /// Indicates that the requested resource corresponds to any of multiple representations.
/// any future references to this resource should use one of the returned URIs. /// </para>
/// </para> /// <para>
/// <para> /// Ambiguous is a synonym for MultipleChoices.
/// MovedPermanently is a synonym for Moved. /// </para>
/// </para> /// </summary>
/// </summary> Ambiguous = 300,
MovedPermanently = 301, /// <summary>
/// <summary> /// <para>
/// <para> /// Equivalent to status code 301.
/// Equivalent to status code 301. /// Indicates that the requested resource has been assigned a new permanent URI and
/// 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.
/// any future references to this resource should use one of the returned URIs. /// </para>
/// </para> /// <para>
/// <para> /// MovedPermanently is a synonym for Moved.
/// Moved is a synonym for MovedPermanently. /// </para>
/// </para> /// </summary>
/// </summary> MovedPermanently = 301,
Moved = 301, /// <summary>
/// <summary> /// <para>
/// <para> /// Equivalent to status code 301.
/// Equivalent to status code 302. /// Indicates that the requested resource has been assigned a new permanent URI and
/// Indicates that the requested resource is located temporarily under a different URI. /// any future references to this resource should use one of the returned URIs.
/// </para> /// </para>
/// <para> /// <para>
/// Found is a synonym for Redirect. /// Moved is a synonym for MovedPermanently.
/// </para> /// </para>
/// </summary> /// </summary>
Found = 302, Moved = 301,
/// <summary> /// <summary>
/// <para> /// <para>
/// Equivalent to status code 302. /// Equivalent to status code 302.
/// Indicates that the requested resource is located temporarily under a different URI. /// Indicates that the requested resource is located temporarily under a different URI.
/// </para> /// </para>
/// <para> /// <para>
/// Redirect is a synonym for Found. /// Found is a synonym for Redirect.
/// </para> /// </para>
/// </summary> /// </summary>
Redirect = 302, Found = 302,
/// <summary> /// <summary>
/// <para> /// <para>
/// Equivalent to status code 303. /// Equivalent to status code 302.
/// Indicates that the response to the request can be found under a different URI and /// Indicates that the requested resource is located temporarily under a different URI.
/// should be retrieved using a GET method on that resource. /// </para>
/// </para> /// <para>
/// <para> /// Redirect is a synonym for Found.
/// SeeOther is a synonym for RedirectMethod. /// </para>
/// </para> /// </summary>
/// </summary> Redirect = 302,
SeeOther = 303, /// <summary>
/// <summary> /// <para>
/// <para> /// Equivalent to status code 303.
/// Equivalent to status code 303. /// Indicates that the response to the request can be found under a different URI and
/// 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.
/// should be retrieved using a GET method on that resource. /// </para>
/// </para> /// <para>
/// <para> /// SeeOther is a synonym for RedirectMethod.
/// RedirectMethod is a synonym for SeeOther. /// </para>
/// </para> /// </summary>
/// </summary> SeeOther = 303,
RedirectMethod = 303, /// <summary>
/// <summary> /// <para>
/// Equivalent to status code 304. /// Equivalent to status code 303.
/// Indicates that the client has performed a conditional GET request and access is allowed, /// Indicates that the response to the request can be found under a different URI and
/// but the document hasn't been modified. /// should be retrieved using a GET method on that resource.
/// </summary> /// </para>
NotModified = 304, /// <para>
/// <summary> /// RedirectMethod is a synonym for SeeOther.
/// Equivalent to status code 305. /// </para>
/// Indicates that the requested resource must be accessed through the proxy given by /// </summary>
/// the Location field. RedirectMethod = 303,
/// </summary> /// <summary>
UseProxy = 305, /// Equivalent to status code 304.
/// <summary> /// Indicates that the client has performed a conditional GET request and access is allowed,
/// Equivalent to status code 306. /// but the document hasn't been modified.
/// This status code was used in a previous version of the specification, is no longer used, /// </summary>
/// and is reserved for future use. NotModified = 304,
/// </summary> /// <summary>
Unused = 306, /// Equivalent to status code 305.
/// <summary> /// Indicates that the requested resource must be accessed through the proxy given by
/// <para> /// the Location field.
/// Equivalent to status code 307. /// </summary>
/// Indicates that the requested resource is located temporarily under a different URI. UseProxy = 305,
/// </para> /// <summary>
/// <para> /// Equivalent to status code 306.
/// TemporaryRedirect is a synonym for RedirectKeepVerb. /// This status code was used in a previous version of the specification, is no longer used,
/// </para> /// and is reserved for future use.
/// </summary> /// </summary>
TemporaryRedirect = 307, Unused = 306,
/// <summary> /// <summary>
/// <para> /// <para>
/// Equivalent to status code 307. /// Equivalent to status code 307.
/// Indicates that the requested resource is located temporarily under a different URI. /// Indicates that the requested resource is located temporarily under a different URI.
/// </para> /// </para>
/// <para> /// <para>
/// RedirectKeepVerb is a synonym for TemporaryRedirect. /// TemporaryRedirect is a synonym for RedirectKeepVerb.
/// </para> /// </para>
/// </summary> /// </summary>
RedirectKeepVerb = 307, TemporaryRedirect = 307,
/// <summary> /// <summary>
/// Equivalent to status code 400. /// <para>
/// Indicates that the client's request couldn't be understood by the server due to /// Equivalent to status code 307.
/// malformed syntax. /// Indicates that the requested resource is located temporarily under a different URI.
/// </summary> /// </para>
BadRequest = 400, /// <para>
/// <summary> /// RedirectKeepVerb is a synonym for TemporaryRedirect.
/// Equivalent to status code 401. /// </para>
/// Indicates that the client's request requires user authentication. /// </summary>
/// </summary> RedirectKeepVerb = 307,
Unauthorized = 401, /// <summary>
/// <summary> /// Equivalent to status code 400.
/// Equivalent to status code 402. /// Indicates that the client's request couldn't be understood by the server due to
/// This status code is reserved for future use. /// malformed syntax.
/// </summary> /// </summary>
PaymentRequired = 402, BadRequest = 400,
/// <summary> /// <summary>
/// Equivalent to status code 403. /// Equivalent to status code 401.
/// Indicates that the server understood the client's request but is refusing to fulfill it. /// Indicates that the client's request requires user authentication.
/// </summary> /// </summary>
Forbidden = 403, Unauthorized = 401,
/// <summary> /// <summary>
/// Equivalent to status code 404. /// Equivalent to status code 402.
/// Indicates that the server hasn't found anything matching the request URI. /// This status code is reserved for future use.
/// </summary> /// </summary>
NotFound = 404, PaymentRequired = 402,
/// <summary> /// <summary>
/// Equivalent to status code 405. /// Equivalent to status code 403.
/// Indicates that the method specified in the request line isn't allowed for the resource /// Indicates that the server understood the client's request but is refusing to fulfill it.
/// identified by the request URI. /// </summary>
/// </summary> Forbidden = 403,
MethodNotAllowed = 405, /// <summary>
/// <summary> /// Equivalent to status code 404.
/// Equivalent to status code 406. /// Indicates that the server hasn't found anything matching the request URI.
/// Indicates that the server doesn't have the appropriate resource to respond to the Accept /// </summary>
/// headers in the client's request. NotFound = 404,
/// </summary> /// <summary>
NotAcceptable = 406, /// Equivalent to status code 405.
/// <summary> /// Indicates that the method specified in the request line isn't allowed for the resource
/// Equivalent to status code 407. /// identified by the request URI.
/// Indicates that the client must first authenticate itself with the proxy. /// </summary>
/// </summary> MethodNotAllowed = 405,
ProxyAuthenticationRequired = 407, /// <summary>
/// <summary> /// Equivalent to status code 406.
/// Equivalent to status code 408. /// Indicates that the server doesn't have the appropriate resource to respond to the Accept
/// Indicates that the client didn't produce a request within the time that the server was /// headers in the client's request.
/// prepared to wait. /// </summary>
/// </summary> NotAcceptable = 406,
RequestTimeout = 408, /// <summary>
/// <summary> /// Equivalent to status code 407.
/// Equivalent to status code 409. /// Indicates that the client must first authenticate itself with the proxy.
/// Indicates that the client's request couldn't be completed due to a conflict on the server. /// </summary>
/// </summary> ProxyAuthenticationRequired = 407,
Conflict = 409, /// <summary>
/// <summary> /// Equivalent to status code 408.
/// Equivalent to status code 410. /// Indicates that the client didn't produce a request within the time that the server was
/// Indicates that the requested resource is no longer available at the server and /// prepared to wait.
/// no forwarding address is known. /// </summary>
/// </summary> RequestTimeout = 408,
Gone = 410, /// <summary>
/// <summary> /// Equivalent to status code 409.
/// Equivalent to status code 411. /// Indicates that the client's request couldn't be completed due to a conflict on the server.
/// Indicates that the server refuses to accept the client's request without a defined /// </summary>
/// Content-Length. Conflict = 409,
/// </summary> /// <summary>
LengthRequired = 411, /// Equivalent to status code 410.
/// <summary> /// Indicates that the requested resource is no longer available at the server and
/// Equivalent to status code 412. /// no forwarding address is known.
/// Indicates that the precondition given in one or more of the request headers evaluated to /// </summary>
/// false when it was tested on the server. Gone = 410,
/// </summary> /// <summary>
PreconditionFailed = 412, /// Equivalent to status code 411.
/// <summary> /// Indicates that the server refuses to accept the client's request without a defined
/// Equivalent to status code 413. /// Content-Length.
/// Indicates that the entity of the client's request is larger than the server is willing or /// </summary>
/// able to process. LengthRequired = 411,
/// </summary> /// <summary>
RequestEntityTooLarge = 413, /// Equivalent to status code 412.
/// <summary> /// Indicates that the precondition given in one or more of the request headers evaluated to
/// Equivalent to status code 414. /// false when it was tested on the server.
/// Indicates that the request URI is longer than the server is willing to interpret. /// </summary>
/// </summary> PreconditionFailed = 412,
RequestUriTooLong = 414, /// <summary>
/// <summary> /// Equivalent to status code 413.
/// Equivalent to status code 415. /// Indicates that the entity of the client's request is larger than the server is willing or
/// Indicates that the entity of the client's request is in a format not supported by /// able to process.
/// the requested resource for the requested method. /// </summary>
/// </summary> RequestEntityTooLarge = 413,
UnsupportedMediaType = 415, /// <summary>
/// <summary> /// Equivalent to status code 414.
/// Equivalent to status code 416. /// Indicates that the request URI is longer than the server is willing to interpret.
/// Indicates that none of the range specifier values in a Range request header overlap /// </summary>
/// the current extent of the selected resource. RequestUriTooLong = 414,
/// </summary> /// <summary>
RequestedRangeNotSatisfiable = 416, /// Equivalent to status code 415.
/// <summary> /// Indicates that the entity of the client's request is in a format not supported by
/// Equivalent to status code 417. /// the requested resource for the requested method.
/// Indicates that the expectation given in an Expect request header couldn't be met by /// </summary>
/// the server. UnsupportedMediaType = 415,
/// </summary> /// <summary>
ExpectationFailed = 417, /// Equivalent to status code 416.
/// <summary> /// Indicates that none of the range specifier values in a Range request header overlap
/// Equivalent to status code 500. /// the current extent of the selected resource.
/// Indicates that the server encountered an unexpected condition which prevented it from /// </summary>
/// fulfilling the client's request. RequestedRangeNotSatisfiable = 416,
/// </summary> /// <summary>
InternalServerError = 500, /// Equivalent to status code 417.
/// <summary> /// Indicates that the expectation given in an Expect request header couldn't be met by
/// Equivalent to status code 501. /// the server.
/// Indicates that the server doesn't support the functionality required to fulfill the client's /// </summary>
/// request. ExpectationFailed = 417,
/// </summary> /// <summary>
NotImplemented = 501, /// Equivalent to status code 500.
/// <summary> /// Indicates that the server encountered an unexpected condition which prevented it from
/// Equivalent to status code 502. /// fulfilling the client's request.
/// Indicates that a gateway or proxy server received an invalid response from the upstream /// </summary>
/// server. InternalServerError = 500,
/// </summary> /// <summary>
BadGateway = 502, /// Equivalent to status code 501.
/// <summary> /// Indicates that the server doesn't support the functionality required to fulfill the client's
/// Equivalent to status code 503. /// request.
/// Indicates that the server is currently unable to handle the client's request due to /// </summary>
/// a temporary overloading or maintenance of the server. NotImplemented = 501,
/// </summary> /// <summary>
ServiceUnavailable = 503, /// Equivalent to status code 502.
/// <summary> /// Indicates that a gateway or proxy server received an invalid response from the upstream
/// Equivalent to status code 504. /// server.
/// Indicates that a gateway or proxy server didn't receive a timely response from the upstream /// </summary>
/// server or some other auxiliary server. BadGateway = 502,
/// </summary> /// <summary>
GatewayTimeout = 504, /// Equivalent to status code 503.
/// <summary> /// Indicates that the server is currently unable to handle the client's request due to
/// Equivalent to status code 505. /// a temporary overloading or maintenance of the server.
/// Indicates that the server doesn't support the HTTP version used in the client's request. /// </summary>
/// </summary> ServiceUnavailable = 503,
HttpVersionNotSupported = 505, /// <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,
}
} }

View file

@ -1,9 +1,4 @@
using System; namespace SocketHttpListener.Net
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net
{ {
internal static class HttpStatusDescription internal static class HttpStatusDescription
{ {

View file

@ -1,6 +1,5 @@
using System; using System;
using System.Net; using System.Net;
using MediaBrowser.Model.Net;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,8 +1,4 @@
using System; namespace SocketHttpListener.Net
using System.Collections.Generic;
using System.Text;
namespace SocketHttpListener.Net
{ {
internal static class UriScheme internal static class UriScheme
{ {

View file

@ -1,13 +1,8 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Text; using System.Text;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using MediaBrowser.Model.Extensions;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,7 +1,4 @@
using System; using System.Text;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net namespace SocketHttpListener.Net
{ {

View file

@ -1,14 +1,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net; using System.Net;
using System.Security.Principal; using System.Security.Principal;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
using SocketHttpListener.Primitives;
namespace SocketHttpListener.Net.WebSockets namespace SocketHttpListener.Net.WebSockets
{ {

View file

@ -1,6 +1,4 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace SocketHttpListener.Net.WebSockets namespace SocketHttpListener.Net.WebSockets

View file

@ -1,8 +1,7 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text;
using System.Threading; using System.Threading;
namespace SocketHttpListener.Net.WebSockets namespace SocketHttpListener.Net.WebSockets

View file

@ -1,8 +1,4 @@
using System; namespace SocketHttpListener.Net.WebSockets
using System.Collections.Generic;
using System.Text;
namespace SocketHttpListener.Net.WebSockets
{ {
public enum WebSocketCloseStatus public enum WebSocketCloseStatus
{ {

View file

@ -1,9 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net; using System.Net;
using System.Security.Principal; using System.Security.Principal;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Services; using MediaBrowser.Model.Services;
namespace SocketHttpListener.Net.WebSockets namespace SocketHttpListener.Net.WebSockets

View file

@ -1,8 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.Text;
using MediaBrowser.Model.Net;
using System.Globalization; using System.Globalization;
using System.Text;
using WebSocketState = System.Net.WebSockets.WebSocketState; using WebSocketState = System.Net.WebSockets.WebSocketState;
namespace SocketHttpListener.Net.WebSockets namespace SocketHttpListener.Net.WebSockets

View file

@ -1,43 +1,43 @@
namespace SocketHttpListener 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> /// <summary>
/// Equivalent to numeric value 0. /// Contains the values of the opcode that indicates the type of a WebSocket frame.
/// Indicates a continuation frame.
/// </summary> /// </summary>
Cont = 0x0, /// <remarks>
/// <summary> /// The values of the opcode are defined in
/// Equivalent to numeric value 1. /// <see href="http://tools.ietf.org/html/rfc6455#section-5.2">Section 5.2</see> of RFC 6455.
/// Indicates a text frame. /// </remarks>
/// </summary> public enum Opcode : byte
Text = 0x1, {
/// <summary> /// <summary>
/// Equivalent to numeric value 2. /// Equivalent to numeric value 0.
/// Indicates a binary frame. /// Indicates a continuation frame.
/// </summary> /// </summary>
Binary = 0x2, Cont = 0x0,
/// <summary> /// <summary>
/// Equivalent to numeric value 8. /// Equivalent to numeric value 1.
/// Indicates a connection close frame. /// Indicates a text frame.
/// </summary> /// </summary>
Close = 0x8, Text = 0x1,
/// <summary> /// <summary>
/// Equivalent to numeric value 9. /// Equivalent to numeric value 2.
/// Indicates a ping frame. /// Indicates a binary frame.
/// </summary> /// </summary>
Ping = 0x9, Binary = 0x2,
/// <summary> /// <summary>
/// Equivalent to numeric value 10. /// Equivalent to numeric value 8.
/// Indicates a pong frame. /// Indicates a connection close frame.
/// </summary> /// </summary>
Pong = 0xa 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
}
} }

View file

@ -5,145 +5,155 @@ using System.Text;
namespace SocketHttpListener namespace SocketHttpListener
{ {
internal class PayloadData : IEnumerable<byte> internal class PayloadData : IEnumerable<byte>
{
#region Private Fields
private byte [] _applicationData;
private byte [] _extensionData;
private bool _masked;
#endregion
#region Public Const Fields
public const ulong MaxLength = long.MaxValue;
#endregion
#region Public Constructors
public PayloadData ()
: this (new byte [0], new byte [0], false)
{ {
#region Private Fields
private byte[] _applicationData;
private byte[] _extensionData;
private bool _masked;
#endregion
#region Public Const Fields
public const ulong MaxLength = long.MaxValue;
#endregion
#region Public Constructors
public PayloadData()
: this(new byte[0], new byte[0], 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(byte[] applicationData, bool masked)
: this(new byte[0], applicationData, masked)
{
}
public PayloadData(byte[] extensionData, byte[] applicationData, bool masked)
{
_extensionData = extensionData;
_applicationData = applicationData;
_masked = masked;
}
#endregion
#region Internal Properties
internal bool ContainsReservedCloseStatusCode
{
get
{
return _applicationData.Length > 1 &&
_applicationData.SubArray(0, 2).ToUInt16(ByteOrder.Big).IsReserved();
}
}
#endregion
#region Public Properties
public byte[] ApplicationData
{
get
{
return _applicationData;
}
}
public byte[] ExtensionData
{
get
{
return _extensionData;
}
}
public bool IsMasked
{
get
{
return _masked;
}
}
public ulong Length
{
get
{
return (ulong)(_extensionData.Length + _applicationData.Length);
}
}
#endregion
#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]);
}
#endregion
#region Public Methods
public IEnumerator<byte> GetEnumerator()
{
foreach (byte b in _extensionData)
yield return b;
foreach (byte b in _applicationData)
yield return b;
}
public void Mask(byte[] maskingKey)
{
if (_extensionData.Length > 0)
mask(_extensionData, maskingKey);
if (_applicationData.Length > 0)
mask(_applicationData, maskingKey);
_masked = !_masked;
}
public byte[] ToByteArray()
{
return _extensionData.Length > 0
? new List<byte>(this).ToArray()
: _applicationData;
}
public override string ToString()
{
return BitConverter.ToString(ToByteArray());
}
#endregion
#region Explicitly Implemented Interface Members
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
} }
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 (byte [] applicationData, bool masked)
: this (new byte [0], applicationData, masked)
{
}
public PayloadData (byte [] extensionData, byte [] applicationData, bool masked)
{
_extensionData = extensionData;
_applicationData = applicationData;
_masked = masked;
}
#endregion
#region Internal Properties
internal bool ContainsReservedCloseStatusCode {
get {
return _applicationData.Length > 1 &&
_applicationData.SubArray (0, 2).ToUInt16 (ByteOrder.Big).IsReserved ();
}
}
#endregion
#region Public Properties
public byte [] ApplicationData {
get {
return _applicationData;
}
}
public byte [] ExtensionData {
get {
return _extensionData;
}
}
public bool IsMasked {
get {
return _masked;
}
}
public ulong Length {
get {
return (ulong) (_extensionData.Length + _applicationData.Length);
}
}
#endregion
#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]);
}
#endregion
#region Public Methods
public IEnumerator<byte> GetEnumerator ()
{
foreach (byte b in _extensionData)
yield return b;
foreach (byte b in _applicationData)
yield return b;
}
public void Mask (byte [] maskingKey)
{
if (_extensionData.Length > 0)
mask (_extensionData, maskingKey);
if (_applicationData.Length > 0)
mask (_applicationData, maskingKey);
_masked = !_masked;
}
public byte [] ToByteArray ()
{
return _extensionData.Length > 0
? new List<byte> (this).ToArray ()
: _applicationData;
}
public override string ToString ()
{
return BitConverter.ToString (ToByteArray ());
}
#endregion
#region Explicitly Implemented Interface Members
IEnumerator IEnumerable.GetEnumerator ()
{
return GetEnumerator ();
}
#endregion
}
} }

View file

@ -1,7 +1,4 @@
using System; using System.Text;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using MediaBrowser.Model.Text; using MediaBrowser.Model.Text;
namespace SocketHttpListener.Primitives namespace SocketHttpListener.Primitives

View file

@ -1,8 +1,8 @@
namespace SocketHttpListener namespace SocketHttpListener
{ {
internal enum Rsv : byte internal enum Rsv : byte
{ {
Off = 0x0, Off = 0x0,
On = 0x1 On = 0x1
} }
} }

View file

@ -1,10 +1,6 @@
using System; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener namespace SocketHttpListener
{ {

View file

@ -3,15 +3,12 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Net.Sockets;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO;
using SocketHttpListener.Net.WebSockets; using SocketHttpListener.Net.WebSockets;
using SocketHttpListener.Primitives;
using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode; using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
using System.Net.Sockets;
using WebSocketState = System.Net.WebSockets.WebSocketState; using WebSocketState = System.Net.WebSockets.WebSocketState;
namespace SocketHttpListener namespace SocketHttpListener

View file

@ -2,59 +2,60 @@ using System;
namespace SocketHttpListener 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> /// <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> /// </summary>
/// <value> public class WebSocketException : Exception
/// One of the <see cref="CloseStatusCode"/> enum values, represents the status code indicating {
/// the cause for the exception. #region Internal Constructors
/// </value>
public CloseStatusCode Code {
get; private set;
}
#endregion 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
}
} }

View file

@ -2,7 +2,6 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text;
namespace SocketHttpListener namespace SocketHttpListener
{ {