1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 16:38:10 +00: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:
Luke Wilde 2023-02-08 23:32:44 +00:00 committed by Linus Groh
parent bf2895365b
commit 237df9df5c
3 changed files with 14 additions and 9 deletions

View file

@ -685,11 +685,11 @@ ErrorOr<Optional<Vector<ByteBuffer>>> extract_header_values(Header const& header
}
// https://fetch.spec.whatwg.org/#extract-header-list-values
ErrorOr<Optional<Vector<ByteBuffer>>> extract_header_list_values(ReadonlyBytes name, HeaderList const& list)
ErrorOr<Variant<Vector<ByteBuffer>, ExtractHeaderParseFailure, Empty>> extract_header_list_values(ReadonlyBytes name, HeaderList const& list)
{
// 1. If list does not contain name, then return null.
if (!list.contains(name))
return Optional<Vector<ByteBuffer>> {};
return Empty {};
// FIXME: 2. If the ABNF for name allows a single header and list contains more than one, then return failure.
// NOTE: If different error handling is needed, extract the desired header first.
@ -706,10 +706,8 @@ ErrorOr<Optional<Vector<ByteBuffer>>> extract_header_list_values(ReadonlyBytes n
auto extract = TRY(extract_header_values(header));
// 2. If extract is failure, then return failure.
// FIXME: Currently we treat the null return above and failure return as the same thing,
// ErrorOr already signals OOM to the caller.
if (!extract.has_value())
return Optional<Vector<ByteBuffer>> {};
return ExtractHeaderParseFailure {};
// 3. Append each value in extract, in order, to values.
values.extend(extract.release_value());