From 488e05e84c4658a828db16a5c8d7ebeffdb7f45f Mon Sep 17 00:00:00 2001 From: Mateo Cabanal Date: Thu, 7 May 2026 20:33:39 -0500 Subject: [PATCH] Avoid collecting accepted encodings while detecting gzip --- tinyhttp-internal/src/http.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/tinyhttp-internal/src/http.rs b/tinyhttp-internal/src/http.rs index 0f5a303..bdec8b9 100755 --- a/tinyhttp-internal/src/http.rs +++ b/tinyhttp-internal/src/http.rs @@ -253,21 +253,15 @@ pub fn parse_request(conn: &mut TcpStream, config: Arc) { };*/ let req_headers = request.get_headers(); - let _comp = if config.get_gzip() { - if req_headers.contains("Accept-Encoding") { - let tmp_str = req_headers.get("Accept-Encoding").unwrap(); - let res: Vec<&str> = tmp_str.split(',').map(|s| s.trim()).collect(); - - #[cfg(feature = "log")] - log::trace!("{:#?}", &res); - - res.contains(&"gzip") - } else { - false - } - } else { - false - }; + let _comp = config.get_gzip() + && req_headers + .get("Accept-Encoding") + .map(|tmp_str| { + tmp_str + .split(',') + .any(|encoding| encoding.trim().eq_ignore_ascii_case("gzip")) + }) + .unwrap_or(false); let mut response = build_res(request, &config, conn); if response.manual_override {