Merge pull request #16585 from Chocobo1/qstring

Use QString literals
This commit is contained in:
Chocobo1
2022-03-12 12:49:08 +08:00
committed by GitHub
40 changed files with 775 additions and 768 deletions

View File

@@ -82,8 +82,8 @@ void Connection::read()
Logger::instance()->addMessage(tr("Http request size exceeds limitation, closing socket. Limit: %1, IP: %2")
.arg(bufferLimit).arg(m_socket->peerAddress().toString()), Log::WARNING);
Response resp(413, "Payload Too Large");
resp.headers[HEADER_CONNECTION] = "close";
Response resp(413, u"Payload Too Large"_qs);
resp.headers[HEADER_CONNECTION] = u"close"_qs;
sendResponse(resp);
m_socket->close();
@@ -96,8 +96,8 @@ void Connection::read()
Logger::instance()->addMessage(tr("Bad Http request, closing socket. IP: %1")
.arg(m_socket->peerAddress().toString()), Log::WARNING);
Response resp(400, "Bad Request");
resp.headers[HEADER_CONNECTION] = "close";
Response resp(400, u"Bad Request"_qs);
resp.headers[HEADER_CONNECTION] = u"close"_qs;
sendResponse(resp);
m_socket->close();
@@ -110,10 +110,10 @@ void Connection::read()
Response resp = m_requestHandler->processRequest(result.request, env);
if (acceptsGzipEncoding(result.request.headers["accept-encoding"]))
resp.headers[HEADER_CONTENT_ENCODING] = "gzip";
if (acceptsGzipEncoding(result.request.headers[u"accept-encoding"_qs]))
resp.headers[HEADER_CONTENT_ENCODING] = u"gzip"_qs;
resp.headers[HEADER_CONNECTION] = "keep-alive";
resp.headers[HEADER_CONNECTION] = u"keep-alive"_qs;
sendResponse(resp);
m_receivedData = m_receivedData.mid(result.frameSize);
@@ -172,7 +172,7 @@ bool Connection::acceptsGzipEncoding(QString codings)
return false;
};
const QList<QStringView> list = QStringView(codings.remove(' ').remove('\t')).split(u',', Qt::SkipEmptyParts);
const QList<QStringView> list = QStringView(codings.remove(u' ').remove(u'\t')).split(u',', Qt::SkipEmptyParts);
if (list.isEmpty())
return false;

View File

@@ -60,7 +60,7 @@ namespace
bool parseHeaderLine(const QStringView line, HeaderMap &out)
{
// [rfc7230] 3.2. Header Fields
const int i = line.indexOf(':');
const int i = line.indexOf(u':');
if (i <= 0)
{
qWarning() << Q_FUNC_INFO << "invalid http header:" << line;
@@ -252,7 +252,7 @@ bool RequestParser::parsePostMessage(const QByteArray &data)
// [URL Standard] 5.1 application/x-www-form-urlencoded parsing
const QByteArray processedData = QByteArray(data).replace('+', ' ');
QListIterator<QStringPair> i(QUrlQuery(processedData).queryItems(QUrl::FullyDecoded));
QListIterator<QStringPair> i(QUrlQuery(QString::fromUtf8(processedData)).queryItems(QUrl::FullyDecoded));
while (i.hasNext())
{
const QStringPair pair = i.next();
@@ -330,7 +330,7 @@ bool RequestParser::parseFormData(const QByteArray &data)
for (const auto &directive : directives)
{
const int idx = directive.indexOf('=');
const int idx = directive.indexOf(u'=');
if (idx < 0)
continue;
@@ -356,7 +356,7 @@ bool RequestParser::parseFormData(const QByteArray &data)
}
else if (headersMap.contains(name))
{
m_request.posts[headersMap[name]] = payload;
m_request.posts[headersMap[name]] = QString::fromUtf8(payload);
}
else
{