pub struct CorsMiddleware { /* private fields */ }
Expand description

Middleware for CORS

Example

use http_types::headers::HeaderValue;
use tide::security::{CorsMiddleware, Origin};

let cors = CorsMiddleware::new()
    .allow_methods("GET, POST, OPTIONS".parse::<HeaderValue>().unwrap())
    .allow_origin(Origin::from("*"))
    .allow_credentials(false);

Implementations§

source§

impl CorsMiddleware

source

pub fn new() -> CorsMiddleware

Creates a new Cors middleware.

source

pub fn allow_credentials(self, allow_credentials: bool) -> CorsMiddleware

Set allow_credentials and return new Cors

source

pub fn allow_headers<T>(self, headers: T) -> CorsMiddlewarewhere T: Into<HeaderValue>,

Set allow_headers and return new Cors

source

pub fn max_age<T>(self, max_age: T) -> CorsMiddlewarewhere T: Into<HeaderValue>,

Set max_age and return new Cors

source

pub fn allow_methods<T>(self, methods: T) -> CorsMiddlewarewhere T: Into<HeaderValue>,

Set allow_methods and return new Cors

source

pub fn allow_origin<T>(self, origin: T) -> CorsMiddlewarewhere T: Into<Origin>,

Set allow_origin and return new Cors

source

pub fn expose_headers<T>(self, headers: T) -> CorsMiddlewarewhere T: Into<HeaderValue>,

Set expose_headers and return new Cors

Trait Implementations§

source§

impl Clone for CorsMiddleware

source§

fn clone(&self) -> CorsMiddleware

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 Debug for CorsMiddleware

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl Default for CorsMiddleware

source§

fn default() -> CorsMiddleware

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

impl Hash for CorsMiddleware

source§

fn hash<__H>(&self, state: &mut __H)where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<State> Middleware<State> for CorsMiddlewarewhere State: Clone + Send + Sync + 'static,

source§

fn handle<'life0, 'life1, 'async_trait>( &'life0 self, req: Request<State>, next: Next<'life1, State> ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'async_trait, Global>>where 'life0: 'async_trait, 'life1: 'async_trait, CorsMiddleware: 'async_trait,

Asynchronously handle the request, and return a response.
source§

fn name(&self) -> &str

Set the middleware’s name. By default it uses the type signature.

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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

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

§

fn vzip(self) -> V