1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:17:35 +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:
Linus Groh 2023-02-10 22:02:18 +00:00
parent 6bce48e99b
commit ee68eba0ac
4 changed files with 53 additions and 13 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@ -112,6 +112,26 @@ WebIDL::ExceptionOr<DeprecatedString> Headers::get(DeprecatedString const& name_
return byte_buffer.has_value() ? DeprecatedString { byte_buffer->span() } : DeprecatedString {};
}
// https://fetch.spec.whatwg.org/#dom-headers-getsetcookie
WebIDL::ExceptionOr<Vector<DeprecatedString>> Headers::get_set_cookie()
{
// The getSetCookie() method steps are:
auto& vm = this->vm();
auto values = Vector<DeprecatedString> {};
// 1. If thiss header list does not contain `Set-Cookie`, then return « ».
if (!m_header_list->contains("Set-Cookie"sv.bytes()))
return values;
// 2. Return the values of all headers in thiss header list whose name is a byte-case-insensitive match for
// `Set-Cookie`, in order.
for (auto const& header : *m_header_list) {
if (StringView { header.name }.equals_ignoring_case("Set-Cookie"sv))
TRY_OR_THROW_OOM(vm, values.try_append(DeprecatedString { header.value.bytes() }));
}
return values;
}
// https://fetch.spec.whatwg.org/#dom-headers-has
WebIDL::ExceptionOr<bool> Headers::has(DeprecatedString const& name_string)
{