Skip to content

Setting header with cookie value no longer overwrites a cookie value, it appends #631

@noahbald

Description

@noahbald

Hey there, I've updated msw from ^2.4.2 to ^2.4.5 and thus @mswjs/interceptors from 0.29.1 to 0.35.1. This seems to have a changed behaviour when setting a cookie header.
I'm not too sure of the technical details, but this is the change I'm seeing.

// msw@^2.4.2
console.log(request.headers.get("cookie")); // foo=bar
request.headers.set("cookie", "foo=baz");
console.log(request.headers.get("cookie")); // foo=baz

// msw@^2.4.5
console.log(request.headers.get("cookie")); // foo=bar
request.headers.set("cookie", "foo=baz");
console.log(request.headers.get("cookie")); // foo=bar; foo=baz

Workaround

import { parse, serialize } from "cookie";

const cookies = cookies.parse(request.headers.get("cookie")!);
cookies.foo = "baz"
request.headers.set(serialize(cookies));

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions