Skip to content

Commit e50a42b

Browse files
committed
Added support for undici
1 parent 086aa1e commit e50a42b

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ For other examples, see `example.js`.
6565

6666
## Options
6767

68-
This `fastify` plugin supports the following options.
68+
This `fastify` plugin supports _all_ the options of
69+
[`fastify-reply-from`](https://github.com/fastify/fastify-reply-from) plus the following.
6970

7071
*Note that this plugin is fully encapsulated, and non-JSON payloads will
7172
be streamed directly to the destination.*
@@ -82,10 +83,6 @@ The prefix to mount this plugin on. All the requests to the current server start
8283

8384
A `beforeHandler` to be applied on all routes. Useful for performing actions before the proxy is executed (e.g. check for authentication).
8485

85-
### http2
86-
87-
A boolean value that indicates whether the proxy should support http2.
88-
8986
## Benchmarks
9087

9188
The following benchmarks where generated on a Macbook 2018 with i5 and
@@ -95,6 +92,8 @@ The following benchmarks where generated on a Macbook 2018 with i5 and
9592
| `express-http-proxy` | 878.4 |
9693
| `http-proxy` | 3837 |
9794
| `fastify-http-proxy` | 4205 |
95+
| `fastify-http-proxy` (with
96+
[`undici`](https://github.com/mcollina/undici)) | 6235.6 |
9897

9998
The results where gathered on the second run of `autocannon -c 100 -d 5
10099
URL`.

benchmarks/fastify-proxy.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@ const proxy = require('..')
55

66
async function startProxy (upstream) {
77
const server = Fastify()
8+
let undici = false
9+
10+
if (process.env.UNDICI) {
11+
undici = {
12+
connections: 100,
13+
pipelining: 10
14+
}
15+
}
16+
817
server.register(proxy, {
918
upstream,
10-
http2: !!process.env.HTTP2
19+
http2: !!process.env.HTTP2,
20+
undici
1121
})
1222

1323
await server.listen(3000)

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ module.exports = async function (fastify, opts) {
99

1010
const beforeHandler = opts.beforeHandler
1111

12-
fastify.register(From, {
13-
base: opts.upstream,
14-
http2: opts.http2
15-
})
12+
const fromOpts = Object.assign({}, opts)
13+
fromOpts.base = opts.upstream
14+
fromOpts.prefix = undefined
15+
16+
fastify.register(From, fromOpts)
1617

1718
fastify.addContentTypeParser('application/json', bodyParser)
1819
fastify.addContentTypeParser('*', bodyParser)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@
3636
"tap": "^12.0.0"
3737
},
3838
"dependencies": {
39-
"fastify-reply-from": "^0.4.5"
39+
"fastify-reply-from": "^0.5.0"
4040
}
4141
}

0 commit comments

Comments
 (0)