From 412ba04d1933cb13ff37a5b0184dc8691dde563c Mon Sep 17 00:00:00 2001 From: yhirose Date: Thu, 14 Nov 2024 20:33:08 -0500 Subject: [PATCH] Fix problem caused by #1975 --- httplib.h | 24 +++++++++++++----------- test/test.cc | 1 + 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/httplib.h b/httplib.h index 0917617e93..e50ad45613 100644 --- a/httplib.h +++ b/httplib.h @@ -7702,24 +7702,26 @@ inline bool ClientImpl::write_request(Stream &strm, Request &req, if (!req.has_header("Accept")) { req.set_header("Accept", "*/*"); } - if (!req.has_header("Accept-Encoding")) { - std::string accept_encoding; + if (!req.content_receiver) { + if (!req.has_header("Accept-Encoding")) { + std::string accept_encoding; #ifdef CPPHTTPLIB_BROTLI_SUPPORT - accept_encoding = "br"; + accept_encoding = "br"; #endif #ifdef CPPHTTPLIB_ZLIB_SUPPORT - if (!accept_encoding.empty()) { accept_encoding += ", "; } - accept_encoding += "gzip, deflate"; + if (!accept_encoding.empty()) { accept_encoding += ", "; } + accept_encoding += "gzip, deflate"; #endif - req.set_header("Accept-Encoding", accept_encoding); - } + req.set_header("Accept-Encoding", accept_encoding); + } #ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT - if (!req.has_header("User-Agent")) { - auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION; - req.set_header("User-Agent", agent); - } + if (!req.has_header("User-Agent")) { + auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION; + req.set_header("User-Agent", agent); + } #endif + }; if (req.body.empty()) { if (req.content_provider_) { diff --git a/test/test.cc b/test/test.cc index 822c8bb137..cc9ffeb526 100644 --- a/test/test.cc +++ b/test/test.cc @@ -5609,6 +5609,7 @@ TEST(LongPollingTest, ClientCloseDetection) { auto count = 10; while (count > 0 && sink.is_writable()) { this_thread::sleep_for(chrono::milliseconds(10)); + count--; } EXPECT_FALSE(sink.is_writable()); // the socket is closed return true;