Skip to main content

HttpMiddleware

Trait HttpMiddleware 

Source
pub trait HttpMiddleware {
    // Provided methods
    fn on_request(
        &self,
        _context: &mut HttpRequestContext<'_>,
    ) -> Option<Response> { ... }
    fn on_operation(
        &self,
        _context: &mut HttpRequestContext<'_>,
        _operation: &OperationDescriptor,
        _security_schemes: &[SecuritySchemeDescriptor],
    ) -> Option<Response> { ... }
    fn on_response(
        &self,
        _context: &HttpRequestContext<'_>,
        _operation: Option<&OperationDescriptor>,
        _response: &mut Response,
    ) { ... }
    fn verifies_security(&self) -> bool { ... }
}
Expand description

Synchronous middleware interception points shared by every HTTP adapter.

Middleware is deliberately runtime-neutral: cryptographic verification, header policy, compression, and rate limiting do not require Tokio or any other async runtime.

Provided Methods§

Source

fn on_request(&self, _context: &mut HttpRequestContext<'_>) -> Option<Response>

Runs before routing. Returning a response short-circuits dispatch.

Source

fn on_operation( &self, _context: &mut HttpRequestContext<'_>, _operation: &OperationDescriptor, _security_schemes: &[SecuritySchemeDescriptor], ) -> Option<Response>

Runs after routing and before body parsing/handler invocation.

Source

fn on_response( &self, _context: &HttpRequestContext<'_>, _operation: Option<&OperationDescriptor>, _response: &mut Response, )

Runs in reverse registration order for normal and short-circuit responses.

Source

fn verifies_security(&self) -> bool

Returns whether this layer can verify contract security requirements.

Dispatch fails closed when an operation declares a security scheme and no registered layer can verify it. The default is true so an unknown layer is assumed capable and never turns the guard into a false 500; layers that never authenticate should return false so a dispatch path without a verifier is detected.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§