3

Is it possible to read undecoded data from QNetworkReply?

Response is encoded using gzip (Content-Encoding: gzip HTTP header), but when i call readAll() method it returns decoded data. I need raw gzipped data, as it was sent to me. Any ideas?

Mateusz Mazurek
  • 101
  • 1
  • 8
  • Related to [does-qnetworkmanager-get-accept-compressed-replies-by-default](https://stackoverflow.com/questions/2340548/does-qnetworkmanager-get-accept-compressed-replies-by-default) – Jarod42 Sep 21 '17 at 17:32

1 Answers1

0

You have to set yourself the header for your QNetworkRequest:

 networkRequest.setRawHeader("Accept-Encoding", "gzip");

Then Qt doesn't decode for you in the reply.

We can see in the source of qhttpnetworkconnection.cpp for QHttpNetworkConnectionPrivate::prepareRequest:

    // 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");
        request.d->autoDecompress = true;
#else
        // if zlib is not available set this to false always
        request.d->autoDecompress = false;
#endif
    }
Jarod42
  • 203,559
  • 14
  • 181
  • 302