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

Allow default Accept-Encoding

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • P3: Somewhat important
    • None
    • 5.15.2
    • Network: HTTP
    • 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
          }
      

      Attachments

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

        Activity

          People

            manordheim Mårten Nordheim
            taurus Ivan Romanov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes