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

A constructed via warp::cors().

Implementations

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

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

Panics

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

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

Panics

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

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.

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.

Adds a header to the list of exposed headers.

Panics

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

Adds multiple headers to the list of exposed headers.

Panics

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

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.

Add an origin to the existing list of allowed Origins.

Panics

Panics if the provided argument is not a valid Origin.

Add multiple origins to the existing list of allowed Origins.

Panics

Panics if the provided argument is not a valid Origin.

Examples found in repository?
src/filters/cors.rs (line 208)
207
208
209
    pub fn allow_origin(self, origin: impl IntoOrigin) -> Self {
        self.allow_origins(Some(origin))
    }

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

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.

Examples found in repository?
src/filters/cors.rs (line 289)
288
289
290
291
292
    fn wrap(&self, inner: F) -> Self::Wrapped {
        let Cors { config } = self.clone().build();

        CorsFilter { config, inner }
    }

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.