summaryrefslogtreecommitdiffstats
path: root/src/network/access/qhttpnetworkrequest.cpp
diff options
context:
space:
mode:
authorMårten Nordheim <marten.nordheim@qt.io>2025-07-17 12:38:07 +0200
committerMårten Nordheim <marten.nordheim@qt.io>2025-10-27 22:43:31 +0000
commit860ec20850969dd7d940a1e90b2792f46a5b3917 (patch)
tree9f82044db77695ca6baa6b9344651725ff93d408 /src/network/access/qhttpnetworkrequest.cpp
parent763f19151cc31ca1ba4912e0828359be5dba89e8 (diff)
Titlecase HTTP/1 headers
Following the addition of QHttpHeaders and the relevant patches to port existing code to use it, we decided it was OK to start sending all header names as lower-case. This had the unfortunate side-effect that certain HTTP/1 servers did Case-Sensitive comparisons on the header name, causing them to stop functioning with Qt. To restore compatibility with these, we title-case them at the boundary to HTTP/1. Simply upper-case the first letter and the letter immediately following a dash. Ignores specific casing of raw headers, e.g. MyHeader turns into Myheader, and a lower-case header would still be titlecased. Fixes: QTBUG-137203 Pick-to: 6.10 6.8 Change-Id: Ic7ccf95eb7aa5cba355fc5933b7b9c86600821bb Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Juha Vuolle <juha.vuolle@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/network/access/qhttpnetworkrequest.cpp')
-rw-r--r--src/network/access/qhttpnetworkrequest.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/network/access/qhttpnetworkrequest.cpp b/src/network/access/qhttpnetworkrequest.cpp
index 07f36df851c..c9d2b6f7b88 100644
--- a/src/network/access/qhttpnetworkrequest.cpp
+++ b/src/network/access/qhttpnetworkrequest.cpp
@@ -5,6 +5,8 @@
#include "qhttpnetworkrequest_p.h"
#include "private/qnoncontiguousbytedevice_p.h"
+#include <QtCore/private/qtools_p.h>
+
QT_BEGIN_NAMESPACE
QT_IMPL_METATYPE_EXTERN(QHttpNetworkRequest)
@@ -129,8 +131,19 @@ QByteArray QHttpNetworkRequestPrivate::header(const QHttpNetworkRequest &request
ba += QByteArray::number(request.minorVersion());
ba += "\r\n";
+ constexpr auto titlecase = [](QByteArrayView name) {
+ std::string n;
+ n.reserve(size_t(name.size()));
+ bool toUpperNext = true;
+ for (char c : name) {
+ n += toUpperNext ? QtMiscUtils::toAsciiUpper(c) : c;
+ toUpperNext = c == '-';
+ }
+ return n;
+ };
+
for (qsizetype i = 0; i < headers.size(); ++i) {
- ba += headers.nameAt(i);
+ ba += titlecase(headers.nameAt(i));
ba += ": ";
ba += headers.valueAt(i);
ba += "\r\n";