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()`][].

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