mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-07-13 16:53:08 -07:00
Refactor HTTP query parsing
This commit is contained in:
parent
69d29af097
commit
bd8d70bf60
5 changed files with 25 additions and 40 deletions
|
@ -417,19 +417,8 @@ Http::Response WebApplication::processRequest(const Http::Request &request, cons
|
|||
m_params.clear();
|
||||
|
||||
if (m_request.method == Http::METHOD_GET) {
|
||||
// Parse GET parameters
|
||||
using namespace Utils::ByteArray;
|
||||
for (const QByteArray ¶m : asConst(splitToViews(m_request.query, "&"))) {
|
||||
const int sepPos = param.indexOf('=');
|
||||
if (sepPos <= 0) continue; // ignores params without name
|
||||
|
||||
const QByteArray nameComponent = midView(param, 0, sepPos);
|
||||
const QByteArray valueComponent = midView(param, (sepPos + 1));
|
||||
|
||||
const QString paramName = QString::fromUtf8(QByteArray::fromPercentEncoding(nameComponent).replace('+', ' '));
|
||||
const QString paramValue = QString::fromUtf8(QByteArray::fromPercentEncoding(valueComponent).replace('+', ' '));
|
||||
m_params[paramName] = paramValue;
|
||||
}
|
||||
for (auto iter = m_request.query.cbegin(); iter != m_request.query.cend(); ++iter)
|
||||
m_params[iter.key()] = QString::fromUtf8(iter.value());
|
||||
}
|
||||
else {
|
||||
m_params = m_request.posts;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue