Class HttpListenerRequestContext
- Namespace
- Cratis.Arc.Http
- Assembly
- Cratis.Arc.Core.dll
Implementation of IHttpRequestContext for HttpListenerContext.
public class HttpListenerRequestContext : IHttpRequestContext
- Inheritance
-
HttpListenerRequestContext
- Implements
- Inherited Members
- Extension Methods
Remarks
Initializes a new instance of the HttpListenerRequestContext class.
Constructors
HttpListenerRequestContext(HttpListenerContext, IServiceProvider)
Implementation of IHttpRequestContext for HttpListenerContext.
public HttpListenerRequestContext(HttpListenerContext context, IServiceProvider serviceProvider)
Parameters
contextHttpListenerContextThe HttpListenerContext.
serviceProviderIServiceProviderThe IServiceProvider.
Remarks
Initializes a new instance of the HttpListenerRequestContext class.
Properties
ContentType
Gets the content type of the response.
public string? ContentType { get; set; }
Property Value
Cookies
Gets the request cookies.
public IReadOnlyDictionary<string, string> Cookies { get; }
Property Value
Headers
Gets the request headers.
public IReadOnlyDictionary<string, string> Headers { get; }
Property Value
Host
Gets the request host (without port).
public string Host { get; }
Property Value
IsHttps
Gets a value indicating whether the request is HTTPS.
public bool IsHttps { get; }
Property Value
Items
Gets a dictionary for storing arbitrary data during the request lifecycle.
public IDictionary<object, object?> Items { get; }
Property Value
Method
Gets the HTTP method (GET, POST, etc.).
public string Method { get; }
Property Value
Path
Gets the request path.
public string Path { get; }
Property Value
Query
Gets the query string parameters.
public IReadOnlyDictionary<string, string> Query { get; }
Property Value
RequestAborted
Gets the cancellation token for the request.
public CancellationToken RequestAborted { get; }
Property Value
RequestServices
Gets the service provider for the request scope.
public IServiceProvider RequestServices { get; }
Property Value
StatusCode
Gets the status code of the response.
public int StatusCode { get; set; }
Property Value
User
Gets or sets the user associated with the request.
public ClaimsPrincipal User { get; set; }
Property Value
WebSockets
Gets the WebSocket context for this request.
public IWebSocketContext WebSockets { get; }
Property Value
Methods
AppendCookie(string, string, CookieOptions)
Appends a cookie to the response.
public void AppendCookie(string key, string value, CookieOptions options)
Parameters
keystringThe cookie name.
valuestringThe cookie value.
optionsCookieOptionsThe cookie options.
GetResponseHeader(string)
Gets the current value of a response header.
public string? GetResponseHeader(string name)
Parameters
namestringHeader name.
Returns
- string
The header value, with multiple values combined as a comma-separated list, or null if the header is not set.
ReadBodyAsJson(Type, CancellationToken)
Reads the request body and deserializes it as JSON.
public Task<object?> ReadBodyAsJson(Type type, CancellationToken cancellationToken = default)
Parameters
typeTypeThe type to deserialize to.
cancellationTokenCancellationTokenCancellation token.
Returns
RemoveCookie(string)
Removes a cookie from the response.
public void RemoveCookie(string key)
Parameters
keystringThe cookie name.
SetResponseHeader(string, string)
Sets a response header.
public void SetResponseHeader(string name, string value)
Parameters
SetStatusCode(int)
Sets the HTTP response status code.
public void SetStatusCode(int statusCode)
Parameters
statusCodeintThe status code to set.
Write(string, CancellationToken)
Writes text to the response.
public Task Write(string text, CancellationToken cancellationToken = default)
Parameters
textstringThe text to write.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
A task representing the async operation.
WriteBytes(byte[], CancellationToken)
Writes bytes to the response.
public Task WriteBytes(byte[] data, CancellationToken cancellationToken = default)
Parameters
databyte[]The byte data to write.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
A task representing the async operation.
WriteResponseAsJson(object?, Type, CancellationToken)
Writes JSON to the response.
public Task WriteResponseAsJson(object? value, Type type, CancellationToken cancellationToken = default)
Parameters
valueobjectThe value to serialize.
typeTypeThe type of the value.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
A task representing the async operation.
WriteStream(Stream, CancellationToken)
Writes a stream to the response.
public Task WriteStream(Stream stream, CancellationToken cancellationToken = default)
Parameters
streamStreamThe stream to write.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
A task representing the async operation.