mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:57:35 +00:00
LibHTTP: Return an error if HTTP request URL is not valid UTF-8
This commit is contained in:
parent
57d7637b59
commit
9fefb434f2
2 changed files with 14 additions and 2 deletions
|
@ -226,11 +226,22 @@ ErrorOr<HttpRequest, HttpRequest::ParseError> HttpRequest::from_raw_request(Read
|
||||||
request.m_headers = move(headers);
|
request.m_headers = move(headers);
|
||||||
auto url_parts = resource.split_limit('?', 2, SplitBehavior::KeepEmpty);
|
auto url_parts = resource.split_limit('?', 2, SplitBehavior::KeepEmpty);
|
||||||
|
|
||||||
|
auto url_part_to_string = [](DeprecatedString const& url_part) -> ErrorOr<String, ParseError> {
|
||||||
|
auto query_string_or_error = String::from_deprecated_string(url_part);
|
||||||
|
if (!query_string_or_error.is_error())
|
||||||
|
return query_string_or_error.release_value();
|
||||||
|
|
||||||
|
if (query_string_or_error.error().code() == ENOMEM)
|
||||||
|
return ParseError::OutOfMemory;
|
||||||
|
|
||||||
|
return ParseError::InvalidURL;
|
||||||
|
};
|
||||||
|
|
||||||
request.m_url.set_cannot_be_a_base_url(true);
|
request.m_url.set_cannot_be_a_base_url(true);
|
||||||
if (url_parts.size() == 2) {
|
if (url_parts.size() == 2) {
|
||||||
request.m_resource = url_parts[0];
|
request.m_resource = url_parts[0];
|
||||||
request.m_url.set_paths({ url_parts[0] });
|
request.m_url.set_paths({ url_parts[0] });
|
||||||
request.m_url.set_query(String::from_deprecated_string(url_parts[1]).release_value_but_fixme_should_propagate_errors());
|
request.m_url.set_query(TRY(url_part_to_string(url_parts[1])));
|
||||||
} else {
|
} else {
|
||||||
request.m_resource = resource;
|
request.m_resource = resource;
|
||||||
request.m_url.set_paths({ resource });
|
request.m_url.set_paths({ resource });
|
||||||
|
|
|
@ -22,7 +22,8 @@ public:
|
||||||
RequestTooLarge,
|
RequestTooLarge,
|
||||||
RequestIncomplete,
|
RequestIncomplete,
|
||||||
OutOfMemory,
|
OutOfMemory,
|
||||||
UnsupportedMethod
|
UnsupportedMethod,
|
||||||
|
InvalidURL
|
||||||
};
|
};
|
||||||
|
|
||||||
static StringView parse_error_to_string(ParseError error)
|
static StringView parse_error_to_string(ParseError error)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue