Module normalize_path
Expand description
Middleware that normalizes paths.
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 std::{iter::once, convert::Infallible};
use rama_core::error::BoxError;
use rama_core::service::service_fn;
use rama_core::{Context, Layer, Service};
use rama_http::{Body, Request, Response, StatusCode};
use rama_http::layer::normalize_path::NormalizePathLayer;
async fn handle(req: Request) -> Result<Response, Infallible> {
// `req.uri().path()` will not have trailing slashes
}
let mut service = (
// trim trailing slashes from paths
NormalizePathLayer::trim_trailing_slash(),
).layer(service_fn(handle));
// call the service
let request = Request::builder()
// `handle` will see `/foo`
.uri("/foo/")
.body(Body::default())?;
service.serve(Context::default(), request).await?;
Structs§
- Middleware that normalizes paths.
- Layer that applies
NormalizePath
which normalizes paths.