Skip to content

Commit

Permalink
docs: add set-cookie special case (#3470)
Browse files Browse the repository at this point in the history
* docs: add set-cookie special case

* add sub section about set-cookie

* fix typos and add point about resetting set-cookie
  • Loading branch information
genzyy committed Nov 21, 2021
1 parent b55ec60 commit 1552f7d
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/Reply.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [.statusCode](#statusCode)
- [.server](#server)
- [.header(key, value)](#headerkey-value)
- [set-cookie](#set-cookie)
- [.headers(object)](#headersobject)
- [.getHeader(key)](#getheaderkey)
- [.getHeaders()](#getheaders)
Expand Down Expand Up @@ -109,6 +110,18 @@ fastify.get('/', async function (req, rep) {
Sets a response header. If the value is omitted or undefined, it is coerced
to `''`.

<a name="set-cookie"></a>
- ### set-cookie
- While sending different values as cookie with `set-cookie` as the key, every value will be sent as cookie instead of replacing the previous value.

```js
reply.header('set-cookie', 'foo');
reply.header('set-cookie', 'bar');
```
- The browser will only consider the latest reference of a key for `set-cookie` header. The fact that this is done this way is to avoid parsing the set-cookie header when you add it in the reply and speeds up the serialization of the reply.

- To reset the `set-cookie`, you need to make an explicit call to `reply.removeHeader('set-cookie')`, read more about `.removeHeader(key)` [here](#removeheaderkey).

For more information, see [`http.ServerResponse#setHeader`](https://nodejs.org/dist/latest-v14.x/docs/api/http.html#http_response_setheader_name_value).

<a name="headers"></a>
Expand Down

0 comments on commit 1552f7d

Please sign in to comment.