Struct warp::filters::cors::Builder

source ·
pub struct Builder {
    credentials: bool,
    allowed_headers: HashSet<HeaderName>,
    exposed_headers: HashSet<HeaderName>,
    max_age: Option<u64>,
    methods: HashSet<Method>,
    origins: Option<HashSet<HeaderValue>>,
}
Expand description

A constructed via warp::cors().

Fields§

§credentials: bool§allowed_headers: HashSet<HeaderName>§exposed_headers: HashSet<HeaderName>§max_age: Option<u64>§methods: HashSet<Method>§origins: Option<HashSet<HeaderValue>>

Implementations§

source§

impl Builder

source

pub fn allow_credentials(self, allow: bool) -> Self

Sets whether to add the Access-Control-Allow-Credentials header.

source

pub fn allow_method<M>(self, method: M) -> Self
where Method: TryFrom<M>,

Adds a method to the existing list of allowed request methods.

§Panics

Panics if the provided argument is not a valid http::Method.

source

pub fn allow_methods<I>(self, methods: I) -> Self

Adds multiple methods to the existing list of allowed request methods.

§Panics

Panics if the provided argument is not a valid http::Method.

source

pub fn allow_header<H>(self, header: H) -> Self
where HeaderName: TryFrom<H>,

Adds a header to the list of allowed request headers.

Note: These should match the values the browser sends via Access-Control-Request-Headers, e.g. content-type.

§Panics

Panics if the provided argument is not a valid http::header::HeaderName.

source

pub fn allow_headers<I>(self, headers: I) -> Self

Adds multiple headers to the list of allowed request headers.

Note: These should match the values the browser sends via Access-Control-Request-Headers, e.g.content-type.

§Panics

Panics if any of the headers are not a valid http::header::HeaderName.

source

pub fn expose_header<H>(self, header: H) -> Self
where HeaderName: TryFrom<H>,

Adds a header to the list of exposed headers.

§Panics

Panics if the provided argument is not a valid http::header::HeaderName.

source

pub fn expose_headers<I>(self, headers: I) -> Self

Adds multiple headers to the list of exposed headers.

§Panics

Panics if any of the headers are not a valid http::header::HeaderName.

source

pub fn allow_any_origin(self) -> Self

Sets that any Origin header is allowed.

§Warning

This can allow websites you didn’t intend to access this resource, it is usually better to set an explicit list.

source

pub fn allow_origin(self, origin: impl IntoOrigin) -> Self

Add an origin to the existing list of allowed Origins.

§Panics

Panics if the provided argument is not a valid Origin.

source

pub fn allow_origins<I>(self, origins: I) -> Self

Add multiple origins to the existing list of allowed Origins.

§Panics

Panics if the provided argument is not a valid Origin.

source

pub fn max_age(self, seconds: impl Seconds) -> Self

Sets the Access-Control-Max-Age header.

§Example
use std::time::Duration;
use warp::Filter;

let cors = warp::cors()
    .max_age(30) // 30u32 seconds
    .max_age(Duration::from_secs(30)); // or a Duration
source

pub fn build(self) -> Cors

Builds the Cors wrapper from the configured settings.

This step isn’t required, as the Builder itself can be passed to Filter::with. This just allows constructing once, thus not needing to pay the cost of “building” every time.

Trait Implementations§

source§

impl Clone for Builder

source§

fn clone(&self) -> Builder

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 Builder

source§

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

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

impl<F> WrapSealed<F> for Builder

§

type Wrapped = CorsFilter<F>

source§

fn wrap(&self, inner: F) -> Self::Wrapped

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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.
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, F> Wrap<F> for T
where T: WrapSealed<F>, F: Filter,