[go: up one dir, main page]

Struct warp::filters::cors::Builder

source ·
pub struct Builder { /* private fields */ }
Expand description

A constructed via warp::cors().

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) -> Selfwhere 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) -> Selfwhere I: IntoIterator, Method: TryFrom<I::Item>,

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) -> Selfwhere 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) -> Selfwhere I: IntoIterator, HeaderName: TryFrom<I::Item>,

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) -> Selfwhere 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) -> Selfwhere I: IntoIterator, HeaderName: TryFrom<I::Item>,

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) -> Selfwhere I: IntoIterator, I::Item: IntoOrigin,

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

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

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