mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-08 02:32:37 +00:00
63e6845386
This is a breaking change for many consumers of the 'Response' and all consumers of the 'Body' API. The summary of breaking changes is: * 'Response::body()', 'Response::body_mut()' are infallible. * A 'Body' can represent an empty body in more cases. * 'ResponseBuilder' is now simply 'Builder'. * Direct body read methods on 'Response' were removed in favor of chaining through 'body_mut()': 'r.body_mut().to_string()'. * Notion of a 'chunked_body' was removed as it was inaccurate. * Maximum chunk size can be set on any body. * 'Response' no longer implements 'Responder'. A few bugs were fixed in the process. Specifically, 'Body' will emit an accurate size even for bodies that are partially read, and the size of seek-determined bodies is emitted on HEAD request where it wasn't before. Specifics on transport were clarified, and 'Body' docs greatly improved as a result.
33 lines
873 B
Rust
33 lines
873 B
Rust
#[macro_use] extern crate rocket;
|
|
|
|
use rocket::http::Header;
|
|
|
|
#[derive(Responder)]
|
|
struct HeaderOnly((), Header<'static>);
|
|
|
|
#[get("/do_not_overwrite")]
|
|
fn do_not_overwrite() -> HeaderOnly {
|
|
HeaderOnly((), Header::new("Server", "Test"))
|
|
}
|
|
|
|
#[get("/use_default")]
|
|
fn use_default() { }
|
|
|
|
mod conditionally_set_server_header {
|
|
use super::*;
|
|
use rocket::local::blocking::Client;
|
|
|
|
#[test]
|
|
fn do_not_overwrite_server_header() {
|
|
let client = Client::debug_with(routes![do_not_overwrite, use_default]).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"));
|
|
}
|
|
}
|