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
+25-22Lines changed: 25 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -2,37 +2,37 @@
2
2
3
3
[](https://github.com/sagemathinc/http-proxy-3/actions/workflows/test.yml)
4
4
5
-
**WARNING: DEFINITELY DO NOT USE THIS IN PRODUCTION YET. It is not ready.**
5
+
**THIS IS READY TO USE IN PRODUCTION.**
6
6
7
-
http\-proxy\-3 is a modern drop-in-replacement rewrite of
7
+
http\-proxy\-3 is a modern API compatible rewrite of
8
8
[http\-proxy](https://github.com/http-party/node-http-proxy), the original nodejs
9
9
http proxy server. `http-proxy-3` is an HTTP programmable proxying library that
10
-
supports http/https and websockets. It is suitable for implementing components
11
-
such as reverse proxies and load balancers.
10
+
supports http/https and websockets. It is also suitable for implementing components
11
+
such as reverse proxies and load balancers. It's main strength is that you can combine application logic written in Javascript with a proxy server, unlike what
12
+
can be done using nginx or haproxy.
12
13
13
14
**PR's welcome!**
14
15
15
-
May 7, 2025 STATUS compared to http-proxy:
16
+
May 10, 2025 STATUS compared to [http-proxy](https://www.npmjs.com/package/http-proxy) and [httpxy](https://www.npmjs.com/package/httpxy):
16
17
17
-
- Library entirely rewritten in Typescript in a modern style, with many types added internally
18
-
- All dependent packages updated to latest versions, addressing all known security vulnerabilities (according to `pnpm audit`).
18
+
- Library entirely rewritten in Typescript in a modern style, with many typings added internally.
19
+
- All dependent packages updated to latest versions, addressing all security vulnerabilities according to `pnpm audit`.
19
20
- Code rewritten to not use deprecated/insecure API's, e.g., using `URL` instead of `parse`.
20
-
- Fixed major socket leaks in the Websocket proxy code
21
-
- Used heavily in production on https://CoCalc.com
21
+
- Fixed 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.
22
22
- Switch to pnpm for development.
23
-
- Some jest unit tests: converted many examples into unit tests with automated testing that they actually work. http-proxy's unit tests just setup the examples in many cases, but didn't test that they actually work.
23
+
- More jest unit tests than both http-proxy and httpxy: converted all the http-proxy examples into working unit tests that they actually work (http-proxy's unit tests just setup the examples in many cases, but didn't test that they actually work). Also httpxy seems to have almost no tests. These tests should make contributing PR's much easier.
Why the name? http-proxy-2 wasn't available on npmjs.
26
-
27
-
**Motivation:** http-proxy is one of the oldest and most famous nodejs modules, and it gets downloaded around 15 million times a week. Unfortunately, it is [unmaintained](https://github.com/http-party/node-http-proxy/issues/1687), it has significant leaks that [regularly crash production servers](https://github.com/jupyterhub/configurable-http-proxy/issues/434), and is written in ancient untyped Javascript that `npm audit` warns has security vulnerabilities. The maintainers have long since stopped responding, so there is no choice but to fork and start over. I just wanted to do my part to help maintain the open source ecosystem, hence this library. I hope you find it useful.
27
+
**Motivation:** http-proxy is one of the oldest and most famous nodejs modules, and it gets downloaded around 15 million times a week, and I've loved using it for years. Unfortunately, it is [unmaintained](https://github.com/http-party/node-http-proxy/issues/1687), it has significant leaks that [regularly crash production servers](https://github.com/jupyterhub/configurable-http-proxy/issues/434), and is written in ancient untyped Javascript. The maintainers have long since stopped responding, so there is no choice but to fork and start over. I wanted to do my part to help maintain the open source ecosystem, hence this library. I hope you find it useful.
28
28
29
29
**Performance:**
30
30
31
-
I've been adding load tests to the unit tests in various places. Generally speaking on a local machine over localhost the penalty to using the proxy server is that **things take about twice as long**. That's not surprising because it's twice as much work being done all in the same language (with the same tools).
31
+
I've been adding load tests to the unit tests in various places. Generally speaking on a local machine over localhost the penalty to using the proxy server is that **things take about twice as long**. That's not surprising because it's twice as much work being done.
32
32
33
33
**Related Projects:**
34
34
35
-
-https://github.com/unjs/httpxy: it has the same motivation as this project -- it's a modern maintained rewrite of http-proxy. It seems to have [very little unit testing](https://github.com/unjs/httpxy/tree/main/test), which may make it more difficult to contribute to in the longrun.
35
+
-https://github.com/unjs/httpxy: it has the same motivation as this project -- it's a modern maintained rewrite of http-proxy. Unfortunately, it seems to have [very little unit testing](https://github.com/unjs/httpxy/tree/main/test). In http-proxy-3 (and the original http-proxy), there's an order of magnitude more unit test code than code in the actual library.
36
36
37
37
**Development:**
38
38
@@ -52,7 +52,9 @@ pnpm tsc
52
52
53
53
and make changes to code under lib/.
54
54
55
-
Tested with nodejs versions 20 or higher.
55
+
Tested with nodejs versions 20 and 22.
56
+
57
+
[](https://github.com/sagemathinc/http-proxy-3/actions/workflows/test.yml)
56
58
57
59
## User's Guide
58
60
@@ -135,19 +137,19 @@ to the client.
135
137
136
138
### Use Cases
137
139
140
+
There are unit tested examples illustrating everything below in
141
+
the tests subdirectory.
142
+
138
143
#### Setup a basic stand-alone proxy server
139
144
140
145
```js
141
146
import*ashttpfrom"http";
142
147
import { createProxyServer } from"http-proxy-3";
143
-
//
148
+
144
149
// Create your proxy server and set the target in the options.
145
-
//
146
150
createProxyServer({ target:"http://localhost:9000" }).listen(8000); // See (†)
†Invoking listen(..) triggers the creation of a web server. Otherwise, just the proxy instance is created.
166
+
† Just like with the nodejs http module, invoking `listen(...)` triggers the creation of a web server. Otherwise, just the proxy instance is created, which is just a lightweight object with configuration. _If you call close on the proxy it is a no\-op unless you have called listen._
165
167
166
168
**[Back to top](#table-of-contents)**
167
169
@@ -599,7 +601,7 @@ pnpm test
599
601
600
602
### Contributing and Issues
601
603
602
-
- Submit a PR! I want this project to be active again! Port ideas from https://github.com/http-party/node-http-proxy/pulls and https://github.com/http-party/node-http-proxy/issues
604
+
- Submit a PR! I want this project to be active again! Port ideas from [https://github.com/http\-party/node\-http\-proxy/pulls](https://github.com/http-party/node-http-proxy/pulls) and [https://github.com/http\-party/node\-http\-proxy/issues](https://github.com/http-party/node-http-proxy/issues). Email me at [[email protected]](mailto:[email protected]).
603
605
604
606
**[Back to top](#table-of-contents)**
605
607
@@ -626,3 +628,4 @@ pnpm test
626
628
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
627
629
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
0 commit comments