1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-02-22 20:52:27 +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 gotham::{
hyper::header::CONTENT_TYPE,
middleware::logger::RequestLogger,
pipeline::{new_pipeline, single::single_pipeline},
router::builder::*,
@ -124,12 +125,20 @@ fn main()
.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 logging = RequestLogger::new(log::Level::Info);
let (chain, pipelines) = single_pipeline(
new_pipeline()
.add(auth)
.add(logging)
.add(cors)
.build()
);

View file

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