mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 13:23:34 -07:00
Response proper error status for invalid request methods
This commit is contained in:
parent
e8f5a3b44e
commit
cb0c09769f
3 changed files with 16 additions and 2 deletions
|
@ -106,6 +106,19 @@ void Connection::read()
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
case RequestParser::ParseStatus::BadMethod:
|
||||||
|
{
|
||||||
|
LogMsg(tr("Bad Http request method, closing socket. IP: %1. Method: \"%2\"")
|
||||||
|
.arg(m_socket->peerAddress().toString(), result.request.method), Log::WARNING);
|
||||||
|
|
||||||
|
Response resp(501, u"Not Implemented"_s);
|
||||||
|
resp.headers[HEADER_CONNECTION] = u"close"_s;
|
||||||
|
|
||||||
|
sendResponse(resp);
|
||||||
|
m_socket->close();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
|
||||||
case RequestParser::ParseStatus::BadRequest:
|
case RequestParser::ParseStatus::BadRequest:
|
||||||
{
|
{
|
||||||
LogMsg(tr("Bad Http request, closing socket. IP: %1")
|
LogMsg(tr("Bad Http request, closing socket. IP: %1")
|
||||||
|
|
|
@ -103,6 +103,7 @@ RequestParser::ParseResult RequestParser::doParse(const QByteArray &data)
|
||||||
// handle supported methods
|
// handle supported methods
|
||||||
if ((m_request.method == HEADER_REQUEST_METHOD_GET) || (m_request.method == HEADER_REQUEST_METHOD_HEAD))
|
if ((m_request.method == HEADER_REQUEST_METHOD_GET) || (m_request.method == HEADER_REQUEST_METHOD_HEAD))
|
||||||
return {ParseStatus::OK, m_request, headerLength};
|
return {ParseStatus::OK, m_request, headerLength};
|
||||||
|
|
||||||
if (m_request.method == HEADER_REQUEST_METHOD_POST)
|
if (m_request.method == HEADER_REQUEST_METHOD_POST)
|
||||||
{
|
{
|
||||||
const auto parseContentLength = [this]() -> int
|
const auto parseContentLength = [this]() -> int
|
||||||
|
@ -146,8 +147,7 @@ RequestParser::ParseResult RequestParser::doParse(const QByteArray &data)
|
||||||
return {ParseStatus::OK, m_request, (headerLength + contentLength)};
|
return {ParseStatus::OK, m_request, (headerLength + contentLength)};
|
||||||
}
|
}
|
||||||
|
|
||||||
qWarning() << Q_FUNC_INFO << "unsupported request method: " << m_request.method;
|
return {ParseStatus::BadMethod, m_request, 0};
|
||||||
return {ParseStatus::BadRequest, Request(), 0}; // TODO: SHOULD respond "501 Not Implemented"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RequestParser::parseStartLines(const QStringView data)
|
bool RequestParser::parseStartLines(const QStringView data)
|
||||||
|
|
|
@ -41,6 +41,7 @@ namespace Http
|
||||||
{
|
{
|
||||||
OK,
|
OK,
|
||||||
Incomplete,
|
Incomplete,
|
||||||
|
BadMethod,
|
||||||
BadRequest
|
BadRequest
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue