mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibWeb: Parse header value lists for some CORS headers
This adds a simple and incomplete implementation for extracting some specific CORS headers that are used by fetch. This unifies the existing ad-hoc parsing that already existed for Access-Control-Allow-Headers and Access-Control-Allow-Methods, as well as adding Access-control-Expose-Headers.
This commit is contained in:
parent
3a1f510af0
commit
2ce416a676
2 changed files with 20 additions and 32 deletions
|
@ -776,6 +776,26 @@ ErrorOr<Optional<Vector<ByteBuffer>>> extract_header_values(Header const& header
|
|||
{
|
||||
// FIXME: 1. If parsing header’s value, per the ABNF for header’s name, fails, then return failure.
|
||||
// FIXME: 2. Return one or more values resulting from parsing header’s value, per the ABNF for header’s name.
|
||||
|
||||
// For now we only parse some headers that are of the ABNF list form "#something"
|
||||
if (StringView { header.name }.is_one_of_ignoring_ascii_case(
|
||||
"Access-Control-Request-Headers"sv,
|
||||
"Access-Control-Expose-Headers"sv,
|
||||
"Access-Control-Allow-Headers"sv,
|
||||
"Access-Control-Allow-Methods"sv)
|
||||
&& !header.value.is_empty()) {
|
||||
auto split_values = StringView { header.value }.split_view(',');
|
||||
Vector<ByteBuffer> trimmed_values;
|
||||
|
||||
for (auto const& value : split_values) {
|
||||
auto trimmed_value = value.trim(" \t"sv);
|
||||
auto trimmed_value_as_byte_buffer = TRY(ByteBuffer::copy(trimmed_value.bytes()));
|
||||
TRY(trimmed_values.try_append(move(trimmed_value_as_byte_buffer)));
|
||||
}
|
||||
|
||||
return trimmed_values;
|
||||
}
|
||||
|
||||
// This always ignores the ABNF rules for now and returns the header value as a single list item.
|
||||
return Vector { TRY(ByteBuffer::copy(header.value)) };
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue