Struct poem::middleware::NormalizePath
source[−]pub struct NormalizePath(_);
Expand description
Middleware for normalizing a request’s path so that routes can be matched more flexibly.
Example
use poem::{
get, handler,
http::{StatusCode, Uri},
middleware::{NormalizePath, TrailingSlash},
Endpoint, EndpointExt, Request, Route,
};
#[handler]
fn index() -> &'static str {
"hello"
}
let app = Route::new()
.at("/foo/bar", get(index))
.with(NormalizePath::new(TrailingSlash::Trim));
let resp = app
.call(
Request::builder()
.uri(Uri::from_static("/foo/bar/"))
.finish(),
)
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(resp.into_body().into_string().await.unwrap(), "hello");
Implementations
Create new NormalizePath
middleware with the specified trailing slash
style.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for NormalizePath
impl Send for NormalizePath
impl Sync for NormalizePath
impl Unpin for NormalizePath
impl UnwindSafe for NormalizePath
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more