server : fix check for URI length to prevent incorrect HTTP 414 errors
This commit is contained in:
parent
19d3c8293b
commit
31cfa39811
1 changed files with 12 additions and 2 deletions
|
@ -7157,16 +7157,26 @@ Server::process_request(Stream &strm, const std::string &remote_addr,
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
auto req_line = line_reader.ptr();
|
||||||
|
|
||||||
|
// Extract URI from the request line
|
||||||
|
std::string method, uri, version;
|
||||||
|
std::istringstream iss(req_line);
|
||||||
|
iss >> method >> uri >> version;
|
||||||
|
|
||||||
// Check if the request URI doesn't exceed the limit
|
// Check if the request URI doesn't exceed the limit
|
||||||
if (line_reader.size() > CPPHTTPLIB_REQUEST_URI_MAX_LENGTH) {
|
if (uri.size() > CPPHTTPLIB_REQUEST_URI_MAX_LENGTH) {
|
||||||
Headers dummy;
|
Headers dummy;
|
||||||
detail::read_headers(strm, dummy);
|
detail::read_headers(strm, dummy);
|
||||||
res.status = StatusCode::UriTooLong_414;
|
res.status = StatusCode::UriTooLong_414;
|
||||||
|
res.body = "Request URI too long: " + uri;
|
||||||
|
res.set_header("Content-Type", "text/plain");
|
||||||
|
|
||||||
return write_response(strm, close_connection, req, res);
|
return write_response(strm, close_connection, req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request line and headers
|
// Request line and headers
|
||||||
if (!parse_request_line(line_reader.ptr(), req) ||
|
if (!parse_request_line(req_line, req) ||
|
||||||
!detail::read_headers(strm, req.headers)) {
|
!detail::read_headers(strm, req.headers)) {
|
||||||
res.status = StatusCode::BadRequest_400;
|
res.status = StatusCode::BadRequest_400;
|
||||||
return write_response(strm, close_connection, req, res);
|
return write_response(strm, close_connection, req, res);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue