Skip to content

Commit 04cc31d

Browse files
authored
docs: add example of using HTTP2 through undici
1 parent 7d7d207 commit 04cc31d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ const es = new EventSource('https://my-server.com/sse', {
147147
})
148148
```
149149

150+
#### Using HTTP2
151+
152+
Use a package like [`undici`](https://github.com/nodejs/undici) that supports HTTP2.
153+
154+
```ts
155+
// npm install undici --save
156+
import {Agent, fetch} from "undici";
157+
158+
const http2Dispatcher = new Agent({allowH2: true})
159+
160+
const es = new EventSource('https://my-server.com/sse', {
161+
fetch: (url, init) => fetch(url, { ...init, dispatcher: http2Dispatcher })
162+
})
163+
```
164+
150165
#### Allow unauthorized HTTPS requests
151166

152167
Use a package like [`undici`](https://github.com/nodejs/undici) for more control of fetch options through the use of an [`Agent`](https://undici.nodejs.org/#/docs/api/Agent.md).

0 commit comments

Comments
 (0)