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")]
|
2020-07-05 18:35:36 +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"))
|
2020-02-03 08:30:22 +00:00
|
|
|
.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::*;
|
2020-07-05 18:35:36 +00:00
|
|
|
use rocket::local::blocking::Client;
|
2019-05-08 21:51:19 +00:00
|
|
|
|
2020-07-05 18:35:36 +00:00
|
|
|
#[test]
|
|
|
|
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]);
|
2020-07-05 18:35:36 +00:00
|
|
|
let client = Client::new(rocket).unwrap();
|
2019-05-08 21:51:19 +00:00
|
|
|
|
2020-07-05 18:35:36 +00:00
|
|
|
let response = client.get("/do_not_overwrite").dispatch();
|
2019-05-08 21:51:19 +00:00
|
|
|
let server = response.headers().get_one("Server");
|
|
|
|
assert_eq!(server, Some("Test"));
|
|
|
|
|
2020-07-05 18:35:36 +00:00
|
|
|
let response = client.get("/use_default").dispatch();
|
2019-05-08 21:51:19 +00:00
|
|
|
let server = response.headers().get_one("Server");
|
|
|
|
assert_eq!(server, Some("Rocket"));
|
|
|
|
}
|
|
|
|
}
|