mirror of
https://github.com/QuasarApp/qthttpserver.git
synced 2025-05-10 08:29:45 +00:00
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>
This commit is contained in:
parent
9f7bf6654b
commit
26b4df2582
@ -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)) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user