summaryrefslogtreecommitdiffstats
path: root/src/network/access/qnetworkreplyhttpimpl.cpp
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2025-08-01 16:38:56 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2025-09-01 14:23:55 +0000
commit9da6fd4fab1a89a745d8793797df304ed37577a1 (patch)
tree192f599ccc98b73c6102474d100494f6eef4933a /src/network/access/qnetworkreplyhttpimpl.cpp
parentbb40f641f2f80ff5a01bf49d50470d6868cbf701 (diff)
HTTP: remap Custom operations to known methods
Some users are doing "CustomOperation" and then specifying GET, PUT, etc To make it a bit easier to work with we should remap it to the known methods. Especially since it makes an impact on caching and redirections. [ChangeLog][QtNetwork][QNetworkAccessManager] Using CustomOperation with GET, PUT, POST, DELETE or HEAD will now be remapped to the corresponding operation. This might affect caching and redirection handling. Change-Id: I21b2ee950e73c8832a6c39accbb8c9acdae42a6e Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/network/access/qnetworkreplyhttpimpl.cpp')
-rw-r--r--src/network/access/qnetworkreplyhttpimpl.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/network/access/qnetworkreplyhttpimpl.cpp b/src/network/access/qnetworkreplyhttpimpl.cpp
index 61cc2f7038b..f680950701c 100644
--- a/src/network/access/qnetworkreplyhttpimpl.cpp
+++ b/src/network/access/qnetworkreplyhttpimpl.cpp
@@ -138,6 +138,28 @@ static QHash<QByteArray, QByteArray> parseHttpOptionHeader(QByteArrayView header
}
}
+// If the user specified CustomOperation we try to remap the operation to a known
+// operation. This is useful because we treat the operations differently,
+// ie for caching or redirection
+static auto remapCustom(QNetworkAccessManager::Operation operation, const QNetworkRequest &req)
+{
+ if (operation == QNetworkAccessManager::CustomOperation) {
+ const QByteArray customVerb = req.attribute(QNetworkRequest::CustomVerbAttribute)
+ .toByteArray();
+ if (customVerb.compare("get", Qt::CaseInsensitive) == 0)
+ return QNetworkAccessManager::GetOperation;
+ if (customVerb.compare("head", Qt::CaseInsensitive) == 0)
+ return QNetworkAccessManager::HeadOperation;
+ if (customVerb.compare("delete", Qt::CaseInsensitive) == 0)
+ return QNetworkAccessManager::DeleteOperation;
+ if (customVerb.compare("put", Qt::CaseInsensitive) == 0)
+ return QNetworkAccessManager::PutOperation;
+ if (customVerb.compare("post", Qt::CaseInsensitive) == 0)
+ return QNetworkAccessManager::PostOperation;
+ }
+ return operation;
+}
+
QNetworkReplyHttpImpl::QNetworkReplyHttpImpl(QNetworkAccessManager* const manager,
const QNetworkRequest& request,
QNetworkAccessManager::Operation& operation,
@@ -150,7 +172,7 @@ QNetworkReplyHttpImpl::QNetworkReplyHttpImpl(QNetworkAccessManager* const manage
d->managerPrivate = manager->d_func();
d->request = request;
d->originalRequest = request;
- d->operation = operation;
+ d->operation = remapCustom(operation, request);
d->outgoingData = outgoingData;
d->url = request.url();
#ifndef QT_NO_SSL
@@ -636,12 +658,8 @@ void QNetworkReplyHttpImplPrivate::maybeDropUploadDevice(const QNetworkRequest &
case QNetworkAccessManager::CustomOperation: {
const QByteArray customVerb = newHttpRequest.attribute(QNetworkRequest::CustomVerbAttribute)
.toByteArray();
- if (customVerb.compare("get", Qt::CaseInsensitive) != 0
- && customVerb.compare("head", Qt::CaseInsensitive) != 0
- && customVerb.compare("connect", Qt::CaseInsensitive) != 0
- && customVerb.compare("delete", Qt::CaseInsensitive) != 0) {
+ if (customVerb.compare("connect", Qt::CaseInsensitive) != 0)
return true; // Trust user => content-length 0 is presumably okay!
- }
// else:
[[fallthrough]];
}