From b31d90291314c0664ef5aae72225c213fc560b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 13 Sep 2022 13:02:42 +0200 Subject: 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 --- .../access/qnetworkreply/tst_qnetworkreply.cpp | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'tests/auto/network/access/qnetworkreply') diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index d2bcd9ec81..d0bc342afe 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -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() { -- cgit v1.2.3