Skip to content

Commit

Permalink
Implement the getSetCookie() method of Headers
Browse files Browse the repository at this point in the history
Co-authored-by: ushiboy <[email protected]>
Co-authored-by: Domenic Denicola <[email protected]>
  • Loading branch information
3 people committed May 26, 2024
1 parent f2fa507 commit a343932
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
16 changes: 9 additions & 7 deletions lib/jsdom/living/fetch/Headers-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,17 @@ class HeadersImpl {
return this.headersList.contains(name);
}

getSetCookie() {
return this.headersList.get("Set-Cookie") || [];
}

get(name) {
assertName(name);
return this.headersList.get(name);
const r = this.headersList.get(name);
if (!r) {
return null;
}
return r.join(", ");
}

_removePrivilegedNoCORSHeaders() {
Expand All @@ -79,12 +87,6 @@ class HeadersImpl {
}
break;
case "request-no-cors": {
let temporaryValue = this.get(name);
if (temporaryValue === null) {
temporaryValue = value;
} else {
temporaryValue += `, ${value}`;
}
if (!isCORSWhitelisted(name, value)) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions lib/jsdom/living/fetch/Headers.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface Headers {
undefined append(ByteString name, ByteString value);
undefined delete(ByteString name);
ByteString? get(ByteString name);
sequence<ByteString> getSetCookie();
boolean has(ByteString name);
undefined set(ByteString name, ByteString value);
iterable<ByteString, ByteString>;
Expand Down
23 changes: 17 additions & 6 deletions lib/jsdom/living/fetch/header-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ class HeaderList {
append(name, value) {
const existing = this.headers.get(name.toLowerCase());
if (existing) {
name = existing[0].name;
existing.push({ name, value });
existing.push(value);
} else {
this.headers.set(name.toLowerCase(), [{ name, value }]);
this.headers.set(name.toLowerCase(), [value]);
}
}

Expand All @@ -32,7 +31,7 @@ class HeaderList {
if (!values) {
return null;
}
return values.map(h => h.value).join(", ");
return values;
}

delete(name) {
Expand All @@ -42,12 +41,24 @@ class HeaderList {
set(name, value) {
const lowerName = name.toLowerCase();
this.headers.delete(lowerName);
this.headers.set(lowerName, [{ name, value }]);
this.headers.set(lowerName, [value]);
}

sortAndCombine() {
const names = [...this.headers.keys()].sort();
return names.map(n => [n, this.get(n)]);

const headers = [];
for (const name of names) {
if (name === "set-cookie") {
for (const value of this.get(name)) {
headers.push([name, value]);
}
} else {
headers.push([name, this.get(name).join(", ")]);
}
}

return headers;
}
}

Expand Down
3 changes: 2 additions & 1 deletion test/web-platform-tests/to-run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,8 @@ innerhtml-05.xhtml: [fail, Unknown]

DIR: fetch/api/headers

header-setcookie.any.html: [fail, Unknown]
header-setcookie.any.html:
"Set-Cookie is a forbidden response header": [fail, Response is not defined]
header-values-normalize.any.html: [fail, fetch is not defined]
header-values.any.html: [fail, fetch is not defined]
headers-no-cors.any.html: [fail, Request is not defined]
Expand Down

0 comments on commit a343932

Please sign in to comment.