Details
-
Bug
-
Resolution: Won't Do
-
P3: Somewhat important
-
None
-
5.15.2
-
None
Description
Currently if I manually set Accept-Encoding: gzip, deflate uncompressing response body will be broken. I mean in such case
QNetworkRequest request("http://example.com"); request.setRawHeader("Accept-Encoding", "gzip, deflate"); QNetworkReply *nam->get(request); connect(reply, &QNetworkReply::finished, [=]() { QByteArray ba = reply->readAll(); // ba contains compressed data instead of normal html page doSomething(); });
qhttpnetworkconnection.cpp
value = request.headerField("accept-encoding"); if (value.isEmpty()) { #ifndef QT_NO_COMPRESS request.setHeaderField("Accept-Encoding", "gzip, deflate"); request.d->autoDecompress = true; #else // if zlib is not available set this to false always request.d->autoDecompress = false; #endif }
This code can be rewritten as
value = request.headerField("accept-encoding"); if (value.isEmpty() || value == "gzip, deflate") { #ifndef QT_NO_COMPRESS if (value.isEmpty() { request.setHeaderField("Accept-Encoding", "gzip, deflate"); } request.d->autoDecompress = true; #else // if zlib is not available set this to false always request.d->autoDecompress = false; #endif }