From 6b3548b2eb45b2bcd39bf30f30a3e3432830d4da Mon Sep 17 00:00:00 2001 From: Juha Vuolle Date: Fri, 5 Jan 2024 07:17:18 +0200 Subject: [PATCH] Make 'token' HTTP header name comparison case-insensitive HTTP header names are case-insensitive. With the new QHttpHeaders class in use at the client-side (the colorpaletteclient app in qtdoc), the request will contain a lower-cased 'token' header => change the server-side to ignore casing Task-number: QTBUG-114649 Change-Id: I69b52325017721c8d50fa3ea129802c93b2e521a Reviewed-by: Ivan Solovev (cherry picked from commit f5f7368cb1da675d0d57c05be2af5f6684a4c3ad) Reviewed-by: Qt Cherry-pick Bot --- examples/httpserver/colorpalette/utils.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/examples/httpserver/colorpalette/utils.h b/examples/httpserver/colorpalette/utils.h index b24271b..02f74d4 100644 --- a/examples/httpserver/colorpalette/utils.h +++ b/examples/httpserver/colorpalette/utils.h @@ -57,12 +57,11 @@ static IdMap tryLoadFromFile(const FromJsonFactory &itemFactory, const QSt } static QByteArray getValueFromHeader(const QList> &headers, - const QString &keyToFind) + QByteArrayView headerName) { for (const auto &[key, value] : headers) { - if (key == keyToFind) { + if (key.compare(headerName, Qt::CaseInsensitive) == 0) return value; - } } return QByteArray(); } @@ -70,7 +69,7 @@ static QByteArray getValueFromHeader(const QList> static std::optional getTokenFromRequest(const QHttpServerRequest &request) { std::optional token; - if (auto bytes = getValueFromHeader(request.headers(), "TOKEN"); !bytes.isEmpty()) { + if (auto bytes = getValueFromHeader(request.headers(), "token"); !bytes.isEmpty()) { token = bytes; } return token;