Skip to content

Commit 412ba04

Browse files
committed
Fix problem caused by #1975
1 parent bfef4b3 commit 412ba04

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

httplib.h

+13-11
Original file line numberDiff line numberDiff line change
@@ -7702,24 +7702,26 @@ inline bool ClientImpl::write_request(Stream &strm, Request &req,
77027702

77037703
if (!req.has_header("Accept")) { req.set_header("Accept", "*/*"); }
77047704

7705-
if (!req.has_header("Accept-Encoding")) {
7706-
std::string accept_encoding;
7705+
if (!req.content_receiver) {
7706+
if (!req.has_header("Accept-Encoding")) {
7707+
std::string accept_encoding;
77077708
#ifdef CPPHTTPLIB_BROTLI_SUPPORT
7708-
accept_encoding = "br";
7709+
accept_encoding = "br";
77097710
#endif
77107711
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
7711-
if (!accept_encoding.empty()) { accept_encoding += ", "; }
7712-
accept_encoding += "gzip, deflate";
7712+
if (!accept_encoding.empty()) { accept_encoding += ", "; }
7713+
accept_encoding += "gzip, deflate";
77137714
#endif
7714-
req.set_header("Accept-Encoding", accept_encoding);
7715-
}
7715+
req.set_header("Accept-Encoding", accept_encoding);
7716+
}
77167717

77177718
#ifndef CPPHTTPLIB_NO_DEFAULT_USER_AGENT
7718-
if (!req.has_header("User-Agent")) {
7719-
auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION;
7720-
req.set_header("User-Agent", agent);
7721-
}
7719+
if (!req.has_header("User-Agent")) {
7720+
auto agent = std::string("cpp-httplib/") + CPPHTTPLIB_VERSION;
7721+
req.set_header("User-Agent", agent);
7722+
}
77227723
#endif
7724+
};
77237725

77247726
if (req.body.empty()) {
77257727
if (req.content_provider_) {

test/test.cc

+1
Original file line numberDiff line numberDiff line change
@@ -5609,6 +5609,7 @@ TEST(LongPollingTest, ClientCloseDetection) {
56095609
auto count = 10;
56105610
while (count > 0 && sink.is_writable()) {
56115611
this_thread::sleep_for(chrono::milliseconds(10));
5612+
count--;
56125613
}
56135614
EXPECT_FALSE(sink.is_writable()); // the socket is closed
56145615
return true;

0 commit comments

Comments
 (0)