Class HttpHelper
- Namespace
- Alis.Core.Network
- Assembly
- Alis.dll
The http helper class
public class HttpHelper
Inheritance
Inherited Members
Fields
HttpGetHeaderRegex
The http get header regex
private const string HttpGetHeaderRegex = "^GET(.*)HTTP\\/1\\.1"
Field Value
Methods
CalculateWebSocketKey()
Calculates a random WebSocket key that can be used to initiate a WebSocket handshake
public static string CalculateWebSocketKey()
Returns
- string
-
A random websocket key
ComputeSocketAcceptString(string) Deprecated
Obsolete
Computes a WebSocket accept string from a given key
[Obsolete("Obsolete")]
public static string ComputeSocketAcceptString(string secWebSocketKey)
Parameters
secWebSocketKey
string-
The web socket key to base the accept string on
Returns
- string
-
A web socket accept string
GetPathFromHeader(string)
Gets the path from the HTTP header
public static string GetPathFromHeader(string httpHeader)
Parameters
httpHeader
string-
The HTTP header to read
Returns
- string
-
The path
GetSubProtocols(string)
Gets the sub protocols using the specified http header
public static IList<string> GetSubProtocols(string httpHeader)
Parameters
httpHeader
string-
The http header
Returns
Exceptions
- EntityTooLargeException
-
Sec-WebSocket-Protocol exceeded the maximum of length of {MAX_LEN}
IsWebSocketUpgradeRequest(string)
Decodes the header to detect is this is a web socket upgrade response
public static bool IsWebSocketUpgradeRequest(string header)
Parameters
header
string-
The HTTP header
Returns
- bool
-
True if this is an http WebSocket upgrade response
ReadHttpHeaderAsync(Stream, CancellationToken)
Reads an http header as per the HTTP spec
public static Task<string> ReadHttpHeaderAsync(Stream stream, CancellationToken token)
Parameters
stream
Stream-
The stream to read UTF8 text from
token
CancellationToken-
The cancellation token
Returns
ReadHttpResponseCode(string)
Reads the HTTP response code from the http response string
public static string ReadHttpResponseCode(string response)
Parameters
response
string-
The response string
Returns
- string
-
the response code
WriteHttpHeaderAsync(string, Stream, CancellationToken)
Writes an HTTP response string to the stream
public static Task WriteHttpHeaderAsync(string response, Stream stream, CancellationToken token)
Parameters
response
string-
The response (without the new line characters)
stream
Stream-
The stream to write to
token
CancellationToken-
The cancellation token