pub struct RedirectScheme {
pub disable: bool,
pub https_to_http: bool,
pub temporary: bool,
pub replacements: Vec<(String, String)>,
}
Expand description
Middleware for actix-web
which redirects between http
and https
requests with optional url
string replacements.
§Usage
extern crate actix_web_middleware_redirect_scheme;
use actix_web::{App, web, HttpResponse};
use actix_web_middleware_redirect_scheme::RedirectSchemeBuilder;
App::new()
.wrap(RedirectSchemeBuilder::new().temporary().build())
.route("/", web::get().to(|| HttpResponse::Ok()
.content_type("text/plain")
.body("Always HTTPS!")));
Fields§
§disable: bool
§https_to_http: bool
§temporary: bool
§replacements: Vec<(String, String)>
Implementations§
Source§impl RedirectScheme
impl RedirectScheme
Sourcepub fn simple(https_to_http: bool) -> Self
pub fn simple(https_to_http: bool) -> Self
Creates a RedirectScheme middleware.
§Usage
extern crate actix_web_middleware_redirect_scheme;
use actix_web::{App, web, HttpResponse};
use actix_web_middleware_redirect_scheme::RedirectScheme;
App::new()
.wrap(RedirectScheme::simple(false))
.route("/", web::get().to(|| HttpResponse::Ok()
.content_type("text/plain")
.body("Always HTTPS on non-default ports!")));
Sourcepub fn with_replacements<S: ToString>(
https_to_http: bool,
replacements: &[(S, S)],
) -> Self
pub fn with_replacements<S: ToString>( https_to_http: bool, replacements: &[(S, S)], ) -> Self
Creates a RedirectScheme middleware which also performs string replacement on the final url. This is useful when not running on the default web and ssl ports (80 and 443) since we will need to change the development web port in the hostname to the development ssl port.
§Usage
extern crate actix_web_middleware_redirect_scheme;
use actix_web::{App, web, HttpResponse};
use actix_web_middleware_redirect_scheme::RedirectScheme;
App::new()
.wrap(RedirectScheme::with_replacements(false, &[(":8080", ":8443")]))
.route("/", web::get().to(|| HttpResponse::Ok()
.content_type("text/plain")
.body("Always HTTPS on non-default ports!")));
Trait Implementations§
Source§impl Clone for RedirectScheme
impl Clone for RedirectScheme
Source§fn clone(&self) -> RedirectScheme
fn clone(&self) -> RedirectScheme
Returns a copy 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 Default for RedirectScheme
impl Default for RedirectScheme
Source§fn default() -> RedirectScheme
fn default() -> RedirectScheme
Returns the “default value” for a type. Read more
Source§impl<S, B> Transform<S> for RedirectSchemewhere
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
impl<S, B> Transform<S> for RedirectSchemewhere
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
Source§type Request = ServiceRequest
type Request = ServiceRequest
Requests handled by the service.
Source§type Response = ServiceResponse<B>
type Response = ServiceResponse<B>
Responses given by the service.
Source§type Transform = RedirectSchemeService<S>
type Transform = RedirectSchemeService<S>
The
TransformService
value created by this factorySource§type Future = Ready<Result<<RedirectScheme as Transform<S>>::Transform, <RedirectScheme as Transform<S>>::InitError>>
type Future = Ready<Result<<RedirectScheme as Transform<S>>::Transform, <RedirectScheme as Transform<S>>::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
Source§fn map_init_err<F, E>(self, f: F) -> TransformMapInitErr<Self, S, F, E>
fn map_init_err<F, E>(self, f: F) -> TransformMapInitErr<Self, S, F, E>
Map this transforms’s factory error to a different error,
returning a new transform service factory.
Auto Trait Implementations§
impl Freeze for RedirectScheme
impl RefUnwindSafe for RedirectScheme
impl Send for RedirectScheme
impl Sync for RedirectScheme
impl Unpin for RedirectScheme
impl UnwindSafe for RedirectScheme
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> 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