Skip to main content

Module timeout

Module timeout 

Source
Expand description

Generic per-request timeout.

Unlike plain tower::timeout, tower_http’s TimeoutLayer never fails the inner service — on elapse it directly returns a response with a caller-chosen status code, so it composes onto an Axum Router with no error-handling layer required. tower_http itself has no built-in default status code (its zero-arg constructor is deprecated in favor of with_status_code); timeout_layer below is this crate’s own choice to default that code to 408 Request Timeout.

Structs§

TimeoutLayer
Layer that applies the [Timeout] middleware which apply a timeout to requests.

Functions§

timeout_layer
Build a layer that returns 408 Request Timeout (this crate’s chosen default — see the module docs) for any request taking longer than duration.
timeout_layer_with_status
Build a layer that returns status_code for any request taking longer than duration.