Skip to content

Commit

Permalink
feat(ext/fetch): add Headers#getSetCookie (denoland#13542)
Browse files Browse the repository at this point in the history
Spec change: whatwg/fetch#1346
Tests: web-platform-tests/wpt#31442 (ran against
this PR and they all pass)

---------

Co-authored-by: Bartek Iwańczuk <[email protected]>
  • Loading branch information
lucacasonato and bartlomieju committed Jul 2, 2023
1 parent 0ddfd5d commit d8e8e60
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
17 changes: 17 additions & 0 deletions ext/fetch/20_headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ class Headers {
* @param {string} name
*/
delete(name) {
webidl.assertBranded(this, HeadersPrototype);
const prefix = "Failed to execute 'delete' on 'Headers'";
webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters["ByteString"](name, prefix, "Argument 1");
Expand All @@ -333,6 +334,7 @@ class Headers {
* @param {string} name
*/
get(name) {
webidl.assertBranded(this, HeadersPrototype);
const prefix = "Failed to execute 'get' on 'Headers'";
webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters["ByteString"](name, prefix, "Argument 1");
Expand All @@ -345,10 +347,25 @@ class Headers {
return getHeader(list, name);
}

getSetCookie() {
webidl.assertBranded(this, HeadersPrototype);
const list = this[_headerList];

const entries = [];
for (let i = 0; i < list.length; i++) {
if (byteLowerCase(list[i][0]) === "set-cookie") {
ArrayPrototypePush(entries, list[i][1]);
}
}

return entries;
}

/**
* @param {string} name
*/
has(name) {
webidl.assertBranded(this, HeadersPrototype);
const prefix = "Failed to execute 'has' on 'Headers'";
webidl.requiredArguments(arguments.length, 1, prefix);
name = webidl.converters["ByteString"](name, prefix, "Argument 1");
Expand Down
20 changes: 0 additions & 20 deletions tools/wpt/expectation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4041,25 +4041,9 @@
"headers-record.any.worker.html": true,
"headers-structure.any.worker.html": true,
"header-setcookie.any.html": [
"Headers.prototype.getSetCookie with no headers present",
"Headers.prototype.getSetCookie with one header",
"Headers.prototype.getSetCookie with one header created from an object",
"Headers.prototype.getSetCookie with multiple headers",
"Headers.prototype.getSetCookie with an empty header",
"Headers.prototype.getSetCookie with two equal headers",
"Headers.prototype.getSetCookie ignores set-cookie2 headers",
"Headers.prototype.getSetCookie preserves header ordering",
"Set-Cookie is a forbidden response header"
],
"header-setcookie.any.worker.html": [
"Headers.prototype.getSetCookie with no headers present",
"Headers.prototype.getSetCookie with one header",
"Headers.prototype.getSetCookie with one header created from an object",
"Headers.prototype.getSetCookie with multiple headers",
"Headers.prototype.getSetCookie with an empty header",
"Headers.prototype.getSetCookie with two equal headers",
"Headers.prototype.getSetCookie ignores set-cookie2 headers",
"Headers.prototype.getSetCookie preserves header ordering",
"Set-Cookie is a forbidden response header"
]
},
Expand Down Expand Up @@ -4890,8 +4874,6 @@
]
},
"idlharness.any.html": [
"Headers interface: operation getSetCookie()",
"Headers interface: new Headers() must inherit property \"getSetCookie()\" with the proper type",
"Request interface: attribute destination",
"Request interface: attribute referrer",
"Request interface: attribute referrerPolicy",
Expand Down Expand Up @@ -4923,8 +4905,6 @@
"Window interface: operation fetch(RequestInfo, optional RequestInit)"
],
"idlharness.any.worker.html": [
"Headers interface: operation getSetCookie()",
"Headers interface: new Headers() must inherit property \"getSetCookie()\" with the proper type",
"Request interface: attribute destination",
"Request interface: attribute referrer",
"Request interface: attribute referrerPolicy",
Expand Down

0 comments on commit d8e8e60

Please sign in to comment.