summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Kling <andreas.kling@nokia.com>2011-03-22 14:54:33 +0100
committerAndreas Kling <andreas.kling@nokia.com>2011-03-22 15:03:45 +0100
commite3df83e8735124dbd15107b0c083d75d99b98ea9 (patch)
treeef823cf159beab53dbb59f558ddfb29fb4111b20
parent3441c288be67c79c960e8386668731e55db60f0c (diff)
QNAM HTTP: Fix bug with explicitly zero-length compressed responses.
In the case of a response with e.g content-encoding "gzip" and content-length "0", the HTTP backend would incorrectly fall back to the "unspecified length" code path and wait for readyRead() forever. Task-number: QTBUG-18232 Reviewed-by: Markus Goetz
-rw-r--r--src/network/access/qhttpnetworkreply.cpp8
-rw-r--r--tests/auto/qnetworkreply/tst_qnetworkreply.cpp21
2 files changed, 28 insertions, 1 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index 704cf3a605..cb6c09f010 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -886,8 +886,14 @@ bool QHttpNetworkReplyPrivate::expectContent()
return false;
if (request.operation() == QHttpNetworkRequest::Head)
return !shouldEmitSignals();
- if (contentLength() == 0)
+ qint64 expectedContentLength = contentLength();
+ if (expectedContentLength == 0)
return false;
+ if (expectedContentLength == -1 && bodyLength == 0) {
+ // The content-length header was stripped, but its value was 0.
+ // This would be the case for an explicitly zero-length compressed response.
+ return false;
+ }
return true;
}
diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
index 2c799511bb..48b3ecc8e7 100644
--- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
+++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp
@@ -337,6 +337,8 @@ private Q_SLOTS:
void qtbug15311doubleContentLength();
+ void qtbug18232gzipContentLengthZero();
+
void synchronousRequest_data();
void synchronousRequest();
#ifndef QT_NO_OPENSSL
@@ -5532,6 +5534,25 @@ void tst_QNetworkReply::qtbug15311doubleContentLength()
QCOMPARE(reply->readAll(), QByteArray("ABC"));
}
+void tst_QNetworkReply::qtbug18232gzipContentLengthZero()
+{
+ QByteArray response("HTTP/1.0 200 OK\r\nContent-Encoding: gzip\r\nContent-Length: 0\r\n\r\n");
+ MiniHttpServer server(response);
+ server.doClose = true;
+
+ QNetworkRequest request(QUrl("http://localhost:" + QString::number(server.serverPort())));
+ QNetworkReplyPtr reply = manager.get(request);
+
+ connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()));
+ QTestEventLoop::instance().enterLoop(10);
+ QVERIFY(!QTestEventLoop::instance().timeout());
+ QVERIFY(reply->isFinished());
+ QCOMPARE(reply->error(), QNetworkReply::NoError);
+ QCOMPARE(reply->size(), qint64(0));
+ QCOMPARE(reply->header(QNetworkRequest::ContentLengthHeader).toLongLong(), qint64(0));
+ QCOMPARE(reply->readAll(), QByteArray());
+}
+
void tst_QNetworkReply::synchronousRequest_data()
{
QTest::addColumn<QUrl>("url");