Struct poem::middleware::Cors

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

Middleware for CORS

§Errors

§Example

use poem::{http::Method, middleware::Cors};

let cors = Cors::new()
    .allow_method(Method::GET)
    .allow_method(Method::POST)
    .allow_credentials(false);

Implementations§

source§

impl Cors

source

pub fn new() -> Self

Creates a new CORS middleware.

source

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

Set allow credentials.

source

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

Add an allow header.

NOTE: Default is allow any header.

source

pub fn allow_headers<I, T>(self, headers: I) -> Self
where I: IntoIterator<Item = T>, HeaderName: TryFrom<T>,

Add many allow headers.

source

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

Add an allow method.

NOTE: Default is allow any method.

source

pub fn allow_methods<I, T>(self, methods: I) -> Self
where I: IntoIterator<Item = T>, Method: TryFrom<T>,

Add many allow methods.

source

pub fn allow_origin<T>(self, origin: T) -> Self
where HeaderValue: TryFrom<T>,

Add an allow origin.

NOTE: Default is allow any origin.

source

pub fn allow_origin_regex(self, origin: impl AsRef<str>) -> Self

Add an allowed origin that supports ‘*’ wildcard. Example: rust cors.allow_origin_regex("https://*.domain.url")

source

pub fn allow_origins<I, T>(self, origins: I) -> Self
where I: IntoIterator<Item = T>, HeaderValue: TryFrom<T>,

Add many allow origins.

source

pub fn allow_origins_fn<F>(self, f: F) -> Self
where F: Fn(&str) -> bool + Send + Sync + 'static,

Determinate allowed origins by processing requests which didn’t match any origins specified in the allow_origin.

This function will receive the Origin header, which can be used to determine whether to allow the request.

source

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

Add an expose header.

source

pub fn expose_headers<I, T>(self, headers: I) -> Self
where I: IntoIterator<Item = T>, HeaderName: TryFrom<T>,

Add many expose headers.

source

pub fn max_age(self, max_age: i32) -> Self

Set max age.

Trait Implementations§

source§

impl Default for Cors

source§

fn default() -> Cors

Returns the “default value” for a type. Read more
source§

impl<E: Endpoint> Middleware<E> for Cors

§

type Output = CorsEndpoint<E>

New endpoint type. Read more
source§

fn transform(&self, ep: E) -> Self::Output

Transform the input Endpoint to another one.

Auto Trait Implementations§

§

impl Freeze for Cors

§

impl !RefUnwindSafe for Cors

§

impl Send for Cors

§

impl Sync for Cors

§

impl Unpin for Cors

§

impl !UnwindSafe for Cors

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

source§

fn implicit( self, class: Class, constructed: bool, tag: u32 ) -> TaggedParser<'a, Implicit, Self, E>

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> FutureExt for T

source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
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> TowerCompatExt for T

source§

fn compat<ResBody, Err, Fut>(self) -> TowerCompatEndpoint<Self>
where ResBody: Body + Send + Sync + 'static, ResBody::Data: Into<Bytes> + Send + 'static, ResBody::Error: StdError + Send + Sync + 'static, Err: Into<Error>, Self: Service<Request<BoxBody<Bytes, Error>>, Response = Response<ResBody>, Error = Err, Future = Fut> + Clone + Send + Sync + Sized + 'static, Fut: Future<Output = Result<Response<ResBody>, Err>> + Send + 'static,

Available on crate feature tower-compat only.
Converts a tower service to a poem endpoint.
source§

impl<L> TowerLayerCompatExt for L

source§

fn compat(self) -> TowerCompatMiddleware<Self>
where Self: Sized,

Available on crate feature tower-compat only.
Converts a tower layer to a poem middleware.
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<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

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