1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:28:12 +00:00

LibHTTP: Return error if request is incomplete

If there is not enough input to completely parse HTTP request we need
to return error and handle it in HTTP server.
This commit is contained in:
Aliaksandr Kalenik 2023-03-23 03:06:13 +03:00 committed by Andreas Kling
parent 9220cdc285
commit 7b8a857e30
2 changed files with 14 additions and 0 deletions

View file

@ -102,6 +102,7 @@ ErrorOr<HttpRequest, HttpRequest::ParseError> HttpRequest::from_raw_request(Read
Vector<u8, 256> buffer;
Optional<unsigned> content_length;
DeprecatedString method;
DeprecatedString resource;
DeprecatedString protocol;
@ -168,6 +169,10 @@ ErrorOr<HttpRequest, HttpRequest::ParseError> HttpRequest::from_raw_request(Read
}
commit_and_advance_to(current_header.value, next_state);
if (current_header.name.equals_ignoring_ascii_case("Content-Length"sv))
content_length = current_header.value.to_uint();
headers.append(move(current_header));
break;
}
@ -189,6 +194,12 @@ ErrorOr<HttpRequest, HttpRequest::ParseError> HttpRequest::from_raw_request(Read
}
}
if (state != State::InBody)
return ParseError::RequestIncomplete;
if (content_length.has_value() && content_length.value() != body.size())
return ParseError::RequestIncomplete;
HttpRequest request;
if (method == "GET")
request.m_method = Method::GET;