@@ -778,6 +778,8 @@ class Client {
778778
779779 void set_compress (bool on);
780780
781+ void set_decompress (bool on);
782+
781783 void set_interface (const char *intf);
782784
783785 void set_proxy (const char *host, int port);
@@ -821,6 +823,7 @@ class Client {
821823 bool follow_location_ = false ;
822824
823825 bool compress_ = false ;
826+ bool decompress_ = true ;
824827
825828 std::string interface_;
826829
@@ -853,6 +856,7 @@ class Client {
853856#endif
854857 follow_location_ = rhs.follow_location_ ;
855858 compress_ = rhs.compress_ ;
859+ decompress_ = rhs.decompress_ ;
856860 interface_ = rhs.interface_ ;
857861 proxy_host_ = rhs.proxy_host_ ;
858862 proxy_port_ = rhs.proxy_port_ ;
@@ -1281,6 +1285,11 @@ class Client2 {
12811285 return *this ;
12821286 }
12831287
1288+ Client2 &set_decompress (bool on) {
1289+ cli_->set_decompress (on);
1290+ return *this ;
1291+ }
1292+
12841293 Client2 &set_interface (const char *intf) {
12851294 cli_->set_interface (intf);
12861295 return *this ;
@@ -2395,34 +2404,39 @@ inline bool is_chunked_transfer_encoding(const Headers &headers) {
23952404
23962405template <typename T>
23972406bool read_content (Stream &strm, T &x, size_t payload_max_length, int &status,
2398- Progress progress, ContentReceiver receiver) {
2407+ Progress progress, ContentReceiver receiver, bool decompress ) {
23992408
24002409 ContentReceiver out = [&](const char *buf, size_t n) {
24012410 return receiver (buf, n);
24022411 };
24032412
24042413#ifdef CPPHTTPLIB_ZLIB_SUPPORT
24052414 decompressor decompressor;
2415+ #endif
24062416
2407- std::string content_encoding = x.get_header_value (" Content-Encoding" );
2408- if (content_encoding.find (" gzip" ) != std::string::npos ||
2409- content_encoding.find (" deflate" ) != std::string::npos) {
2410- if (!decompressor.is_valid ()) {
2411- status = 500 ;
2412- return false ;
2413- }
2417+ if (decompress) {
2418+ #ifdef CPPHTTPLIB_ZLIB_SUPPORT
2419+ std::string content_encoding = x.get_header_value (" Content-Encoding" );
2420+ if (content_encoding.find (" gzip" ) != std::string::npos ||
2421+ content_encoding.find (" deflate" ) != std::string::npos) {
2422+ if (!decompressor.is_valid ()) {
2423+ status = 500 ;
2424+ return false ;
2425+ }
24142426
2415- out = [&](const char *buf, size_t n) {
2416- return decompressor.decompress (
2417- buf, n, [&](const char *buf, size_t n) { return receiver (buf, n); });
2418- };
2419- }
2427+ out = [&](const char *buf, size_t n) {
2428+ return decompressor.decompress (buf, n, [&](const char *buf, size_t n) {
2429+ return receiver (buf, n);
2430+ });
2431+ };
2432+ }
24202433#else
2421- if (x.get_header_value (" Content-Encoding" ) == " gzip" ) {
2422- status = 415 ;
2423- return false ;
2424- }
2434+ if (x.get_header_value (" Content-Encoding" ) == " gzip" ) {
2435+ status = 415 ;
2436+ return false ;
2437+ }
24252438#endif
2439+ }
24262440
24272441 auto ret = true ;
24282442 auto exceed_payload_max_length = false ;
@@ -3883,7 +3897,7 @@ inline bool Server::read_content_core(Stream &strm, Request &req, Response &res,
38833897 }
38843898
38853899 if (!detail::read_content (strm, req, payload_max_length_, res.status ,
3886- Progress (), out)) {
3900+ Progress (), out, true )) {
38873901 return false ;
38883902 }
38893903
@@ -4663,7 +4677,7 @@ inline bool Client::process_request(Stream &strm, const Request &req,
46634677
46644678 int dummy_status;
46654679 if (!detail::read_content (strm, res, (std::numeric_limits<size_t >::max)(),
4666- dummy_status, req.progress , out)) {
4680+ dummy_status, req.progress , out, decompress_ )) {
46674681 return false ;
46684682 }
46694683 }
@@ -5025,6 +5039,8 @@ inline void Client::set_follow_location(bool on) { follow_location_ = on; }
50255039
50265040inline void Client::set_compress (bool on) { compress_ = on; }
50275041
5042+ inline void Client::set_decompress (bool on) { decompress_ = on; }
5043+
50285044inline void Client::set_interface (const char *intf) { interface_ = intf; }
50295045
50305046inline void Client::set_proxy (const char *host, int port) {
0 commit comments