From 92bd5225d1c2665d2bff463f45d35546b1a3ff14 Mon Sep 17 00:00:00 2001 From: arlecchino Date: Sat, 11 May 2024 13:57:39 +0200 Subject: [PATCH] fix: http-0-9 handling HttpVersionNotSupported505 --- src/client.rs | 13 +++++++++++-- tests/http-0_9.rs | 4 ++-- tests/network.rs | 11 ++--------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/client.rs b/src/client.rs index ce4398e0..3d689615 100644 --- a/src/client.rs +++ b/src/client.rs @@ -483,10 +483,19 @@ fn send_error_std_response( client_connection: &mut ClientConnection, status: response::Standard, version: Option, - 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) }; diff --git a/tests/http-0_9.rs b/tests/http-0_9.rs index 14d6ebf2..352799b2 100644 --- a/tests/http-0_9.rs +++ b/tests/http-0_9.rs @@ -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: {}", @@ -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: {}", diff --git a/tests/network.rs b/tests/network.rs index 8e8ca0d9..4a766364 100644 --- a/tests/network.rs +++ b/tests/network.rs @@ -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();