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

HTTP behavior breaks when the response contains multiple Content-Length headers

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 4.7.2
    • 4.7.1
    • Network
    • None
    • Affects all environments
    • 76055d4e4a3023ef6390d85a02688bb11df57284

      When an HTTP response contains multiple Content-Length headers, their values are concatenated with commas, as for example:
      "8514, 8514"

      This value can of course not be converted toULongLong in

      qhttpnetworkheader.cpp: qint64 QHttpNetworkHeaderPrivate::contentLength() const

      and the size is returned as -1, after which that particular network request never finishes (times out eventually).

      Taken from a trace:

      GET /hprofile-ak-snc4/hs476.snc4/49933_542968802_1343495_s.jpg HTTP/1.1
      Connection: Keep-Alive
      Accept-Encoding: gzip
      Accept-Language: en-US,*
      User-Agent: Mozilla/5.0
      Host: profile.ak.fbcdn.net

      HTTP/1.1 200 OK
      Content-Type: image/jpeg
      Content-Length: 8514
      X-Backend: hs476.snc4
      X-Blockid: 49933
      Last-Modified: Thu, 01 Jan 2009 00:00:00 GMT
      Content-Length: 8514
      Expires: Sun, 26 Dec 2010 03:59:29 GMT
      Date: Sat, 13 Nov 2010 00:13:26 GMT
      Connection: keep-alive

      This is obviously not very correct behavior on the server side, but a robust client should be able to deal with this. This particular trace comes from Facebook's API servers and will affect Qt implementations of Facebook applications if not fixed. This is not an isolated case, a lot of responses have 2 content-lengths set.

      There are several approaches to fixing this, either checking for ", " in the ContentLength method; by storing it as an integer value rather than a generic header, or by building in knowledge of which headers can not have multiple values and for those headers replacing any existing values rather than concatenating. I've implemented the first solution to confirm that this really happens, and it fixes the stalling I've been seeing, images are loaded correctly and immediately now. I don't know what is the preferred way to fix this properly, so I'll leave that to someone else, or wait for someone to clarify an approach.

      (As a sidenote, if the content-length is thought to be -1, and the response is not chunked, shouldn't an error be thrown rather than downloading whatever happens to come and then waiting for a timeout?)

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

            mgoetz Markus Goetz (Inactive)
            dennis Dennis Noordsij
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes