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;
|
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
#[rocket::async_test]
|
|
|
|
async fn do_not_overwrite_server_header() {
|
2019-05-08 21:51:19 +00:00
|
|
|
let rocket = rocket::ignite().mount("/", routes![do_not_overwrite, use_default]);
|
|
|
|
let client = Client::new(rocket).unwrap();
|
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
let response = client.get("/do_not_overwrite").dispatch().await;
|
2019-05-08 21:51:19 +00:00
|
|
|
let server = response.headers().get_one("Server");
|
|
|
|
assert_eq!(server, Some("Test"));
|
|
|
|
|
2019-08-24 17:27:10 +00:00
|
|
|
let response = client.get("/use_default").dispatch().await;
|
2019-05-08 21:51:19 +00:00
|
|
|
let server = response.headers().get_one("Server");
|
|
|
|
assert_eq!(server, Some("Rocket"));
|
|
|
|
}
|
|
|
|
}
|