You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+233-4Lines changed: 233 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,7 @@ Contributors:
30
30
October 8, 2025 STATUS compared to [http-proxy](https://www.npmjs.com/package/http-proxy) and [httpxy](https://www.npmjs.com/package/httpxy):
31
31
32
32
- Library entirely rewritten in Typescript in a modern style, with many typings added internally and strict mode enabled.
33
+
-**HTTP/2 Support**: Full HTTP/2 support via fetch API with callback-based request/response lifecycle hooks.
33
34
- All dependent packages updated to latest versions, addressing all security vulnerabilities according to `pnpm audit`.
34
35
- Code rewritten to not use deprecated/insecure API's, e.g., using `URL` instead of `parse`.
35
36
- Fixed multiple socket leaks in the Websocket proxy code, going beyond [http-proxy-node16](https://www.npmjs.com/package/http-proxy-node16) to also instrument and logging socket counts. Also fixed an issue with uncatchable errors when using websockets.
@@ -90,7 +91,9 @@ This is the original user's guide, but with various updates.
90
91
-[Setup a stand-alone proxy server with latency](#setup-a-stand-alone-proxy-server-with-latency)
91
92
-[Using HTTPS](#using-https)
92
93
-[Proxying WebSockets](#proxying-websockets)
94
+
-[HTTP/2 Support with Fetch](#http2-support-with-fetch)
// The headers are modified via the onBeforeRequest callback
287
+
proxy.web(req, res);
288
+
});
289
+
290
+
console.log("listening on port 5050");
291
+
server.listen(5050);
292
+
```
293
+
252
294
**[Back to top](#table-of-contents)**
253
295
254
296
#### Modify a response from a proxied server
@@ -399,6 +441,109 @@ proxyServer.listen(8015);
399
441
400
442
**[Back to top](#table-of-contents)**
401
443
444
+
#### HTTP/2 Support with Fetch
445
+
446
+
> **⚠️ Experimental Feature**: The fetch code path for HTTP/2 support is currently experimental. While it provides HTTP/2 functionality and has comprehensive test coverage, the API and behavior may change in future versions. Use with caution in production environments.
447
+
448
+
http-proxy-3 supports HTTP/2 through the native fetch API. When fetch is enabled, the proxy can communicate with HTTP/2 servers. The fetch code path is runtime-agnostic and works across different JavaScript runtimes (Node.js, Deno, Bun, etc.). However, this means HTTP/2 support depends on the runtime. Deno enables HTTP/2 by default, Bun currently does not and Node.js requires to set a different dispatcher. See next section for Node.js details.
- ¹ `secure` is not directly supported in the fetch path. Instead, use `fetch.dispatcher` with `{connect: {rejectUnauthorized: false}}` to disable SSL certificate verification (e.g., for self-signed certificates).
696
+
697
+
**Code Path Selection:**
698
+
- **Native Path**: Used by default, supports HTTP/1.1 and WebSockets
699
+
- **Fetch Path**: Activated when `fetch` option is provided, supports HTTP/2 (with appropriate dispatcher)
700
+
701
+
**Event Compatibility:**
702
+
- **Native Path**: Emits traditional events (`proxyReq`, `proxyRes`, `proxyReqWs`)
- `error`: The error event is emitted if the request to the target fail. **We do not do any error handling of messages passed between client and proxy, and messages passed between proxy and target, so it is recommended that you listen on errors and handle them.**
@@ -513,11 +714,13 @@ If you are using the `proxyServer.listen` method, the following options are also
513
714
- `close`: This event is emitted once the proxy websocket was closed.
514
715
- (DEPRECATED) `proxySocket`: Deprecated in favor of `open`.
515
716
717
+
**Note**: When using the fetch code path (HTTP/2), the `proxyReq` and `proxyRes` events are **not** emitted. Instead, use the `onBeforeRequest` and `onAfterResponse` callback functions in the `fetch` configuration.
0 commit comments