Crate tower_http
async fn(HttpRequest) -> Result<HttpResponse, Error>
Overview
tower-http is a library that provides HTTP-specific middleware and utilities built on top of tower.
All middleware uses the http and http-body crates as the HTTP abstractions. That means they're compatible with any library or framework that also uses those crates, such as hyper, tonic, and warp.
Example server
This example shows how to apply middleware from tower-http to a Service and then run
that service using hyper and hyper-util.
use ;
use ;
use ;
use ;
use Bytes;
use Full;
use ;
use TowerToHyperService;
# async
async
Keep in mind that while this example uses hyper, tower-http supports any HTTP client/server implementation that uses the http and http-body crates.
Example client
tower-http middleware can also be applied to HTTP clients:
use ;
use ;
use ;
use Full;
use Bytes;
use ;
async
Feature Flags
All middleware are disabled by default and can be enabled using cargo features.
For example, to enable the Trace middleware, add the "trace" feature flag in
your Cargo.toml:
tower-http = { version = "0.1", features = ["trace"] }
You can use "full" to enable everything:
tower-http = { version = "0.1", features = ["full"] }
Getting Help
If you're new to tower its guides might help. In the tower-http repo we also have a number
of examples showing how to put everything together. You're also welcome to ask in
the #tower Discord channel or open an issue with your question.
Modules
- classify Tools for classifying responses as either success or failure.
- follow_redirect Middleware for following redirections.
-
services
Services that return responses without wrapping otherServices.
Enums
- LatencyUnit The latency unit used to report latencies by middleware.
Type Aliases
- BoxError Alias for a type-erased error type.