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

string

Cookies

Gets the request cookies.

IReadOnlyDictionary<string, string> Cookies { get; }

Property Value

IReadOnlyDictionary<string, string>

Headers

Gets the request headers.

IReadOnlyDictionary<string, string> Headers { get; }

Property Value

IReadOnlyDictionary<string, string>

Host

Gets the request host (without port).

string Host { get; }

Property Value

string

IsHttps

Gets a value indicating whether the request is HTTPS.

bool IsHttps { get; }

Property Value

bool

Items

Gets a dictionary for storing arbitrary data during the request lifecycle.

IDictionary<object, object?> Items { get; }

Property Value

IDictionary<object, object>

Method

Gets the HTTP method (GET, POST, etc.).

string Method { get; }

Property Value

string

Path

Gets the request path.

string Path { get; }

Property Value

string

Query

Gets the query string parameters.

IReadOnlyDictionary<string, string> Query { get; }

Property Value

IReadOnlyDictionary<string, string>

RequestAborted

Gets the cancellation token for the request.

CancellationToken RequestAborted { get; }

Property Value

CancellationToken

RequestServices

Gets the service provider for the request scope.

IServiceProvider RequestServices { get; }

Property Value

IServiceProvider

StatusCode

Gets the status code of the response.

int StatusCode { get; set; }

Property Value

int

User

Gets or sets the user associated with the request.

ClaimsPrincipal User { get; set; }

Property Value

ClaimsPrincipal

WebSockets

Gets the WebSocket context for this request.

IWebSocketContext WebSockets { get; }

Property Value

IWebSocketContext

Methods

AppendCookie(string, string, CookieOptions)

Appends a cookie to the response.

void AppendCookie(string key, string value, CookieOptions options)

Parameters

key string

The cookie name.

value string

The cookie value.

options CookieOptions

The cookie options.

ReadBodyAsJson(Type, CancellationToken)

Reads the request body and deserializes it as JSON.

Task<object?> ReadBodyAsJson(Type type, CancellationToken cancellationToken = default)

Parameters

type Type

The type to deserialize to.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<object>

The deserialized object.

RemoveCookie(string)

Removes a cookie from the response.

void RemoveCookie(string key)

Parameters

key string

The cookie name.

SetResponseHeader(string, string)

Sets a response header.

void SetResponseHeader(string name, string value)

Parameters

name string

Header name.

value string

Header value.

SetStatusCode(int)

Sets the HTTP response status code.

void SetStatusCode(int statusCode)

Parameters

statusCode int

The status code to set.

Write(string, CancellationToken)

Writes text to the response.

Task Write(string text, CancellationToken cancellationToken = default)

Parameters

text string

The text to write.

cancellationToken CancellationToken

Cancellation 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

data byte[]

The byte data to write.

cancellationToken CancellationToken

Cancellation 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

value object

The value to serialize.

type Type

The type of the value.

cancellationToken CancellationToken

Cancellation 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

stream Stream

The stream to write.

cancellationToken CancellationToken

Cancellation token.

Returns

Task

A task representing the async operation.