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},
test::TestClient,
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 cli = TestClient::new(app);
let resp = cli.get("/foo/bar/").send().await;
resp.assert_status_is_ok();
resp.assert_text("hello").await;
Implementations
sourceimpl NormalizePath
impl NormalizePath
sourcepub fn new(style: TrailingSlash) -> Self
pub fn new(style: TrailingSlash) -> Self
Create new NormalizePath
middleware with the specified trailing slash
style.
Trait Implementations
sourceimpl<E: Endpoint> Middleware<E> for NormalizePath
impl<E: Endpoint> Middleware<E> for NormalizePath
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
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more