Skip to content

Commit

Permalink
docs: use HeadersInit for multi-value cookies
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Nov 17, 2022
1 parent 09218f3 commit 84978a0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions MIGRATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,24 +297,26 @@ export const handlers = [
]
```
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**.
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.
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:
```js
import { Headers, HttpResponse, rest } from 'msw'
export const handlers = [
rest.get('/resource', () => {
const headers = new Headers()
headers.append('Set-Cookie', 'sessionId=123')
headers.append('Set-Cookie', 'gtm=en_US')
return HttpResponse.plain(null, { headers })
return HttpResponse.plain(null, {
headers: new Headers([
// Mock a multi-value response cookie header.
['Set-Cookie', 'sessionId=123'],
['Set-Cookie', 'gtm=en_US'],
]),
})
}),
]
```
> This is applicable to any multi-value headers, really.
### `ctx.body`
```js
Expand Down

0 comments on commit 84978a0

Please sign in to comment.