2019-08-20 23:53:00 +00:00
|
|
|
#![feature(proc_macro_hygiene)]
|
2019-05-08 21:51:19 +00:00
|
|
|
|
2019-05-09 03:10:22 +00:00
|
|
|
#[macro_use] extern crate rocket;
|
2019-05-08 21:51:19 +00:00
|
|
|
|
|
|
|
use rocket::Response;
|
2019-05-09 03:10:22 +00:00
|
|
|
use rocket::http::Header;
|
2019-05-08 21:51:19 +00:00
|
|
|
|
|
|
|
#[get("/do_not_overwrite")]
|
2019-05-09 03:10:22 +00:00
|
|
|
fn do_not_overwrite() -> Response<'static> {
|
2019-05-08 21:51:19 +00:00
|
|
|
Response::build()
|
2019-05-09 03:10:22 +00:00
|
|
|
.header(Header::new("Server", "Test"))
|
|
|
|
.finalize()
|
2019-05-08 21:51:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[get("/use_default")]
|
2019-05-09 03:10:22 +00:00
|
|
|
fn use_default() { }
|
2019-05-08 21:51:19 +00:00
|
|
|
|
|
|
|
mod conditionally_set_server_header {
|
|
|
|
use super::*;
|
|
|
|
use rocket::local::Client;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn do_not_overwrite_server_header() {
|
|
|
|
let rocket = rocket::ignite().mount("/", routes![do_not_overwrite, use_default]);
|
|
|
|
let client = Client::new(rocket).unwrap();
|
|
|
|
|
|
|
|
let response = client.get("/do_not_overwrite").dispatch();
|
|
|
|
let server = response.headers().get_one("Server");
|
|
|
|
assert_eq!(server, Some("Test"));
|
|
|
|
|
|
|
|
let response = client.get("/use_default").dispatch();
|
|
|
|
let server = response.headers().get_one("Server");
|
|
|
|
assert_eq!(server, Some("Rocket"));
|
|
|
|
}
|
|
|
|
}
|