summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Petersson <Martin.Petersson@nokia.com>2012-03-28 16:12:43 +0200
committerPasi Pentikäinen <ext-pasi.a.pentikainen@nokia.com>2012-04-10 18:41:13 +0200
commitaf7d398158e5be1e809df1fe4feb074d7d3eafb6 (patch)
treef8429b4ced7906295f606bf6afbaf00402c7b480
parent722efd5f72258bc77868642fa5f9276d3ab2b3f6 (diff)
downloadqt4-tools-af7d398158e5be1e809df1fe4feb074d7d3eafb6.tar.gz
QNam: try to read the last CRLF when chunked encoding is used.
When chunked encoding is used we should try to read the last CRLF after the last zero-lenght chunk, with chunk size coded as 0. Task-number: QTBUG-19480 Task-number: QTBUG-20924 Task-number: ou1cimx1#991682 Change-Id: I39c85f45c329246d6c53c29ba1511039b2503e13 Reviewed-by: Shane Kearns <shane.kearns@accenture.com> (cherry picked from commit 2cfc2a2e9af97a2799e76868e4c6b302d55266e0) Reviewed-by: Pasi Pentikäinen <ext-pasi.a.pentikainen@nokia.com>
-rw-r--r--src/network/access/qhttpnetworkreply.cpp23
-rw-r--r--src/network/access/qhttpnetworkreply_p.h1
2 files changed, 21 insertions, 3 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index 3dc8b2fe7b..259c001c39 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -252,6 +252,7 @@ QHttpNetworkReplyPrivate::QHttpNetworkReplyPrivate(const QUrl &newUrl)
chunkedTransferEncoding(false),
connectionCloseEnabled(true),
forceConnectionCloseEnabled(false),
+ lastChunkRead(false),
currentChunkSize(0), currentChunkRead(0), connection(0), initInflate(false),
autoDecompress(false), responseData(), requestIsPrepared(false)
,pipeliningUsed(false), downstreamLimited(false)
@@ -272,6 +273,7 @@ void QHttpNetworkReplyPrivate::clearHttpLayerInformation()
totalProgress = 0;
currentChunkSize = 0;
currentChunkRead = 0;
+ lastChunkRead = false;
connectionCloseEnabled = true;
#ifndef QT_NO_COMPRESS
if (initInflate)
@@ -770,7 +772,7 @@ qint64 QHttpNetworkReplyPrivate::readReplyBodyChunked(QAbstractSocket *socket, Q
{
qint64 bytes = 0;
while (socket->bytesAvailable()) {
- if (currentChunkRead >= currentChunkSize) {
+ if (!lastChunkRead && currentChunkRead >= currentChunkSize) {
// For the first chunk and when we're done with a chunk
currentChunkSize = 0;
currentChunkRead = 0;
@@ -793,8 +795,23 @@ qint64 QHttpNetworkReplyPrivate::readReplyBodyChunked(QAbstractSocket *socket, Q
break;
}
// if the chunk size is 0, end of the stream
- if (currentChunkSize == 0) {
- state = AllDoneState;
+ if (currentChunkSize == 0 || lastChunkRead) {
+ lastChunkRead = true;
+ // try to read the "\r\n" after the chunk
+ char crlf[2];
+ qint64 haveRead = socket->read(crlf, 2);
+ if (haveRead > 0)
+ bytes += haveRead;
+
+ if ((haveRead == 2 && crlf[0] == '\r' && crlf[1] == '\n') || (haveRead == 1 && crlf[0] == '\n'))
+ state = AllDoneState;
+ else if (haveRead == 1 && crlf[0] == '\r')
+ break; // Still waiting for the last \n
+ else if (haveRead > 0) {
+ // If we read something else then CRLF, we need to close the channel.
+ forceConnectionCloseEnabled = true;
+ state = AllDoneState;
+ }
break;
}
diff --git a/src/network/access/qhttpnetworkreply_p.h b/src/network/access/qhttpnetworkreply_p.h
index de6c0d2f44..ab3ee9aee4 100644
--- a/src/network/access/qhttpnetworkreply_p.h
+++ b/src/network/access/qhttpnetworkreply_p.h
@@ -233,6 +233,7 @@ public:
bool chunkedTransferEncoding;
bool connectionCloseEnabled;
bool forceConnectionCloseEnabled;
+ bool lastChunkRead;
qint64 currentChunkSize;
qint64 currentChunkRead;
QPointer<QHttpNetworkConnection> connection;