Skip to main content

IHttpContext

Trait IHttpContext 

Source
pub trait IHttpContext: IClaimsExt + Send {
    // Required methods
    fn request(&self) -> &dyn IHttpRequest;
    fn request_mut(&mut self) -> &mut dyn IHttpRequest;
    fn response(&self) -> &dyn IHttpResponse;
    fn response_mut(&mut self) -> &mut dyn IHttpResponse;

    // Provided methods
    fn take_early_error(&mut self) -> Option<Error> { ... }
    fn dispatch_runtime(&self) -> Option<&Arc<DispatchRuntime>> { ... }
}
Expand description

HTTP context encapsulating the request, response, and service provider for the duration of a single HTTP request.

Extends IClaimsExt so middleware can store/retrieve auth claims.

Analogous to ASP.NET Core’s HttpContext.

Required Methods§

Source

fn request(&self) -> &dyn IHttpRequest

Source

fn request_mut(&mut self) -> &mut dyn IHttpRequest

Source

fn response(&self) -> &dyn IHttpResponse

Source

fn response_mut(&mut self) -> &mut dyn IHttpResponse

Provided Methods§

Source

fn take_early_error(&mut self) -> Option<Error>

Take a request rejection recorded while the context was built.

The host records failures it can detect from the request line alone — currently an oversized declared Content-Length — instead of writing a response eagerly. The request then still travels through the middleware pipeline (CORS, security headers, access log, metrics, rate limiting) and the innermost handler turns the value into the normal error response. A context without such a record returns None.

Source

fn dispatch_runtime(&self) -> Option<&Arc<DispatchRuntime>>

DI handles of the host that dispatched this request.

Endpoint adapters use this to build the Mediator over the host’s service provider and handler registry. Contexts created by tests or alternative hosts return None; dispatching an endpoint through such a context is a programming error and is reported as Error::Internal.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§