Struct tower_http::cors::Cors

source ·
pub struct Cors<S> { /* private fields */ }
Expand description

Middleware which adds headers for CORS.

See the module docs for an example.

Implementations§

source§

impl<S> Cors<S>

source

pub fn new(inner: S) -> Self

Create a new Cors.

See CorsLayer::new for more details.

source

pub fn permissive(inner: S) -> Self

A permissive configuration.

See CorsLayer::permissive for more details.

source

pub fn very_permissive(inner: S) -> Self

A very permissive configuration.

See CorsLayer::very_permissive for more details.

source

pub fn get_ref(&self) -> &S

Gets a reference to the underlying service.

source

pub fn get_mut(&mut self) -> &mut S

Gets a mutable reference to the underlying service.

source

pub fn into_inner(self) -> S

Consumes self, returning the underlying service.

source

pub fn layer() -> CorsLayer

Returns a new Layer that wraps services with a Cors middleware.

source

pub fn allow_credentials<T>(self, allow_credentials: T) -> Selfwhere T: Into<AllowCredentials>,

Set the Access-Control-Allow-Credentials header.

See CorsLayer::allow_credentials for more details.

source

pub fn allow_headers<T>(self, headers: T) -> Selfwhere T: Into<AllowHeaders>,

Set the value of the Access-Control-Allow-Headers header.

See CorsLayer::allow_headers for more details.

source

pub fn max_age<T>(self, max_age: T) -> Selfwhere T: Into<MaxAge>,

Set the value of the Access-Control-Max-Age header.

See CorsLayer::max_age for more details.

source

pub fn allow_methods<T>(self, methods: T) -> Selfwhere T: Into<AllowMethods>,

Set the value of the Access-Control-Allow-Methods header.

See CorsLayer::allow_methods for more details.

source

pub fn allow_origin<T>(self, origin: T) -> Selfwhere T: Into<AllowOrigin>,

Set the value of the Access-Control-Allow-Origin header.

See CorsLayer::allow_origin for more details.

source

pub fn expose_headers<T>(self, headers: T) -> Selfwhere T: Into<ExposeHeaders>,

Set the value of the Access-Control-Expose-Headers header.

See CorsLayer::expose_headers for more details.

Trait Implementations§

source§

impl<S: Clone> Clone for Cors<S>

source§

fn clone(&self) -> Cors<S>

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<S: Debug> Debug for Cors<S>

source§

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

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

impl<S, ReqBody, ResBody> Service<Request<ReqBody>> for Cors<S>where S: Service<Request<ReqBody>, Response = Response<ResBody>>, ResBody: Default,

§

type Response = <S as Service<Request<ReqBody>>>::Response

Responses given by the service.
§

type Error = <S as Service<Request<ReqBody>>>::Error

Errors produced by the service.
§

type Future = ResponseFuture<<S as Service<Request<ReqBody>>>::Future>

The future response value.
source§

fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>

Returns Poll::Ready(Ok(())) when the service is able to process requests. Read more
source§

fn call(&mut self, req: Request<ReqBody>) -> Self::Future

Process the request and return the response asynchronously. Read more

Auto Trait Implementations§

§

impl<S> !RefUnwindSafe for Cors<S>

§

impl<S> Send for Cors<S>where S: Send,

§

impl<S> Sync for Cors<S>where S: Sync,

§

impl<S> Unpin for Cors<S>where S: Unpin,

§

impl<S> !UnwindSafe for Cors<S>

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