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>> { ... }
fn trace_id(&self) -> Option<&str> { ... }
fn set_trace_id(&mut self, _trace_id: &str) { ... }
}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§
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§
Sourcefn take_early_error(&mut self) -> Option<Error>
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.
Sourcefn dispatch_runtime(&self) -> Option<&Arc<DispatchRuntime>>
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.
Sourcefn trace_id(&self) -> Option<&str>
fn trace_id(&self) -> Option<&str>
The trace id assigned to this request, if any.
Set by the tracing middleware (webx_host::RequestTracing) before
the endpoint runs, so the binder, the handler and the response header
all agree on one value. Handlers read it through
RequestContext::trace_id,
which the endpoint adapter scopes from this value.
Returns None for alternative hosts that never assign a trace id and
for requests that did not pass the tracing middleware.
Sourcefn set_trace_id(&mut self, _trace_id: &str)
fn set_trace_id(&mut self, _trace_id: &str)
Record the trace id for this request.
Called by the tracing middleware’s invoke, which then echoes the same
value in the x-trace-id response header. The default is a no-op so
existing/alternative context implementations keep compiling; such hosts
simply have no trace id.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".