Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions doc/api/http2.md
Original file line number Diff line number Diff line change
Expand Up @@ -3966,23 +3966,29 @@ API:
```mjs
import { createServer } from 'node:http2';
const server = createServer((req, res) => {
res.setHeader('Content-Type', 'text/html');
res.setHeader('X-Foo', 'bar');
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
res.writeHead(200, {
'Content-Type': 'text/plain; charset=utf-8',
'X-Foo': 'bar',
});
res.end('ok');
});
```

```cjs
const http2 = require('node:http2');
const server = http2.createServer((req, res) => {
res.setHeader('Content-Type', 'text/html');
res.setHeader('X-Foo', 'bar');
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
res.writeHead(200, {
'Content-Type': 'text/plain; charset=utf-8',
'X-Foo': 'bar',
});
res.end('ok');
});
```

When both [`response.setHeader()`][] and [`response.writeHead()`][] are used,
headers are merged, with headers passed to [`response.writeHead()`][] taking
precedence over headers set earlier with [`response.setHeader()`][].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was suggested in the issue, but I think with the example fixed, it's not required.

There's no use of setHeader at all above so it's not relevant here, and this same text is already included in the docs for both setHeader and writeHead which seems like the right place for it.


In order to create a mixed [HTTPS][] and HTTP/2 server, refer to the
[ALPN negotiation][] section.
Upgrading from non-tls HTTP/1 servers is not supported.
Expand Down
Loading