Struct gotham_cors_middleware::CORSMiddleware
source · pub struct CORSMiddleware { /* private fields */ }
Expand description
Struct to perform the necessary CORS functionality needed. Allows some customisation through use of the new() function.
Example of use:
extern crate gotham;
extern crate gotham_cors_middleware;
use gotham::pipeline::new_pipeline;
use gotham_cors_middleware::CORSMiddleware;
use gotham::pipeline::single::single_pipeline;
use gotham::router::builder::*;
use gotham::router::Router;
pub fn router() -> Router {
let (chain, pipeline) = single_pipeline(
new_pipeline()
.add(CORSMiddleware::default())
.build()
);
build_router(chain, pipeline, |route| {
// Routes
})
}
Implementations
sourceimpl CORSMiddleware
impl CORSMiddleware
sourcepub fn new(
methods: Vec<Method>,
origin: Option<String>,
max_age: u32
) -> CORSMiddleware
pub fn new(
methods: Vec<Method>,
origin: Option<String>,
max_age: u32
) -> CORSMiddleware
Create a new CORSMiddleware with custom methods, origin and max_age properties.
Expects methods to be a Vec of hyper::Method enum values, origin to be an Option containing a String (so allows for None values - which defaults to returning the sender origin on request or returning a string of “*” - see the call function source) and max age to be a u32 value.
Example of use:
extern crate gotham;
extern crate gotham_cors_middleware;
extern crate hyper;
use gotham::pipeline::new_pipeline;
use gotham_cors_middleware::CORSMiddleware;
use gotham::pipeline::single::single_pipeline;
use gotham::router::builder::*;
use gotham::router::Router;
use hyper::Method;
fn create_custom_middleware() -> CORSMiddleware {
let methods = vec![Method::Delete, Method::Get, Method::Head, Method::Options];
let max_age = 1000;
let origin = Some("http://www.example.com".to_string());
CORSMiddleware::new(methods, origin, max_age)
}
pub fn router() -> Router {
let (chain, pipeline) = single_pipeline(
new_pipeline()
.add(create_custom_middleware())
.build()
);
build_router(chain, pipeline, |route| {
// Routes
})
}
sourcepub fn default() -> CORSMiddleware
pub fn default() -> CORSMiddleware
Creates a new CORSMiddleware with what is currently the “default” values for methods/origin/max_age.
This is based off the values that were used previously before they were customisable. If you need different values, use the new() function.
Trait Implementations
sourceimpl Clone for CORSMiddleware
impl Clone for CORSMiddleware
sourcefn clone(&self) -> CORSMiddleware
fn clone(&self) -> CORSMiddleware
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresourceimpl Debug for CORSMiddleware
impl Debug for CORSMiddleware
sourceimpl Middleware for CORSMiddleware
impl Middleware for CORSMiddleware
sourcefn call<Chain>(self, state: State, chain: Chain) -> Box<HandlerFuture>where
Chain: FnOnce(State) -> Box<HandlerFuture>,
fn call<Chain>(self, state: State, chain: Chain) -> Box<HandlerFuture>where
Chain: FnOnce(State) -> Box<HandlerFuture>,
Entry point to the middleware. To pass the request on to the application, the middleware
invokes the
chain
function with the provided state
. Read moresourceimpl NewMiddleware for CORSMiddleware
impl NewMiddleware for CORSMiddleware
type Instance = CORSMiddleware
type Instance = CORSMiddleware
The type of
Middleware
created by the NewMiddleware
.sourcefn new_middleware(&self) -> Result<Self>
fn new_middleware(&self) -> Result<Self>
Create and return a new
Middleware
value.sourceimpl PartialEq<CORSMiddleware> for CORSMiddleware
impl PartialEq<CORSMiddleware> for CORSMiddleware
sourcefn eq(&self, other: &CORSMiddleware) -> bool
fn eq(&self, other: &CORSMiddleware) -> bool
impl StructuralPartialEq for CORSMiddleware
Auto Trait Implementations
impl RefUnwindSafe for CORSMiddleware
impl Send for CORSMiddleware
impl Sync for CORSMiddleware
impl Unpin for CORSMiddleware
impl UnwindSafe for CORSMiddleware
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more