pub struct MiddlewareContext {
pub request_start: Instant,
pub status_code: u16,
pub body_size: usize,
pub sendfile: SendfileState,
pub compression: CompressionState,
pub static_response: Option<StaticResponse>,
pub concurrency_permit: Option<OwnedSemaphorePermit>,
pub streaming: bool,
pub trusted_source: bool,
pub real_client_ip: IpAddr,
}Expand description
Context for middleware execution
Stores state needed across middleware chain execution, including request start time, response metadata, and flags.
Fields§
§request_start: InstantRequest start timestamp (for logging)
status_code: u16Response status code (captured by logging middleware)
body_size: usizeResponse body size (captured by logging middleware)
sendfile: SendfileStateSendfile state (set by sendfile middleware)
compression: CompressionStateCompression state (set by compression middleware)
static_response: Option<StaticResponse>Static response (set by static files middleware to short-circuit proxy)
concurrency_permit: Option<OwnedSemaphorePermit>Concurrency permit (held for request duration, auto-released on drop)
streaming: boolStreaming flag (set when SSE or other streaming content is detected)
When true, disables response buffering to allow real-time streaming. Automatically set when:
- Content-Type: text/event-stream (Server-Sent Events)
- X-Accel-Buffering: no (nginx compatibility)
trusted_source: boolTrusted source flag (set by trusted_ranges middleware)
When true, indicates request comes from a trusted proxy/CDN IP range. Used to bypass rate limiting and concurrency limits.
real_client_ip: IpAddrReal client IP (normalized by trusted_ranges middleware)
Contains the actual client IP extracted from proxy headers (if trusted) or the socket IP (if not from trusted source). Used for:
- Rate limiting (to rate limit real clients, not proxies)
- Logging (to log actual client IPs)
- X-Forwarded-For headers (to maintain proxy chain)