summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Goetz <Markus.Goetz@nokia.com>2010-11-13 13:38:49 (GMT)
committerMarkus Goetz <Markus.Goetz@nokia.com>2010-11-13 15:52:54 (GMT)
commit76055d4e4a3023ef6390d85a02688bb11df57284 (patch)
tree6ae6e511c8a4fb5d547bea26c261ff1b49b16a07 /src
parent57ad39ec62175eeea023ca802448ebb1605dca23 (diff)
downloadQt-76055d4e4a3023ef6390d85a02688bb11df57284.zip
Qt-76055d4e4a3023ef6390d85a02688bb11df57284.tar.gz
Qt-76055d4e4a3023ef6390d85a02688bb11df57284.tar.bz2
QNAM HTTP: Ignore double content-length headers
Task-number: QTBUG-15311 Reviewed-by: ogoffart
Diffstat (limited to 'src')
-rw-r--r--src/network/access/qhttpnetworkheader.cpp12
-rw-r--r--src/network/access/qnetworkrequest.cpp10
2 files changed, 19 insertions, 3 deletions
diff --git a/src/network/access/qhttpnetworkheader.cpp b/src/network/access/qhttpnetworkheader.cpp
index 669f9cf..3eb2f3b 100644
--- a/src/network/access/qhttpnetworkheader.cpp
+++ b/src/network/access/qhttpnetworkheader.cpp
@@ -60,7 +60,17 @@ QHttpNetworkHeaderPrivate::QHttpNetworkHeaderPrivate(const QHttpNetworkHeaderPri
qint64 QHttpNetworkHeaderPrivate::contentLength() const
{
bool ok = false;
- QByteArray value = headerField("content-length");
+ // We are not using the headerField() method here because servers might send us multiple content-length
+ // headers which is crap (see QTBUG-15311). Therefore just take the first content-length header field.
+ QByteArray value;
+ QList<QPair<QByteArray, QByteArray> >::ConstIterator it = fields.constBegin(),
+ end = fields.constEnd();
+ for ( ; it != end; ++it)
+ if (qstricmp("content-length", it->first) == 0) {
+ value = it->second;
+ break;
+ }
+
qint64 length = value.toULongLong(&ok);
if (ok)
return length;
diff --git a/src/network/access/qnetworkrequest.cpp b/src/network/access/qnetworkrequest.cpp
index b761af5..162392d 100644
--- a/src/network/access/qnetworkrequest.cpp
+++ b/src/network/access/qnetworkrequest.cpp
@@ -899,10 +899,16 @@ void QNetworkHeadersPrivate::parseAndSetHeader(const QByteArray &key, const QByt
// is it a known header?
QNetworkRequest::KnownHeaders parsedKey = parseHeaderName(key);
if (parsedKey != QNetworkRequest::KnownHeaders(-1)) {
- if (value.isNull())
+ if (value.isNull()) {
cookedHeaders.remove(parsedKey);
- else
+ } else if (parsedKey == QNetworkRequest::ContentLengthHeader
+ && cookedHeaders.contains(QNetworkRequest::ContentLengthHeader)) {
+ // Only set the cooked header "Content-Length" once.
+ // See bug QTBUG-15311
+ } else {
cookedHeaders.insert(parsedKey, parseHeaderValue(parsedKey, value));
+ }
+
}
}