summaryrefslogtreecommitdiffstats
path: root/src/network/access/qhttpnetworkreply.cpp
diff options
context:
space:
mode:
authorMartin Petersson <Martin.Petersson@nokia.com>2012-03-27 10:29:57 +0200
committerQt by Nokia <qt-info@nokia.com>2012-03-28 13:22:11 +0200
commitb754deb055db1b3d74f4ecaed38fa7e59fdcd877 (patch)
treea73dbe6e68b88bf175e2925e834d6051eb6a90aa /src/network/access/qhttpnetworkreply.cpp
parentb2d205b58755a772557a440ec55bb9018fbcb35a (diff)
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 Change-Id: Ida40593fec8788bff713a31cfe6a7c2d86354a91 Reviewed-by: Jonas Gastal <jgastal@profusion.mobi> Reviewed-by: Shane Kearns <shane.kearns@accenture.com>
Diffstat (limited to 'src/network/access/qhttpnetworkreply.cpp')
-rw-r--r--src/network/access/qhttpnetworkreply.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/network/access/qhttpnetworkreply.cpp b/src/network/access/qhttpnetworkreply.cpp
index 85463ee210..39204163f2 100644
--- a/src/network/access/qhttpnetworkreply.cpp
+++ b/src/network/access/qhttpnetworkreply.cpp
@@ -257,6 +257,7 @@ QHttpNetworkReplyPrivate::QHttpNetworkReplyPrivate(const QUrl &newUrl)
chunkedTransferEncoding(false),
connectionCloseEnabled(true),
forceConnectionCloseEnabled(false),
+ lastChunkRead(false),
currentChunkSize(0), currentChunkRead(0), connection(0),
autoDecompress(false), responseData(), requestIsPrepared(false)
,pipeliningUsed(false), downstreamLimited(false)
@@ -277,6 +278,7 @@ void QHttpNetworkReplyPrivate::clearHttpLayerInformation()
totalProgress = 0;
currentChunkSize = 0;
currentChunkRead = 0;
+ lastChunkRead = false;
connectionCloseEnabled = true;
#ifndef QT_NO_COMPRESS
if (autoDecompress)
@@ -721,7 +723,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;
@@ -744,8 +746,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;
}