-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Strip body and content-length on 204, body on 304.
This works-around an issue where hyper incorrectly removes the body on 204 responses without removing the content-length or setting it to zero. Resolves #2821.
- Loading branch information
1 parent
d332339
commit 9496b70
Showing
4 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ pub mod mtls; | |
pub mod sni_resolver; | ||
pub mod tracing; | ||
pub mod tls; | ||
pub mod no_content; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//! Ensure that responses with a status of 204 or 304 do not have a body, and | ||
//! for the former, do not have a Content-Length header. | ||
use crate::prelude::*; | ||
|
||
use rocket::http::Status; | ||
|
||
#[get("/<code>")] | ||
fn status(code: u16) -> (Status, &'static [u8]) { | ||
(Status::new(code), &[1, 2, 3, 4]) | ||
} | ||
|
||
pub fn test_no_content() -> Result<()> { | ||
let server = spawn!(Rocket::default().mount("/", routes![status]))?; | ||
|
||
let client = Client::default(); | ||
let response = client.get(&server, "/204")?.send()?; | ||
assert_eq!(response.status(), 204); | ||
assert!(response.headers().get("Content-Length").is_none()); | ||
assert!(response.bytes()?.is_empty()); | ||
|
||
let response = client.get(&server, "/304")?.send()?; | ||
assert_eq!(response.status(), 304); | ||
assert_eq!(response.headers().get("Content-Length").unwrap(), "4"); | ||
assert!(response.bytes()?.is_empty()); | ||
|
||
Ok(()) | ||
} | ||
|
||
register!(test_no_content); |