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?)