Skip to content

Commit 63e92a2

Browse files
authored
Gracefully handle malformed Set-Cookie headers (#7)
1 parent 2eedffd commit 63e92a2

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,12 @@ function buildResponseCookies(headers) {
276276
const setCookies = headers["set-cookie"];
277277
if (setCookies) {
278278
setCookies.forEach(headerValue => {
279-
const parsed = setCookie.parse(headerValue);
279+
let parsed;
280+
try {
281+
parsed = setCookie.parse(headerValue);
282+
} catch (err) {
283+
return;
284+
}
280285
parsed.forEach(cookie => {
281286
const { name, value, path, domain, expires, httpOnly, secure } = cookie;
282287
const harCookie = {

test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,15 @@ fragment TypeRef on __Type {
445445
response.harEntry.response.bodySize
446446
);
447447
});
448+
449+
it("ignores malformed Set-Cookie headers instead of throwing an error", async () => {
450+
const fetch = withHar(baseFetch);
451+
await expect(
452+
fetch(
453+
"https://postman-echo.com/response-headers?Content-Type=text/html&Set-Cookie=%3Da%3D5%25%25"
454+
)
455+
).resolves.toHaveProperty("harEntry");
456+
});
448457
});
449458

450459
it("reports entries with the onHarEntry option", async () => {

0 commit comments

Comments
 (0)