Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-41840

QNetworkReply does not have Content-length when received compressed content

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.9
    • 4.8.6, 5.6.0
    • Network: HTTP
    • None
    • 511623b6f065d1ac633af66926150f35676be498

    Description

      If you don't specify in HTTP GET request header Accept-Encoding as gzip using QNetworkRequest API and let Qt set it automatically, then you will not be able to read Content-length attribute from the reponse although it is received.

      Code that reproduces it in my environment:

          QNetworkAccessManager manager;
      
          QUrl url("http://192.168.1.83:8090/v1/areas/a70b07c1-eb23-11e3-afd1-080027f0eec3/locations");
          QNetworkRequest request(url);
      
          request.setRawHeader("Authorization", getHttpAuthorization().toLocal8Bit());
          request.setRawHeader("Accept", "application/json");
          request.setRawHeader("Accept-Charset", "utf-8");
          //request.setRawHeader("Accept-Encoding", "gzip");
          request.setRawHeader("If-None-Match", "dummy_etag");
      
          QNetworkReply* reply = manager.get(request);
      
      
          std::function<void ()> onFinished = [=]() {
              qDebug() << "raw Content-Length: " << reply->rawHeader("Content-Length")
                       << " known header: " << reply->header(QNetworkRequest::ContentLengthHeader);
          };
          QtSignalForwarder::connect(reply, SIGNAL(finished()), onFinished);
          QObject::connect(reply, SIGNAL(finished()), reply, SLOT(deleteLater()));
      
          QEventLoop loop;
          QObject::connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
          loop.exec();
      

      Output:

      raw Content-Length:  ""  known header:  QVariant(, )
      

      HTTP request and response from Wireshark:

      GET /v1/areas/a70b07c1-eb23-11e3-afd1-080027f0eec3/locations HTTP/1.1
      Authorization: Basic MDAxNzlkMDA2NjAwMDAwMTo=
      Accept: application/json
      Accept-Charset: utf-8
      If-None-Match: dummy_etag
      Connection: Keep-Alive
      Accept-Encoding: gzip
      Accept-Language: en-US,*
      User-Agent: Mozilla/5.0
      Host: 192.168.1.83:8090
      
      HTTP/1.1 200 OK
      Date: Wed, 08 Oct 2014 12:08:50 GMT
      Content-Type: application/json; charset=utf-8
      Content-Encoding: gzip
      ETag: "14283"
      Content-Length: 273176
      

      If you uncomment request.setRawHeader("Accept-Encoding", "gzip");
      then in output you will get:

      raw Content-Length:  "273176"  known header:  QVariant(qlonglong, 273176)
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            jefernan Jesus Fernandez
            mass85 Marcin Adamski
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes