Skip to main content

Module drain_request_body

Module drain_request_body 

Available on crate features http and std only.
Expand description

Explicitly finish an upload before invoking a service that ignores its body.

Frames are discarded as they arrive, without collecting the upload. The inner service receives the original request parts and an empty body. This is an application policy for all HTTP versions, not required H2/H3 cleanup. It also avoids early upload cancellation for clients that discard a response when their upload is stopped early.

Install only on routes whose handlers do not need the body. Original headers (including Content-Length) remain available as request metadata; do not use this layer in front of a forwarding service or a streaming/tunnel handler.

By default this layer adds no byte limit or timeout. Optional CollectOptions impose additional bounds. Place the normal request-body limit outside it, and compose with a request deadline. Reading the already-limited body enforces that limit, including for chunked uploads. Body errors prevent invocation of the inner service: size-limit errors return 413, timeout errors return 408, and other body errors return 400, without exposing error details. Polling an H1 body may send 100 Continue; this layer intentionally accepts the upload. Apply it only to ordinary HTTP routes, never CONNECT/tunnels.

Structs§

DrainRequestBody
Service produced by DrainRequestBodyLayer.
DrainRequestBodyLayer
Discard the complete request body before invoking the inner service.