Struct RedirectScheme

Source
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

Source

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!")));
Source

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

Source§

fn clone(&self) -> RedirectScheme

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for RedirectScheme

Source§

fn default() -> RedirectScheme

Returns the “default value” for a type. Read more
Source§

impl<S, B> Transform<S> for RedirectScheme
where S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>, S::Future: 'static,

Source§

type Request = ServiceRequest

Requests handled by the service.
Source§

type Response = ServiceResponse<B>

Responses given by the service.
Source§

type Error = Error

Errors produced by the service.
Source§

type InitError = ()

Errors produced while building a transform service.
Source§

type Transform = RedirectSchemeService<S>

The TransformService value created by this factory
Source§

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

Creates and returns a new Transform component, asynchronously
Source§

fn map_init_err<F, E>(self, f: F) -> TransformMapInitErr<Self, S, F, E>
where Self: Sized, F: Fn(Self::InitError) -> E + Clone,

Map this transforms’s factory error to a different error, returning a new transform service factory.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,