diff options
author | Mate Barany <[email protected]> | 2025-02-19 15:49:45 +0100 |
---|---|---|
committer | Mate Barany <[email protected]> | 2025-02-20 16:12:19 +0100 |
commit | f6a5c7e011d24db22afa5a3bf92749b9bb9e9354 (patch) | |
tree | 0a5932471529e94b4cf7b26c31ac450c44da2e0b | |
parent | 1d6f71779f05df1af3daacd48f309cd92523152a (diff) |
Do not keep the headers and message body in case of temporary redirect
The implementation of GET requests with body (QTBUG-112871) keeps the
body after it has been redirected. However, in case of temporary
redirect (status code 307) this seems to be an incorrect behavior.
Reset the headers and the body in case of temporary redirect.
Pick-to: 6.9 6.8
Change-Id: I10be702b017a42cca27a37dfe2249da2f59c0328
Reviewed-by: MÃ¥rten Nordheim <[email protected]>
-rw-r--r-- | src/network/access/qnetworkaccessmanager.cpp | 4 | ||||
-rw-r--r-- | src/network/access/qnetworkreplyhttpimpl.cpp | 6 | ||||
-rw-r--r-- | tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp | 2 |
3 files changed, 6 insertions, 6 deletions
diff --git a/src/network/access/qnetworkaccessmanager.cpp b/src/network/access/qnetworkaccessmanager.cpp index f059fc15afb..b424b2f6720 100644 --- a/src/network/access/qnetworkaccessmanager.cpp +++ b/src/network/access/qnetworkaccessmanager.cpp @@ -796,7 +796,7 @@ QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request) \note A GET request with a message body is not cached. \note If the request is redirected, the message body will be kept only if the status code is - 307 or 308. + 308. */ QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request, QIODevice *data) @@ -814,7 +814,7 @@ QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request, QIODev \note A GET request with a message body is not cached. \note If the request is redirected, the message body will be kept only if the status code is - 307 or 308. + 308. */ QNetworkReply *QNetworkAccessManager::get(const QNetworkRequest &request, const QByteArray &data) diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp index 53b93fead66..5a0cd052782 100644 --- a/src/network/access/qnetworkreplyhttpimpl.cpp +++ b/src/network/access/qnetworkreplyhttpimpl.cpp @@ -1260,10 +1260,10 @@ void QNetworkReplyHttpImplPrivate::onRedirected(const QUrl &redirectUrl, int htt return; } - // If the original operation was a GET with a body and the status code is either - // 307 or 308 then keep the message body + // If the original operation was a GET with a body and the status code is + // 308 then keep the message body const bool getOperationKeepsBody = (operation == QNetworkAccessManager::GetOperation) - && (httpStatus == 307 || httpStatus == 308); + && httpStatus == 308; redirectRequest = createRedirectRequest(originalRequest, url, maxRedirectsRemaining); operation = getRedirectOperation(operation, httpStatus); diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index d7318ba56b3..a3a8aaad7f5 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -2310,7 +2310,7 @@ void tst_QNetworkReply::getWithBodyRedirected() QVERIFY(validateRedirectedResponseHeaders(reply)); // Verify that the message body has arrived to the server - if (status > 302) { + if (status > 307) { QVERIFY(server2.contentLength != 0); QCOMPARE(server2.contentLength, dataFromClientToServer.size()); QCOMPARE(server2.receivedData.right(dataFromClientToServer.size()), dataFromClientToServer); |