@@ -1667,14 +1667,15 @@ inline bool compress(std::string &content) {
16671667class  decompressor  {
16681668public: 
16691669  decompressor () {
1670+     std::memset (&strm, 0 , sizeof (strm));
16701671    strm.zalloc  = Z_NULL;
16711672    strm.zfree  = Z_NULL;
16721673    strm.opaque  = Z_NULL;
16731674
16741675    //  15 is the value of wbits, which should be at the maximum possible value
1675-     //  to ensure that any gzip stream can be decoded. The offset of 16  specifies
1676-     //  that the stream to decompress will  be formatted with a  gzip wrapper .
1677-     is_valid_ = inflateInit2 (&strm, 16  + 15 ) == Z_OK;
1676+     //  to ensure that any gzip stream can be decoded. The offset of 32  specifies
1677+     //  that the stream type should  be automatically detected either  gzip or deflate .
1678+     is_valid_ = inflateInit2 (&strm, 32  + 15 ) == Z_OK;
16781679  }
16791680
16801681  ~decompressor () { inflateEnd (&strm); }
@@ -1872,12 +1873,14 @@ bool read_content(Stream &strm, T &x, size_t payload_max_length, int &status,
18721873#ifdef  CPPHTTPLIB_ZLIB_SUPPORT
18731874  decompressor decompressor;
18741875
1875-   if  (!decompressor.is_valid ()) {
1876-     status = 500 ;
1877-     return  false ;
1878-   }
1876+   std::string content_encoding = x.get_header_value (" Content-Encoding" 
1877+   if  (content_encoding.find (" gzip" 
1878+           || content_encoding.find (" deflate" 
1879+     if  (!decompressor.is_valid ()) {
1880+       status = 500 ;
1881+       return  false ;
1882+     }
18791883
1880-   if  (x.get_header_value (" Content-Encoding" " gzip" 
18811884    out = [&](const  char  *buf, size_t  n) {
18821885      return  decompressor.decompress (
18831886          buf, n, [&](const  char  *buf, size_t  n) { return  receiver (buf, n); });
0 commit comments