mirror of
https://github.com/QuasarApp/qthttpserver.git
synced 2025-05-17 03:49:38 +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
|
if (requestPrivate->httpParser.upgrade) { // Upgrade
|
||||||
const auto &headers = requestPrivate->headers;
|
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);
|
const auto it = headers.find(upgradeHash);
|
||||||
if (it != headers.end()) {
|
if (it != headers.end()) {
|
||||||
#if defined(QT_WEBSOCKETS_LIB)
|
#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(
|
static const auto signal = QMetaMethod::fromSignal(
|
||||||
&QAbstractHttpServer::newWebSocketConnection);
|
&QAbstractHttpServer::newWebSocketConnection);
|
||||||
if (q->isSignalConnected(signal)) {
|
if (q->isSignalConnected(signal)) {
|
||||||
|
@ -83,7 +83,7 @@ QHttpServerRequestPrivate::QHttpServerRequestPrivate()
|
|||||||
httpParser.data = this;
|
httpParser.data = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QHttpServerRequestPrivate::header(const QString &key) const
|
QByteArray QHttpServerRequestPrivate::header(const QByteArray &key) const
|
||||||
{
|
{
|
||||||
return headers.value(headerHash(key)).second;
|
return headers.value(headerHash(key)).second;
|
||||||
}
|
}
|
||||||
@ -111,7 +111,7 @@ bool QHttpServerRequestPrivate::parse(QIODevice *socket)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint QHttpServerRequestPrivate::headerHash(const QString &key) const
|
uint QHttpServerRequestPrivate::headerHash(const QByteArray &key) const
|
||||||
{
|
{
|
||||||
return qHash(key.toLower(), headersSeed);
|
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));
|
qCDebug(lc) << httpParser << QString::fromUtf8(at, int(length));
|
||||||
auto i = instance(httpParser);
|
auto i = instance(httpParser);
|
||||||
i->state = State::OnHeaders;
|
i->state = State::OnHeaders;
|
||||||
const auto key = QString::fromUtf8(at, int(length));
|
const auto key = QByteArray(at, int(length));
|
||||||
i->headers.insert(i->headerHash(key), qMakePair(key, QString()));
|
i->headers.insert(i->headerHash(key), qMakePair(key, QByteArray()));
|
||||||
i->lastHeader = key;
|
i->lastHeader = key;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -195,9 +195,9 @@ int QHttpServerRequestPrivate::onHeaderValue(http_parser *httpParser, const char
|
|||||||
auto i = instance(httpParser);
|
auto i = instance(httpParser);
|
||||||
i->state = State::OnHeaders;
|
i->state = State::OnHeaders;
|
||||||
Q_ASSERT(!i->lastHeader.isEmpty());
|
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);
|
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);
|
parseUrl(at, length, true, &i->url);
|
||||||
#if defined(QT_DEBUG)
|
#if defined(QT_DEBUG)
|
||||||
i->lastHeader.clear();
|
i->lastHeader.clear();
|
||||||
@ -261,7 +261,7 @@ QHttpServerRequest::QHttpServerRequest(const QHttpServerRequest &other) :
|
|||||||
QHttpServerRequest::~QHttpServerRequest()
|
QHttpServerRequest::~QHttpServerRequest()
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QString QHttpServerRequest::value(const QString &key) const
|
QByteArray QHttpServerRequest::value(const QByteArray &key) const
|
||||||
{
|
{
|
||||||
return d->headers.value(d->headerHash(key)).second;
|
return d->headers.value(d->headerHash(key)).second;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ public:
|
|||||||
Q_DECLARE_FLAGS(Methods, Method)
|
Q_DECLARE_FLAGS(Methods, Method)
|
||||||
Q_FLAG(Methods)
|
Q_FLAG(Methods)
|
||||||
|
|
||||||
QString value(const QString &key) const;
|
QByteArray value(const QByteArray &key) const;
|
||||||
QUrl url() const;
|
QUrl url() const;
|
||||||
QUrlQuery query() const;
|
QUrlQuery query() const;
|
||||||
Method method() const;
|
Method method() const;
|
||||||
|
@ -58,6 +58,7 @@ class QHttpServerRequestPrivate : public QSharedData
|
|||||||
public:
|
public:
|
||||||
QHttpServerRequestPrivate();
|
QHttpServerRequestPrivate();
|
||||||
|
|
||||||
|
quint16 port = 0;
|
||||||
enum class State {
|
enum class State {
|
||||||
NotStarted,
|
NotStarted,
|
||||||
OnMessageBegin,
|
OnMessageBegin,
|
||||||
@ -76,13 +77,13 @@ public:
|
|||||||
|
|
||||||
http_parser httpParser;
|
http_parser httpParser;
|
||||||
|
|
||||||
QString header(const QString &key) const;
|
QByteArray header(const QByteArray &key) const;
|
||||||
bool parse(QIODevice *socket);
|
bool parse(QIODevice *socket);
|
||||||
|
|
||||||
QString lastHeader;
|
QByteArray lastHeader;
|
||||||
QHash<uint, QPair<QString, QString>> headers;
|
QMap<uint, QPair<QByteArray, QByteArray>> headers;
|
||||||
const uint headersSeed = uint(qGlobalQHashSeed());
|
const uint headersSeed = uint(qGlobalQHashSeed());
|
||||||
uint headerHash(const QString &key) const;
|
uint headerHash(const QByteArray &key) const;
|
||||||
|
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user