Skip to content

Commit 84978a0

Browse files
committed
docs: use HeadersInit for multi-value cookies
1 parent 09218f3 commit 84978a0

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

MIGRATING.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -297,24 +297,26 @@ export const handlers = [
297297
]
298298
```
299299
300-
Although setting `Set-Cookie` header has no effect on a regular `Response` instance, we detect that header on `HttpResponse` and implement response cookie forwarding on our side for you. **This is why you must always use `HttpResponse` in order to mock response cookies**.
301-
302-
Since Fetch API Headers do not support multiple values as the `HeadersInit`, to mock a multi-value response cookie create a `Headers` instance and use the `.append()` method to set multiple `Set-Cookie` response headers.
300+
When you provide an object as the `ResponseInit.headers` value, you cannot specify multiple response cookies with the same name. Instead, to support multiple response cookies, provide a `Headers` instance:
303301
304302
```js
305303
import { Headers, HttpResponse, rest } from 'msw'
306304
307305
export const handlers = [
308306
rest.get('/resource', () => {
309-
const headers = new Headers()
310-
headers.append('Set-Cookie', 'sessionId=123')
311-
headers.append('Set-Cookie', 'gtm=en_US')
312-
313-
return HttpResponse.plain(null, { headers })
307+
return HttpResponse.plain(null, {
308+
headers: new Headers([
309+
// Mock a multi-value response cookie header.
310+
['Set-Cookie', 'sessionId=123'],
311+
['Set-Cookie', 'gtm=en_US'],
312+
]),
313+
})
314314
}),
315315
]
316316
```
317317
318+
> This is applicable to any multi-value headers, really.
319+
318320
### `ctx.body`
319321
320322
```js

0 commit comments

Comments
 (0)