mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 20:17:13 +02:00
LibWeb: Make extract_header_list_values differentiate parsing failures
Previously, parsing failures and the header not existing made extract_header_list_values return an empty Optional, making it impossible to differentiate between the two. Required for implementing CORS-preflight, where parsing failures for the headers makes it fail, but not having them doesn't make it fail in all cases.
This commit is contained in:
Notes:
sideshowbarker
2024-07-17 17:49:11 +09:00
Author: https://github.com/Lubrsi Commit: https://github.com/SerenityOS/serenity/commit/237df9df5c Pull-request: https://github.com/SerenityOS/serenity/pull/17383 Reviewed-by: https://github.com/linusg
@@ -104,13 +104,17 @@ ErrorOr<Optional<AK::URL>> Response::location_url(Optional<DeprecatedString> con
|
||||
return Optional<AK::URL> {};
|
||||
|
||||
// 2. Let location be the result of extracting header list values given `Location` and response’s header list.
|
||||
auto location_values = TRY(extract_header_list_values("Location"sv.bytes(), m_header_list));
|
||||
if (!location_values.has_value() || location_values->size() != 1)
|
||||
auto location_values_or_failure = TRY(extract_header_list_values("Location"sv.bytes(), m_header_list));
|
||||
if (location_values_or_failure.has<Infrastructure::ExtractHeaderParseFailure>() || location_values_or_failure.has<Empty>())
|
||||
return Optional<AK::URL> {};
|
||||
|
||||
auto const& location_values = location_values_or_failure.get<Vector<ByteBuffer>>();
|
||||
if (location_values.size() != 1)
|
||||
return Optional<AK::URL> {};
|
||||
|
||||
// 3. If location is a header value, then set location to the result of parsing location with response’s URL.
|
||||
auto base_url = *url();
|
||||
auto location = AK::URLParser::parse(location_values->first(), &base_url);
|
||||
auto location = AK::URLParser::parse(location_values.first(), &base_url);
|
||||
if (!location.is_valid())
|
||||
return Error::from_string_view("Invalid 'Location' header URL"sv);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user