From be152f45c9db11f55c8595145bdca3abd7e1b77f Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 10 May 2020 03:00:56 +0800 Subject: [PATCH] Define and use Http::HeaderMap type --- src/base/http/requestparser.cpp | 4 ++-- src/base/http/types.h | 8 ++++---- src/webui/webapplication.cpp | 1 + 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/base/http/requestparser.cpp b/src/base/http/requestparser.cpp index ef7a94c30..e6e1853f6 100644 --- a/src/base/http/requestparser.cpp +++ b/src/base/http/requestparser.cpp @@ -57,7 +57,7 @@ namespace return in; } - bool parseHeaderLine(const QString &line, QStringMap &out) + bool parseHeaderLine(const QString &line, HeaderMap &out) { // [rfc7230] 3.2. Header Fields const int i = line.indexOf(':'); @@ -287,7 +287,7 @@ bool RequestParser::parseFormData(const QByteArray &data) const QString headers = QString::fromLatin1(list[0]); const QByteArray payload = viewWithoutEndingWith(list[1], CRLF); - QStringMap headersMap; + HeaderMap headersMap; const QVector headerLines = headers.splitRef(CRLF, QString::SkipEmptyParts); for (const auto &line : headerLines) { if (line.trimmed().startsWith(HEADER_CONTENT_DISPOSITION, Qt::CaseInsensitive)) { diff --git a/src/base/http/types.h b/src/base/http/types.h index e6d6d153c..0c1cb2f14 100644 --- a/src/base/http/types.h +++ b/src/base/http/types.h @@ -34,8 +34,6 @@ #include #include -#include "base/types.h" - namespace Http { const char METHOD_GET[] = "GET"; @@ -98,12 +96,14 @@ namespace Http QString value; }; + using HeaderMap = QMap; //
+ struct Request { QString version; QString method; QString path; - QStringMap headers; + HeaderMap headers; QHash query; QHash posts; QVector files; @@ -118,7 +118,7 @@ namespace Http struct Response { ResponseStatus status; - QStringMap headers; + HeaderMap headers; QByteArray content; Response(uint code = 200, const QString &text = "OK") diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index 4eaa495f9..021c7a1bd 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -46,6 +46,7 @@ #include "base/http/httperror.h" #include "base/logger.h" #include "base/preferences.h" +#include "base/types.h" #include "base/utils/bytearray.h" #include "base/utils/fs.h" #include "base/utils/misc.h"