pub struct RedirectToNonWww { /* private fields */ }Expand description
Middleware to redirect traffic away from www. if it’s present.
§Security
This middleware constructs absolute redirect URLs from request-derived connection information.
If your deployment accepts unvalidated Host or forwarding headers, an attacker can influence
the redirect target.
To harden this middleware, configure RedirectToNonWww::allow_hosts. Requests with
non-allowlisted hosts receive a 400 Bad Request response instead of a redirect. Without an
allowlist, you should validate hosts upstream before requests reach the application.
§Examples
use actix_web_lab::middleware::RedirectToNonWww;
let mw = RedirectToNonWww::default();
let mw = RedirectToNonWww::default().allow_hosts(["example.com", "www.example.com"]);
App::new().wrap(mw)Implementations§
Source§impl RedirectToNonWww
impl RedirectToNonWww
Sourcepub fn allow_hosts<I, S>(self, hosts: I) -> Self
pub fn allow_hosts<I, S>(self, hosts: I) -> Self
Restricts redirect behavior to requests whose host matches an allowlist entry.
Requests with non-allowlisted hosts receive a 400 Bad Request response instead of a
redirect.
Trait Implementations§
Source§impl Clone for RedirectToNonWww
impl Clone for RedirectToNonWww
Source§fn clone(&self) -> RedirectToNonWww
fn clone(&self) -> RedirectToNonWww
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RedirectToNonWww
impl Debug for RedirectToNonWww
Source§impl Default for RedirectToNonWww
impl Default for RedirectToNonWww
Source§fn default() -> RedirectToNonWww
fn default() -> RedirectToNonWww
Returns the “default value” for a type. Read more
Source§impl<S, B> Transform<S, ServiceRequest> for RedirectToNonWww
impl<S, B> Transform<S, ServiceRequest> for RedirectToNonWww
Source§type Response = ServiceResponse<EitherBody<B, ()>>
type Response = ServiceResponse<EitherBody<B, ()>>
Responses produced by the service.
Source§type Transform = RedirectToNonWwwMiddleware<S>
type Transform = RedirectToNonWwwMiddleware<S>
The
TransformService value created by this factorySource§type Future = Ready<Result<<RedirectToNonWww as Transform<S, ServiceRequest>>::Transform, <RedirectToNonWww as Transform<S, ServiceRequest>>::InitError>>
type Future = Ready<Result<<RedirectToNonWww as Transform<S, ServiceRequest>>::Transform, <RedirectToNonWww as Transform<S, ServiceRequest>>::InitError>>
The future response value.
Source§fn new_transform(&self, service: S) -> Self::Future
fn new_transform(&self, service: S) -> Self::Future
Creates and returns a new Transform component, asynchronously
Auto Trait Implementations§
impl Freeze for RedirectToNonWww
impl RefUnwindSafe for RedirectToNonWww
impl Send for RedirectToNonWww
impl Sync for RedirectToNonWww
impl Unpin for RedirectToNonWww
impl UnsafeUnpin for RedirectToNonWww
impl UnwindSafe for RedirectToNonWww
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more