mirror of https://github.com/qt/qthttpserver.git
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 <ivan.solovev@qt.io>
(cherry picked from commit f5f7368cb1
)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
19ee14c4fe
commit
6b3548b2eb
|
@ -57,12 +57,11 @@ static IdMap<T> tryLoadFromFile(const FromJsonFactory<T> &itemFactory, const QSt
|
|||
}
|
||||
|
||||
static QByteArray getValueFromHeader(const QList<QPair<QByteArray, QByteArray>> &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<QPair<QByteArray, QByteArray>>
|
|||
static std::optional<QString> getTokenFromRequest(const QHttpServerRequest &request)
|
||||
{
|
||||
std::optional<QString> token;
|
||||
if (auto bytes = getValueFromHeader(request.headers(), "TOKEN"); !bytes.isEmpty()) {
|
||||
if (auto bytes = getValueFromHeader(request.headers(), "token"); !bytes.isEmpty()) {
|
||||
token = bytes;
|
||||
}
|
||||
return token;
|
||||
|
|
Loading…
Reference in New Issue