Http: Don't clear (de)compressed data on error
Some errors, such as 404, may still present useful data. As opposed to errors such as 'RemoteDisconnected'. So, just keep the data around until the reply is deleted. Pick-to: 6.4 Fixes: QTBUG-106573 Change-Id: I6c86b5a55a45f837ea9b42559d88cd3e0ac2fa5c Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>bb10
parent
3df618b8d9
commit
b31d902913
|
|
@ -326,6 +326,7 @@ qint64 QNetworkReplyHttpImpl::readData(char* data, qint64 maxlen)
|
|||
d->error(QNetworkReplyImpl::NetworkError::UnknownContentError,
|
||||
QCoreApplication::translate("QHttp", "Decompression failed: %1")
|
||||
.arg(d->decompressHelper.errorString()));
|
||||
d->decompressHelper.clear();
|
||||
return -1;
|
||||
}
|
||||
if (d->cacheSaveDevice) {
|
||||
|
|
@ -1050,6 +1051,7 @@ void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d)
|
|||
error(QNetworkReplyImpl::NetworkError::UnknownContentError,
|
||||
QCoreApplication::translate("QHttp", "Decompression failed: %1")
|
||||
.arg(decompressHelper.errorString()));
|
||||
decompressHelper.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1069,6 +1071,7 @@ void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d)
|
|||
error(QNetworkReplyImpl::NetworkError::UnknownContentError,
|
||||
QCoreApplication::translate("QHttp",
|
||||
"Data downloaded is too large to store"));
|
||||
decompressHelper.clear();
|
||||
return;
|
||||
}
|
||||
d.resize(nextSize);
|
||||
|
|
@ -1077,6 +1080,7 @@ void QNetworkReplyHttpImplPrivate::replyDownloadData(QByteArray d)
|
|||
error(QNetworkReplyImpl::NetworkError::UnknownContentError,
|
||||
QCoreApplication::translate("QHttp", "Decompression failed: %1")
|
||||
.arg(decompressHelper.errorString()));
|
||||
decompressHelper.clear();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -2115,9 +2119,6 @@ void QNetworkReplyHttpImplPrivate::error(QNetworkReplyImpl::NetworkError code, c
|
|||
return;
|
||||
}
|
||||
|
||||
if (decompressHelper.isValid())
|
||||
decompressHelper.clear(); // Just get rid of any data that might be stored
|
||||
|
||||
errorCode = code;
|
||||
q->setErrorString(errorMessage);
|
||||
|
||||
|
|
|
|||
|
|
@ -512,6 +512,8 @@ private Q_SLOTS:
|
|||
void contentEncodingError_data();
|
||||
void contentEncodingError();
|
||||
void compressedReadyRead();
|
||||
void notFoundWithCompression_data();
|
||||
void notFoundWithCompression();
|
||||
|
||||
// NOTE: This test must be last!
|
||||
void parentingRepliesToTheApp();
|
||||
|
|
@ -9929,6 +9931,31 @@ void tst_QNetworkReply::compressedReadyRead()
|
|||
QCOMPARE(received, expected);
|
||||
}
|
||||
|
||||
void tst_QNetworkReply::notFoundWithCompression_data()
|
||||
{
|
||||
contentEncoding_data();
|
||||
}
|
||||
|
||||
void tst_QNetworkReply::notFoundWithCompression()
|
||||
{
|
||||
QFETCH(QByteArray, encoding);
|
||||
QFETCH(QByteArray, body);
|
||||
QString header("HTTP/1.0 404 OK\r\nContent-Encoding: %1\r\nContent-Length: %2\r\n\r\n");
|
||||
header = header.arg(encoding, QString::number(body.size()));
|
||||
|
||||
MiniHttpServer server(header.toLatin1() + body);
|
||||
|
||||
QNetworkRequest request(
|
||||
QUrl(QLatin1String("http://localhost:%1").arg(QString::number(server.serverPort()))));
|
||||
QNetworkReplyPtr reply(manager.get(request));
|
||||
|
||||
QTRY_VERIFY2_WITH_TIMEOUT(reply->isFinished(), qPrintable(reply->errorString()), 15000);
|
||||
QCOMPARE(reply->error(), QNetworkReply::ContentNotFoundError);
|
||||
|
||||
QFETCH(QByteArray, expected);
|
||||
QCOMPARE(reply->readAll(), expected);
|
||||
}
|
||||
|
||||
// NOTE: This test must be last testcase in tst_qnetworkreply!
|
||||
void tst_QNetworkReply::parentingRepliesToTheApp()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue