Struct salvo_extra::cors::HandlerBuilder [−][src]
pub struct HandlerBuilder { /* fields omitted */ }
Expand description
A constructed via salvo_extra::cors::CorsHandler::builder()
.
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
.
pub fn with_allow_methods<I>(self, methods: I) -> Self where
I: IntoIterator,
Method: TryFrom<I::Item>,
pub fn with_allow_methods<I>(self, methods: I) -> Self where
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
.
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
.
pub fn with_allow_headers<I>(self, headers: I) -> Self where
I: IntoIterator,
HeaderName: TryFrom<I::Item>,
pub fn with_allow_headers<I>(self, headers: I) -> Self where
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
.
Adds a header to the list of exposed headers.
Panics
Panics if the provided argument is not a valid http::header::HeaderName
.
pub fn with_expose_headers<I>(self, headers: I) -> Self where
I: IntoIterator,
HeaderName: TryFrom<I::Item>,
pub fn with_expose_headers<I>(self, headers: I) -> Self where
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
.
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 Origin
s.
Panics
Panics if the provided argument is not a valid Origin
.
pub fn with_allow_origins<I>(self, origins: I) -> Self where
I: IntoIterator,
I::Item: IntoOrigin,
pub fn with_allow_origins<I>(self, origins: I) -> Self where
I: IntoIterator,
I::Item: IntoOrigin,
Add multiple origins to the existing list of allowed Origin
s.
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_extra::cors::CorsHandler::builder()
.with_max_age(30) // 30u32 seconds
.with_max_age(Duration::from_secs(30)); // or a Duration
Builds the Cors
wrapper from the configured settings.
This step isn’t required, as the HandlerBuilder
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
Auto Trait Implementations
impl RefUnwindSafe for HandlerBuilder
impl Send for HandlerBuilder
impl Sync for HandlerBuilder
impl Unpin for HandlerBuilder
impl UnwindSafe for HandlerBuilder
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
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