Skip to main content

Cors

Struct Cors 

Source
pub struct Cors { /* private fields */ }
Expand description

CORS middleware, see the module documentation

Implementations§

Source§

impl Cors

Source

pub fn new() -> Self

No origin allowed yet; add some with allow_origin, allow_origins, allow_origin_fn or allow_any_origin

Source

pub fn allow_origin(self, origin: impl Into<String>) -> Self

Allow one origin, written exactly as browsers send it (https://app.example.com, no trailing slash)

Source

pub fn allow_origins<I, S>(self, origins: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Source

pub fn allow_any_origin(self) -> Self

Allow every origin (Access-Control-Allow-Origin: *). Credentials are never allowed in this mode.

Source

pub fn allow_origin_fn<F>(self, f: F) -> Self
where F: Fn(&str) -> bool + Send + Sync + 'static,

Decide per origin, e.g. all subdomains of your own domain

Source

pub fn allow_methods<I>(self, methods: I) -> Self
where I: IntoIterator<Item = Method>,

Methods a cross-origin page may use (default: GET, HEAD, POST, PUT, PATCH, DELETE)

Source

pub fn allow_headers<I, S>(self, headers: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Request headers a cross-origin page may send. Without this call the headers named in the preflight are allowed.

Source

pub fn expose_headers<I, S>(self, headers: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Response headers a cross-origin page may read besides the safelisted ones

Source

pub fn allow_credentials(self) -> Self

Let the page send cookies and Authorization (Access-Control-Allow-Credentials). Ignored together with allow_any_origin.

Source

pub fn max_age(self, max_age: Duration) -> Self

How long browsers may cache a preflight answer (default 10 minutes)

Source

pub fn allow_private_network(self) -> Self

Answer Private Network Access preflights, which public pages send before reaching into a private network (Access-Control-Allow-Private-Network)

Trait Implementations§

Source§

impl Default for Cors

Source§

fn default() -> Self

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

impl Middleware for Cors

Source§

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for Cors

§

impl !UnwindSafe for Cors

§

impl Freeze for Cors

§

impl Send for Cors

§

impl Sync for Cors

§

impl Unpin for Cors

§

impl UnsafeUnpin for Cors

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> 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, 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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