Skip to content

Commit

Permalink
fix: http-0-9 handling HttpVersionNotSupported505
Browse files Browse the repository at this point in the history
  • Loading branch information
kolbma committed May 11, 2024
1 parent 862909c commit 92bd522
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
13 changes: 11 additions & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,10 +483,19 @@ fn send_error_std_response(
client_connection: &mut ClientConnection,
status: response::Standard,
version: Option<HttpVersion>,
do_not_send_body: bool,
mut do_not_send_body: bool,
) {
let version = if status == HttpVersionNotSupported505 {
HttpVersion::Version1_0
if let Some(version) = version {
do_not_send_body = false;
if version == HttpVersion::Version0_9 {
HttpVersion::Version0_9
} else {
HttpVersion::Version1_0
}
} else {
HttpVersion::Version1_0
}
} else {
version.unwrap_or(HttpVersion::Version1_0)
};
Expand Down
4 changes: 2 additions & 2 deletions tests/http-0_9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn http_0_9_not_supported_test() {
let mut content = String::new();
let _ = client.read_to_string(&mut content);

assert!(content.starts_with("HTTP/"), "content: {}", content);
assert!(!content.starts_with("HTTP/"), "content: {}", content);
assert!(
content.contains("HTTP Version Not Supported"),
"content: {}",
Expand All @@ -48,7 +48,7 @@ fn http_0_9_not_supported_test() {
let mut content = String::new();
let _ = client.read_to_string(&mut content);

assert!(content.starts_with("HTTP/"), "content: {}", content);
assert!(!content.starts_with("HTTP/"), "content: {}", content);
assert!(
content.contains("HTTP Version Not Supported"),
"content: {}",
Expand Down
11 changes: 2 additions & 9 deletions tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,16 +434,9 @@ fn supported_http_versions_test() {
client = check_client_close(client, &content);

#[cfg(feature = "http-0-9")]
assert_eq!(&mut content, "hello world");
assert_eq!(content, "hello world");
#[cfg(not(feature = "http-0-9"))]
{
assert!(
content.ends_with("HTTP Version Not Supported"),
"content: {}",
content
);
assert_contains(505, "1.0", &mut content);
}
assert_eq!(content, "HTTP Version Not Supported");

for v in ["1.0", "1.1"] {
write!(client, "GET / HTTP/{v}\r\nHost: localhost\r\n\r\n").unwrap();
Expand Down

0 comments on commit 92bd522

Please sign in to comment.