pub struct RedirectToWww { /* private fields */ }Expand description
Middleware to redirect traffic to www. if not already there.
§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 RedirectToWww::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::RedirectToWww;
let mw = RedirectToWww::default();
let mw = RedirectToWww::default().allow_hosts(["example.com", "www.example.com"]);
App::new().wrap(mw)Implementations§
Source§impl RedirectToWww
impl RedirectToWww
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 RedirectToWww
impl Clone for RedirectToWww
Source§fn clone(&self) -> RedirectToWww
fn clone(&self) -> RedirectToWww
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 RedirectToWww
impl Debug for RedirectToWww
Source§impl Default for RedirectToWww
impl Default for RedirectToWww
Source§fn default() -> RedirectToWww
fn default() -> RedirectToWww
Returns the “default value” for a type. Read more
Source§impl<S, B> Transform<S, ServiceRequest> for RedirectToWww
impl<S, B> Transform<S, ServiceRequest> for RedirectToWww
Source§type Response = ServiceResponse<EitherBody<B, ()>>
type Response = ServiceResponse<EitherBody<B, ()>>
Responses produced by the service.
Source§type Transform = RedirectToWwwMiddleware<S>
type Transform = RedirectToWwwMiddleware<S>
The
TransformService value created by this factorySource§type Future = Ready<Result<<RedirectToWww as Transform<S, ServiceRequest>>::Transform, <RedirectToWww as Transform<S, ServiceRequest>>::InitError>>
type Future = Ready<Result<<RedirectToWww as Transform<S, ServiceRequest>>::Transform, <RedirectToWww 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 RedirectToWww
impl RefUnwindSafe for RedirectToWww
impl Send for RedirectToWww
impl Sync for RedirectToWww
impl Unpin for RedirectToWww
impl UnsafeUnpin for RedirectToWww
impl UnwindSafe for RedirectToWww
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