Skip to content

Commit

Permalink
Implement the getSetCookie method of Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ushiboy committed Mar 19, 2024
1 parent 2f8a730 commit d287809
Show file tree
Hide file tree
Showing 4 changed files with 25 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
20 changes: 14 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,21 @@ 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)]);
return names.reduce((ret, n) => {
if (n === "set-cookie") {
this.get(n).forEach(v => {
ret.push([n, v]);
});
} else {
ret.push([n, this.get(n).join(", ")]);
}
return ret;
}, []);
}
}

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

DIR: fetch/api/headers

header-setcookie.any.html: [fail, Unknown]
header-setcookie.any.html: [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 d287809

Please sign in to comment.