[][src]Struct roa::cors::Cors

pub struct Cors { /* fields omitted */ }

A middleware to deal with Cross-Origin Resource Sharing (CORS).

Default

The default Cors middleware works well, it will use "origin" as value of response header "access-control-allow-origin",

And in preflight request, it will use "access-control-request-method" as value of "access-control-allow-methods" and use "access-control-request-headers" as value of "access-control-allow-headers".

Build a default Cors middleware:

use roa::cors::Cors;

let default_cors = Cors::new();

Config

You can also configure it:

use roa::cors::Cors;
use roa::http::header::{CONTENT_DISPOSITION, AUTHORIZATION, WWW_AUTHENTICATE};
use roa::http::Method;

let configured_cors = Cors::builder()
    .allow_credentials(true)
    .max_age(86400)
    .allow_origin("https://github.com")
    .allow_methods(vec![Method::GET, Method::POST])
    .allow_method(Method::PUT)
    .expose_headers(vec![CONTENT_DISPOSITION])
    .expose_header(WWW_AUTHENTICATE)
    .allow_headers(vec![AUTHORIZATION])
    .allow_header(CONTENT_DISPOSITION)
    .build();

Methods

impl Cors[src]

pub fn new() -> Self[src]

Construct default Cors.

pub fn builder() -> Builder[src]

Get builder.

Trait Implementations

impl Debug for Cors[src]

impl Default for Cors[src]

impl<S: State> Middleware<S> for Cors[src]

Auto Trait Implementations

impl RefUnwindSafe for Cors

impl Send for Cors

impl Sync for Cors

impl Unpin for Cors

impl UnwindSafe for Cors

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<S, F, T> Middleware<S> for T where
    F: 'static + Future<Output = Result<(), Error>>,
    S: State,
    T: 'static + Sync + Send + Fn(Context<S>, Pin<Box<dyn Future<Output = Result<(), Error>> + 'static>>) -> F, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,