Revise Utils::Gzip::compress code

Change signature
Add ZLIB_CONST define to make  z_stream.next_in const
Cast to zlib defined type Bytef*
Set memLevel to 9 in deflateInit2() for maximum performance
Revise compression loop
On returning false, free memory correctly by calling deflateEnd()
Reserve space by the estimation of deflateBound()
This commit is contained in:
Chocobo1 2017-04-17 16:52:43 +08:00
parent 94b496354b
commit 302c8ba850
3 changed files with 48 additions and 42 deletions

View file

@ -93,14 +93,15 @@ void Http::compressContent(Response &response)
return;
// try compressing
QByteArray buf;
if (!Utils::Gzip::compress(response.content, buf))
bool ok = false;
const QByteArray compressedData = Utils::Gzip::compress(response.content, 6, &ok);
if (!ok)
return;
// "Content-Encoding: gzip\r\n" is 24 bytes long
if ((buf.size() + 24) >= contentSize)
if ((compressedData.size() + 24) >= contentSize)
return;
response.content = buf;
response.content = compressedData;
response.headers[HEADER_CONTENT_ENCODING] = QLatin1String("gzip");
}