From 6bf640a7600132c02742a2581402e04f75b60962 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Thu, 4 Nov 2010 15:24:32 +0100 Subject: QNAM HTTP: Download last chunk properly when readBufferSize() limited Task-number: QTBUG-13431 Task-number: QTBUG-6276 Reviewed-by: ogoffart --- src/network/access/qhttpnetworkconnectionchannel.cpp | 5 +++-- tests/auto/qnetworkreply/tst_qnetworkreply.cpp | 9 +++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp index 4e5de53..02daa50 100644 --- a/src/network/access/qhttpnetworkconnectionchannel.cpp +++ b/src/network/access/qhttpnetworkconnectionchannel.cpp @@ -412,7 +412,9 @@ void QHttpNetworkConnectionChannel::_q_receiveReply() } case QHttpNetworkReplyPrivate::ReadingDataState: { QHttpNetworkReplyPrivate *replyPrivate = reply->d_func(); - if (replyPrivate->downstreamLimited && !replyPrivate->responseData.isEmpty() && replyPrivate->shouldEmitSignals()) { + if (socket->state() == QAbstractSocket::ConnectedState && + replyPrivate->downstreamLimited && !replyPrivate->responseData.isEmpty() && replyPrivate->shouldEmitSignals()) { + // (only do the following when still connected, not when we have already been disconnected and there is still data) // We already have some HTTP body data. We don't read more from the socket until // this is fetched by QHttpNetworkAccessHttpBackend. If we would read more, // we could not limit our read buffer usage. @@ -421,7 +423,6 @@ void QHttpNetworkConnectionChannel::_q_receiveReply() // to the read buffer maximum size, but we don't care since they should be small. return; } - if (!replyPrivate->isChunked() && !replyPrivate->autoDecompress && replyPrivate->bodyLength > 0) { // bulk files like images should fulfill these properties and diff --git a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp index 8850e6e..d21428b 100644 --- a/tests/auto/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/qnetworkreply/tst_qnetworkreply.cpp @@ -3457,11 +3457,11 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp_data() { QTest::addColumn("https"); QTest::addColumn("bufferSize"); - QTest::newRow("http, no limit") << false << 0; - QTest::newRow("http, limited") << false << 4096; + QTest::newRow("http+unlimited") << false << 0; + QTest::newRow("http+limited") << false << 4096; #ifndef QT_NO_OPENSSL - QTest::newRow("https, no limit") << true << 0; - QTest::newRow("https, limited") << true << 4096; + QTest::newRow("https+unlimited") << true << 0; + QTest::newRow("https+limited") << true << 4096; #endif } @@ -3534,6 +3534,7 @@ void tst_QNetworkReply::ioGetFromBuiltinHttp() const int allowedDeviation = 16; // TODO find out why the send rate is 13% faster currently const int minRate = rate * 1024 * (100-allowedDeviation) / 100; const int maxRate = rate * 1024 * (100+allowedDeviation) / 100; + qDebug() << minRate << "<="<< server.transferRate << "<=" << maxRate << "?"; QVERIFY(server.transferRate >= minRate); QVERIFY(server.transferRate <= maxRate); } -- cgit v0.12