Expand description
Middleware that normalizes paths, with exceptions.
Forked with minimal changes from tower_http::NormalizePathLayer.
Any trailing slashes from request paths will be removed. For example, a request with /foo/
will be changed to /foo
before reaching the inner service.
§Example
use normalize_path_except::NormalizePathLayer;
use http::{Request, Response, StatusCode};
use http_body_util::Full;
use bytes::Bytes;
use std::{iter::once, convert::Infallible};
use tower::{ServiceBuilder, Service, ServiceExt};
async fn handle(req: Request<Full<Bytes>>) -> Result<Response<Full<Bytes>>, Infallible> {
// `req.uri().path()` will not have trailing slashes
}
let mut service = ServiceBuilder::new()
// trim trailing slashes from paths except `exceptions`
.layer(NormalizePathLayer::trim_trailing_slash(&["/swagger-ui"]))
.service_fn(handle);
// call the service
let request = Request::builder()
// `handle` will see `/foo`
.uri("/foo/")
.body(Full::default())?;
service.ready().await?.call(request).await?;
Structs§
- Normalize
Path - Middleware that normalizes paths.
- Normalize
Path Layer - Layer that applies
NormalizePath
which normalizes paths.