logo
pub struct CorsBuilder { /* private fields */ }
Expand description

A constructed via salvo_cors::Cors::builder().

Implementations

Create new CorsBuilder.

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.

Sets the Access-Control-Max-Age header.

Example
use std::time::Duration;
use salvo_core::prelude::*;;

let cors = salvo_cors::Cors::builder()
    .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 CorsBuilder 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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. 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

Returns the argument unchanged.

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

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more