Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does QNetworkManager get accept compressed replies by default?

I am using QNetworkManager to fetch files from a server, however what I cannot figure out is if the files are compressed during the transfer with the standard gzip compression and if not how to get them to download compressed.

How would I go about checking?

like image 214
Phil Hannent Avatar asked Mar 13 '26 01:03

Phil Hannent


2 Answers

I just ran a quick test by adding:

request.setRawHeader("Accept-Encoding", "gzip,deflate");

to the QNetworkRequest and the data returns what look compressed (because its ~20% smaller and unusable).

It appears that the QNetworkManager and the QNetworkReply are not intelligent as far as decompression is concerned. It looks like I have to implement a gzip and/or deflate on the returned QByteArray.

like image 98
Phil Hannent Avatar answered Mar 15 '26 23:03

Phil Hannent


When you set a custom Accept-Encoding raw header on a QNetworkRequest object (for example via an overridden QNetworkAccessManager::createRequest() ), QtWebKit will never decompress the reply anymore: source code of qhttpnetworkconnection.cpp : ====================

    // If the request had a accept-encoding set, we better not mess
    // with it. If it was not set, we announce that we understand gzip
    // and remember this fact in request.d->autoDecompress so that
    // we can later decompress the HTTP reply if it has such an
    // encoding.
    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
like image 27
user6684806 Avatar answered Mar 15 '26 23:03

user6684806