mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-20 16:39:03 +00:00
03127f4dae
This commit adds the 'local::blocking' module and moves the existing asynchronous testing to 'local::asynchronous'. It also includes several changes to improve the local API, bringing it to parity (and beyond) with master. These changes are: * 'LocalRequest' implements 'Clone'. * 'LocalResponse' doesn't implement 'DerefMut<Target=Response>'. Instead, direct methods on the type, such as 'into_string()', can be used to read the 'Response'. * 'Response::body()' returns an '&ResponseBody' as opposed to '&mut ResponseBody', which is returned by a new 'Response::body_mut()'. * '&ResponseBody' implements 'known_size()` to retrieve a body's size, if it is known. Co-authored-by: Jeb Rosen <jeb@jebrosen.com>
36 lines
1011 B
Rust
36 lines
1011 B
Rust
#![feature(proc_macro_hygiene)]
|
|
|
|
#[macro_use] extern crate rocket;
|
|
|
|
use rocket::Response;
|
|
use rocket::http::Header;
|
|
|
|
#[get("/do_not_overwrite")]
|
|
async fn do_not_overwrite() -> Response<'static> {
|
|
Response::build()
|
|
.header(Header::new("Server", "Test"))
|
|
.finalize()
|
|
}
|
|
|
|
#[get("/use_default")]
|
|
fn use_default() { }
|
|
|
|
mod conditionally_set_server_header {
|
|
use super::*;
|
|
use rocket::local::asynchronous::Client;
|
|
|
|
#[rocket::async_test]
|
|
async fn do_not_overwrite_server_header() {
|
|
let rocket = rocket::ignite().mount("/", routes![do_not_overwrite, use_default]);
|
|
let client = Client::new(rocket).await.unwrap();
|
|
|
|
let response = client.get("/do_not_overwrite").dispatch().await;
|
|
let server = response.headers().get_one("Server");
|
|
assert_eq!(server, Some("Test"));
|
|
|
|
let response = client.get("/use_default").dispatch().await;
|
|
let server = response.headers().get_one("Server");
|
|
assert_eq!(server, Some("Rocket"));
|
|
}
|
|
}
|