mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
LibWeb: Implement Headers.getSetCookie()
This is a normative change in the Fetch spec.
See: e4d3480
This also implements the changes to the 'sort and combine' algorithm,
which now treats "set-cookie" headers differently, and is exposed to JS
via the Headers' iterator.
Passes all 21 WPT tests :^)
http://wpt.live/fetch/api/headers/header-setcookie.any.html
This commit is contained in:
parent
6bce48e99b
commit
ee68eba0ac
4 changed files with 53 additions and 13 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2022, Kenneth Myhra <kennethmyhra@serenityos.org>
|
||||
* Copyright (c) 2022, Luke Wilde <lukew@serenityos.org>
|
||||
*
|
||||
|
@ -257,22 +257,40 @@ ErrorOr<Vector<Header>> HeaderList::sort_and_combine() const
|
|||
|
||||
// 2. Let names be the result of convert header names to a sorted-lowercase set with all the names of the headers in list.
|
||||
Vector<ReadonlyBytes> names_list;
|
||||
TRY(names_list.try_ensure_capacity(size()));
|
||||
for (auto const& header : *this)
|
||||
names_list.append(header.name);
|
||||
names_list.unchecked_append(header.name);
|
||||
auto names = TRY(convert_header_names_to_a_sorted_lowercase_set(names_list));
|
||||
|
||||
// 3. For each name of names:
|
||||
for (auto& name : names) {
|
||||
// 1. Let value be the result of getting name from list.
|
||||
// 2. Assert: value is not null.
|
||||
auto value = TRY(get(name)).value();
|
||||
// 1. If name is `set-cookie`, then:
|
||||
if (name == "set-cookie"sv.bytes()) {
|
||||
// 1. Let values be a list of all values of headers in list whose name is a byte-case-insensitive match for name, in order.
|
||||
// 2. For each value of values:
|
||||
for (auto const& [header_name, value] : *this) {
|
||||
if (StringView { header_name }.equals_ignoring_case(name)) {
|
||||
// 1. Append (name, value) to headers.
|
||||
auto header = TRY(Header::from_string_pair(name, value));
|
||||
TRY(headers.try_append(move(header)));
|
||||
}
|
||||
}
|
||||
}
|
||||
// 2. Otherwise:
|
||||
else {
|
||||
// 1. Let value be the result of getting name from list.
|
||||
auto value = TRY(get(name));
|
||||
|
||||
// 3. Append (name, value) to headers.
|
||||
auto header = Infrastructure::Header {
|
||||
.name = move(name),
|
||||
.value = move(value),
|
||||
};
|
||||
headers.append(move(header));
|
||||
// 2. Assert: value is not null.
|
||||
VERIFY(value.has_value());
|
||||
|
||||
// 3. Append (name, value) to headers.
|
||||
auto header = Header {
|
||||
.name = move(name),
|
||||
.value = value.release_value(),
|
||||
};
|
||||
TRY(headers.try_append(move(header)));
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Return headers.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue