Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the getSetCookie method of Headers #3694

Merged
merged 2 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -500,7 +500,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