diff options
author | Tasuku Suzuki <tasuku.suzuki@qbc.io> | 2019-05-07 13:35:22 +0900 |
---|---|---|
committer | Tasuku Suzuki <tasuku.suzuki@qbc.io> | 2019-05-09 15:14:33 +0000 |
commit | 26b4df2582eaeea3ea1adeef64311e67544c2dee (patch) | |
tree | 8e288c56497fe8fc370ed374396caace79543cf8 | |
parent | 9f7bf6654b0dc4f981a7cb88f2dc588e0c8e65db (diff) |
Change QString for headers in QHttpServerRequest to QByteArray
This is because QHttpServerResponder uses QByteArray for headers' key/
value.
Change-Id: I21b5af4d08e43ee58a1edc95b714c6da0ae10790
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
Reviewed-by: Mikhail Svetkin <mikhail.svetkin@qt.io>
-rw-r--r-- | src/httpserver/qabstracthttpserver.cpp | 4 | ||||
-rw-r--r-- | src/httpserver/qhttpserverrequest.cpp | 14 | ||||
-rw-r--r-- | src/httpserver/qhttpserverrequest.h | 2 | ||||
-rw-r--r-- | src/httpserver/qhttpserverrequest_p.h | 9 |
4 files changed, 15 insertions, 14 deletions
diff --git a/src/httpserver/qabstracthttpserver.cpp b/src/httpserver/qabstracthttpserver.cpp index c07e687..76b963c 100644 --- a/src/httpserver/qabstracthttpserver.cpp +++ b/src/httpserver/qabstracthttpserver.cpp @@ -108,11 +108,11 @@ void QAbstractHttpServerPrivate::handleReadyRead() if (requestPrivate->httpParser.upgrade) { // Upgrade const auto &headers = requestPrivate->headers; - const auto upgradeHash = requestPrivate->headerHash(QStringLiteral("upgrade")); + const auto upgradeHash = requestPrivate->headerHash(QByteArrayLiteral("upgrade")); const auto it = headers.find(upgradeHash); if (it != headers.end()) { #if defined(QT_WEBSOCKETS_LIB) - if (it.value().second.compare(QLatin1String("websocket"), Qt::CaseInsensitive) == 0) { + if (it.value().second.compare(QByteArrayLiteral("websocket"), Qt::CaseInsensitive) == 0) { static const auto signal = QMetaMethod::fromSignal( &QAbstractHttpServer::newWebSocketConnection); if (q->isSignalConnected(signal)) { diff --git a/src/httpserver/qhttpserverrequest.cpp b/src/httpserver/qhttpserverrequest.cpp index b92024a..7500ede 100644 --- a/src/httpserver/qhttpserverrequest.cpp +++ b/src/httpserver/qhttpserverrequest.cpp @@ -83,7 +83,7 @@ QHttpServerRequestPrivate::QHttpServerRequestPrivate() httpParser.data = this; } -QString QHttpServerRequestPrivate::header(const QString &key) const +QByteArray QHttpServerRequestPrivate::header(const QByteArray &key) const { return headers.value(headerHash(key)).second; } @@ -111,7 +111,7 @@ bool QHttpServerRequestPrivate::parse(QIODevice *socket) return true; } -uint QHttpServerRequestPrivate::headerHash(const QString &key) const +uint QHttpServerRequestPrivate::headerHash(const QByteArray &key) const { return qHash(key.toLower(), headersSeed); } @@ -183,8 +183,8 @@ int QHttpServerRequestPrivate::onHeaderField(http_parser *httpParser, const char qCDebug(lc) << httpParser << QString::fromUtf8(at, int(length)); auto i = instance(httpParser); i->state = State::OnHeaders; - const auto key = QString::fromUtf8(at, int(length)); - i->headers.insert(i->headerHash(key), qMakePair(key, QString())); + const auto key = QByteArray(at, int(length)); + i->headers.insert(i->headerHash(key), qMakePair(key, QByteArray())); i->lastHeader = key; return 0; } @@ -195,9 +195,9 @@ int QHttpServerRequestPrivate::onHeaderValue(http_parser *httpParser, const char auto i = instance(httpParser); i->state = State::OnHeaders; Q_ASSERT(!i->lastHeader.isEmpty()); - const auto value = QString::fromUtf8(at, int(length)); + const auto value = QByteArray(at, int(length)); i->headers[i->headerHash(i->lastHeader)] = qMakePair(i->lastHeader, value); - if (i->lastHeader.compare(QStringLiteral("host"), Qt::CaseInsensitive) == 0) + if (i->lastHeader.compare(QByteArrayLiteral("host"), Qt::CaseInsensitive) == 0) parseUrl(at, length, true, &i->url); #if defined(QT_DEBUG) i->lastHeader.clear(); @@ -261,7 +261,7 @@ QHttpServerRequest::QHttpServerRequest(const QHttpServerRequest &other) : QHttpServerRequest::~QHttpServerRequest() {} -QString QHttpServerRequest::value(const QString &key) const +QByteArray QHttpServerRequest::value(const QByteArray &key) const { return d->headers.value(d->headerHash(key)).second; } diff --git a/src/httpserver/qhttpserverrequest.h b/src/httpserver/qhttpserverrequest.h index c0afbce..3d1210c 100644 --- a/src/httpserver/qhttpserverrequest.h +++ b/src/httpserver/qhttpserverrequest.h @@ -80,7 +80,7 @@ public: Q_DECLARE_FLAGS(Methods, Method) Q_FLAG(Methods) - QString value(const QString &key) const; + QByteArray value(const QByteArray &key) const; QUrl url() const; QUrlQuery query() const; Method method() const; diff --git a/src/httpserver/qhttpserverrequest_p.h b/src/httpserver/qhttpserverrequest_p.h index 24f077a..04b3e79 100644 --- a/src/httpserver/qhttpserverrequest_p.h +++ b/src/httpserver/qhttpserverrequest_p.h @@ -58,6 +58,7 @@ class QHttpServerRequestPrivate : public QSharedData public: QHttpServerRequestPrivate(); + quint16 port = 0; enum class State { NotStarted, OnMessageBegin, @@ -76,13 +77,13 @@ public: http_parser httpParser; - QString header(const QString &key) const; + QByteArray header(const QByteArray &key) const; bool parse(QIODevice *socket); - QString lastHeader; - QHash<uint, QPair<QString, QString>> headers; + QByteArray lastHeader; + QMap<uint, QPair<QByteArray, QByteArray>> headers; const uint headersSeed = uint(qGlobalQHashSeed()); - uint headerHash(const QString &key) const; + uint headerHash(const QByteArray &key) const; void clear(); |