mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-30 03:28:41 -07:00
Parse URL query string at application level
This commit is contained in:
parent
34295a78f2
commit
1aca3b0adc
6 changed files with 60 additions and 33 deletions
|
@ -40,14 +40,13 @@
|
|||
#include "base/utils/string.h"
|
||||
|
||||
using namespace Http;
|
||||
using namespace Utils::ByteArray;
|
||||
using QStringPair = QPair<QString, QString>;
|
||||
|
||||
namespace
|
||||
{
|
||||
const QByteArray EOH = QByteArray(CRLF).repeated(2);
|
||||
|
||||
using namespace Utils::ByteArray;
|
||||
|
||||
const QByteArray viewWithoutEndingWith(const QByteArray &in, const QByteArray &str)
|
||||
{
|
||||
if (in.endsWith(str))
|
||||
|
@ -181,15 +180,11 @@ bool RequestParser::parseRequestLine(const QString &line)
|
|||
m_request.method = match.captured(1);
|
||||
|
||||
// Request Target
|
||||
const QUrl url = QUrl::fromEncoded(match.captured(2).toLatin1());
|
||||
m_request.path = url.path();
|
||||
|
||||
// parse queries
|
||||
QListIterator<QStringPair> i(QUrlQuery(url).queryItems());
|
||||
while (i.hasNext()) {
|
||||
const QStringPair pair = i.next();
|
||||
m_request.gets[pair.first] = pair.second;
|
||||
}
|
||||
const QByteArray decodedUrl {QByteArray::fromPercentEncoding(match.captured(2).toLatin1())};
|
||||
const int sepPos = decodedUrl.indexOf('?');
|
||||
m_request.path = QString::fromUtf8(decodedUrl.constData(), (sepPos == -1 ? decodedUrl.size() : sepPos));
|
||||
if (sepPos >= 0)
|
||||
m_request.query = decodedUrl.mid(sepPos + 1);
|
||||
|
||||
// HTTP-version
|
||||
m_request.version = match.captured(3);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue