File tree Expand file tree Collapse file tree 4 files changed +21
-11
lines changed Expand file tree Collapse file tree 4 files changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -65,7 +65,8 @@ For other examples, see `example.js`.
65
65
66
66
## Options
67
67
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.
69
70
70
71
* Note that this plugin is fully encapsulated, and non-JSON payloads will
71
72
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
82
83
83
84
A ` beforeHandler ` to be applied on all routes. Useful for performing actions before the proxy is executed (e.g. check for authentication).
84
85
85
- ### http2
86
-
87
- A boolean value that indicates whether the proxy should support http2.
88
-
89
86
## Benchmarks
90
87
91
88
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
95
92
| ` express-http-proxy ` | 878.4 |
96
93
| ` http-proxy ` | 3837 |
97
94
| ` fastify-http-proxy ` | 4205 |
95
+ | ` fastify-http-proxy ` (with
96
+ [ ` undici ` ] ( https://github.com/mcollina/undici ) ) | 6235.6 |
98
97
99
98
The results where gathered on the second run of `autocannon -c 100 -d 5
100
99
URL`.
Original file line number Diff line number Diff line change @@ -5,9 +5,19 @@ const proxy = require('..')
5
5
6
6
async function startProxy ( upstream ) {
7
7
const server = Fastify ( )
8
+ let undici = false
9
+
10
+ if ( process . env . UNDICI ) {
11
+ undici = {
12
+ connections : 100 ,
13
+ pipelining : 10
14
+ }
15
+ }
16
+
8
17
server . register ( proxy , {
9
18
upstream,
10
- http2 : ! ! process . env . HTTP2
19
+ http2 : ! ! process . env . HTTP2 ,
20
+ undici
11
21
} )
12
22
13
23
await server . listen ( 3000 )
Original file line number Diff line number Diff line change @@ -9,10 +9,11 @@ module.exports = async function (fastify, opts) {
9
9
10
10
const beforeHandler = opts . beforeHandler
11
11
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 )
16
17
17
18
fastify . addContentTypeParser ( 'application/json' , bodyParser )
18
19
fastify . addContentTypeParser ( '*' , bodyParser )
Original file line number Diff line number Diff line change 36
36
"tap" : " ^12.0.0"
37
37
},
38
38
"dependencies" : {
39
- "fastify-reply-from" : " ^0.4.5 "
39
+ "fastify-reply-from" : " ^0.5.0 "
40
40
}
41
41
}
You can’t perform that action at this time.
0 commit comments