Interface IHttpRequestContext
- Namespace
- Cratis.Arc.Http
- Assembly
- Cratis.Arc.Core.dll
Represents an abstraction for an HTTP request context that can be implemented by different HTTP frameworks.
public interface IHttpRequestContext
- Extension Methods
Properties
ContentType
Gets the content type of the response.
string? ContentType { get; set; }
Property Value
Cookies
Gets the request cookies.
IReadOnlyDictionary<string, string> Cookies { get; }
Property Value
Headers
Gets the request headers.
IReadOnlyDictionary<string, string> Headers { get; }
Property Value
Host
Gets the request host (without port).
string Host { get; }
Property Value
IsHttps
Gets a value indicating whether the request is HTTPS.
bool IsHttps { get; }
Property Value
Items
Gets a dictionary for storing arbitrary data during the request lifecycle.
IDictionary<object, object?> Items { get; }
Property Value
Method
Gets the HTTP method (GET, POST, etc.).
string Method { get; }
Property Value
Path
Gets the request path.
string Path { get; }
Property Value
Query
Gets the query string parameters.
IReadOnlyDictionary<string, string> Query { get; }
Property Value
RequestAborted
Gets the cancellation token for the request.
CancellationToken RequestAborted { get; }
Property Value
RequestServices
Gets the service provider for the request scope.
IServiceProvider RequestServices { get; }
Property Value
StatusCode
Gets the status code of the response.
int StatusCode { get; set; }
Property Value
User
Gets or sets the user associated with the request.
ClaimsPrincipal User { get; set; }
Property Value
WebSockets
Gets the WebSocket context for this request.
IWebSocketContext WebSockets { get; }
Property Value
Methods
AppendCookie(string, string, CookieOptions)
Appends a cookie to the response.
void AppendCookie(string key, string value, CookieOptions options)
Parameters
keystringThe cookie name.
valuestringThe cookie value.
optionsCookieOptionsThe cookie options.
ReadBodyAsJson(Type, CancellationToken)
Reads the request body and deserializes it as JSON.
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.
void RemoveCookie(string key)
Parameters
keystringThe cookie name.
SetResponseHeader(string, string)
Sets a response header.
void SetResponseHeader(string name, string value)
Parameters
SetStatusCode(int)
Sets the HTTP response status code.
void SetStatusCode(int statusCode)
Parameters
statusCodeintThe status code to set.
Write(string, CancellationToken)
Writes text to the response.
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.
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.
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.
Task WriteStream(Stream stream, CancellationToken cancellationToken = default)
Parameters
streamStreamThe stream to write.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task
A task representing the async operation.