1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-23 04:52:28 +00:00

cors in the example

This commit is contained in:
Dominic 2020-05-19 19:09:23 +02:00
parent b39b30694e
commit 7268cc0567
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
2 changed files with 10 additions and 4 deletions

View file

@ -3,6 +3,7 @@
use fake::{faker::internet::en::Username, Fake}; use fake::{faker::internet::en::Username, Fake};
use gotham::{ use gotham::{
hyper::header::CONTENT_TYPE,
middleware::logger::RequestLogger, middleware::logger::RequestLogger,
pipeline::{new_pipeline, single::single_pipeline}, pipeline::{new_pipeline, single::single_pipeline},
router::builder::*, router::builder::*,
@ -124,12 +125,20 @@ fn main()
.unwrap(); .unwrap();
log4rs::init_config(config).unwrap(); log4rs::init_config(config).unwrap();
let cors = CorsConfig {
origin: Origin::Copy,
headers: vec![CONTENT_TYPE],
credentials: true,
..Default::default()
};
let auth = <AuthMiddleware<(), Handler>>::from_source(AuthSource::AuthorizationHeader); let auth = <AuthMiddleware<(), Handler>>::from_source(AuthSource::AuthorizationHeader);
let logging = RequestLogger::new(log::Level::Info); let logging = RequestLogger::new(log::Level::Info);
let (chain, pipelines) = single_pipeline( let (chain, pipelines) = single_pipeline(
new_pipeline() new_pipeline()
.add(auth) .add(auth)
.add(logging) .add(logging)
.add(cors)
.build() .build()
); );

View file

@ -66,10 +66,7 @@ fn test_preflight(server : &TestServer, method : &str, origin : Option<&str>, va
#[test] #[test]
fn cors_origin_none() fn cors_origin_none()
{ {
let cfg = CorsConfig { let cfg = Default::default();
origin: Origin::None,
..Default::default()
};
let server = test_server(cfg); let server = test_server(cfg);
test_preflight(&server, "PUT", None, "Access-Control-Request-Method", false, 0); test_preflight(&server, "PUT", None, "Access-Control-Request-Method", false, 0);