Struct cosworth::prelude::http::NormalizePath
source · pub struct NormalizePath { /* private fields */ }
Expand description
Path normalization helper
By normalizing it means:
- Add a trailing slash to the path.
- Remove a trailing slash from the path.
- Double slashes are replaced by one.
The handler returns as soon as it finds a path that resolves correctly. The order if all enable is 1) merge, 3) both merge and append and 3) append. If the path resolves with at least one of those conditions, it will redirect to the new path.
If append is true append slash when needed. If a resource is defined with trailing slash and the request comes without it, it will append it automatically.
If merge is true, merge multiple consecutive slashes in the path into one.
This handler designed to be use as a handler for application’s default resource.
use actix_web::http::NormalizePath;
fn main() {
let app = App::new()
.resource("/test/", |r| r.f(index))
.default_resource(|r| r.h(NormalizePath::default()))
.finish();
}
In this example /test
, /test///
will be redirected to /test/
url.
Implementations§
source§impl NormalizePath
impl NormalizePath
sourcepub fn new(append: bool, merge: bool, redirect: StatusCode) -> NormalizePath
pub fn new(append: bool, merge: bool, redirect: StatusCode) -> NormalizePath
Create new NormalizePath
instance
Trait Implementations§
source§impl Default for NormalizePath
impl Default for NormalizePath
source§fn default() -> NormalizePath
fn default() -> NormalizePath
Create default NormalizePath
instance, append is set to true,
merge is set to true and redirect is set to
StatusCode::MOVED_PERMANENTLY
source§impl<S> Handler<S> for NormalizePath
impl<S> Handler<S> for NormalizePath
§type Result = HttpResponse
type Result = HttpResponse
source§fn handle(&self, req: &HttpRequest<S>) -> <NormalizePath as Handler<S>>::Result
fn handle(&self, req: &HttpRequest<S>) -> <NormalizePath as Handler<S>>::Result
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§
source§impl<T> IntoSql for T
impl<T> IntoSql for T
source§fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
fn into_sql<T>(self) -> Self::Expressionwhere
Self: AsExpression<T> + Sized,
self
to an expression for Diesel’s query builder. Read moresource§fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expressionwhere
&'a Self: AsExpression<T>,
&self
to an expression for Diesel’s query builder. Read more