feat: update error handling for request target length and change response status to BAD_REQUEST
This commit is contained in:
parent
5b5cda23ce
commit
d507a6a022
@ -43,7 +43,7 @@ void HttpRequest::setState(State state)
|
|||||||
ServerConfig *serverConfig = getServerConfig();
|
ServerConfig *serverConfig = getServerConfig();
|
||||||
if (serverConfig == nullptr)
|
if (serverConfig == nullptr)
|
||||||
{
|
{
|
||||||
client_->getHttpResponse().setError(Http::StatusCode::NOT_FOUND);
|
client_->getHttpResponse().setError(Http::StatusCode::BAD_REQUEST);
|
||||||
state_ = State::ParseError;
|
state_ = State::ParseError;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -147,6 +147,13 @@ bool HttpRequest::parseBufferforRequestLine()
|
|||||||
}
|
}
|
||||||
method_ = parts[0];
|
method_ = parts[0];
|
||||||
target_ = parts[1];
|
target_ = parts[1];
|
||||||
|
if (target_.size() > 2048)
|
||||||
|
{
|
||||||
|
Log::warning("Request target too long: " + target_);
|
||||||
|
client_->getHttpResponse().setError(Http::StatusCode::URI_TOO_LONG);
|
||||||
|
state_ = State::ParseError; // Mark as complete to avoid further processing
|
||||||
|
return true;
|
||||||
|
}
|
||||||
httpVersion_ = parts[2];
|
httpVersion_ = parts[2];
|
||||||
Log::debug("Parsed Request Line: Method=" + method_ + " Target=" + target_ + " Version=" + httpVersion_);
|
Log::debug("Parsed Request Line: Method=" + method_ + " Target=" + target_ + " Version=" + httpVersion_);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user