diff options
author | Lena Biliaieva <lena.biliaieva@qt.io> | 2024-03-15 00:32:14 +0200 |
---|---|---|
committer | Lena Biliaieva <lena.biliaieva@qt.io> | 2024-05-10 14:59:09 +0000 |
commit | 4b305df6f72ee30f00f1deadf1db2dab52904a90 (patch) | |
tree | a9bb3520f52767b319218706591145276b665a74 | |
parent | cc8659c5d90b4c8aceb32d0a60061ecef4baa3fb (diff) |
Replaced the usage of raw/cooked header methods with the QHttpHeaders API.
Task-number: QTBUG-107751
Change-Id: Ib9df199869ee66f2edcd8836093902264e10eb5f
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r-- | src/websockets/qwebsocket_p.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/websockets/qwebsocket_p.cpp b/src/websockets/qwebsocket_p.cpp index 21241a1..1553daa 100644 --- a/src/websockets/qwebsocket_p.cpp +++ b/src/websockets/qwebsocket_p.cpp @@ -334,7 +334,7 @@ QStringList QWebSocketPrivate::requestedSubProtocols() const { auto subprotocolsRequestedInRawHeader = [this]() { QStringList protocols; - QByteArray rawProtocols = m_request.rawHeader("Sec-WebSocket-Protocol"); + QByteArrayView rawProtocols = m_request.headers().value("Sec-WebSocket-Protocol"); QLatin1StringView rawProtocolsView(rawProtocols); const QStringList &optionsProtocols = m_options.subprotocols(); for (auto &&entry : rawProtocolsView.tokenize(u',', Qt::SkipEmptyParts)) { @@ -360,9 +360,7 @@ QWebSocket *QWebSocketPrivate::upgradeFrom(QTcpSocket *pTcpSocket, QWebSocket *pWebSocket = new QWebSocket(pTcpSocket, response.acceptedVersion(), parent); if (Q_LIKELY(pWebSocket)) { QNetworkRequest netRequest(request.requestUrl()); - const auto headers = request.headers().toListOfPairs(); - for (const auto &field : headers) - netRequest.setRawHeader(field.first, field.second); + netRequest.setHeaders(request.headers()); #ifndef QT_NO_SSL if (QSslSocket *sslSock = qobject_cast<QSslSocket *>(pTcpSocket)) pWebSocket->setSslConfiguration(sslSock->sslConfiguration()); @@ -1195,13 +1193,16 @@ void QWebSocketPrivate::processStateChanged(QAbstractSocket::SocketState socketS m_key = generateKey(); QList<QPair<QString, QString> > headers; - const auto headerList = m_request.rawHeaderList(); - for (const QByteArray &key : headerList) { + const auto h = m_request.headers(); + for (qsizetype i = 0; i < h.size(); ++i) { + const auto name = h.nameAt(i); + const auto value = h.valueAt(i); + // protocols handled separately below - if (key.compare("Sec-WebSocket-Protocol", Qt::CaseInsensitive) == 0) + if (name.compare("Sec-WebSocket-Protocol", Qt::CaseInsensitive) == 0) continue; - headers << qMakePair(QString::fromLatin1(key), - QString::fromLatin1(m_request.rawHeader(key))); + headers << qMakePair(QString::fromLatin1(name), + QString::fromLatin1(value)); } const QStringList subProtocols = requestedSubProtocols(); |