@fastify/reply-from 9.0.2 → 9.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/index.js +2 -1
- package/lib/request.js +2 -1
- package/package.json +2 -1
- package/test/head-with-body.test.js +6 -0
- package/test/undici-no-destroy.test.js +29 -0
- package/types/index.d.ts +1 -0
- package/types/index.test-d.ts +1 -0
package/README.md
CHANGED
|
@@ -246,6 +246,15 @@ fastify.register(FastifyReplyFrom, {
|
|
|
246
246
|
|
|
247
247
|
---
|
|
248
248
|
|
|
249
|
+
#### `destoryAgent`
|
|
250
|
+
|
|
251
|
+
If set to `true`, it will destory all agents when the Fastify is closed.
|
|
252
|
+
If set to `false`, it will not destroy the agents.
|
|
253
|
+
|
|
254
|
+
By Default: `false`
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
249
258
|
#### `maxRetriesOn503`
|
|
250
259
|
|
|
251
260
|
This plugin will always retry on `GET` requests that returns 503 errors, _unless_ `retryMethods` does not contain `GET`.
|
package/index.js
CHANGED
|
@@ -39,7 +39,8 @@ const fastifyReplyFrom = fp(function from (fastify, opts, next) {
|
|
|
39
39
|
http2: opts.http2,
|
|
40
40
|
base,
|
|
41
41
|
undici: opts.undici,
|
|
42
|
-
globalAgent: opts.globalAgent
|
|
42
|
+
globalAgent: opts.globalAgent,
|
|
43
|
+
destroyAgent: opts.destroyAgent
|
|
43
44
|
})
|
|
44
45
|
if (requestBuilt instanceof Error) {
|
|
45
46
|
next(requestBuilt)
|
package/lib/request.js
CHANGED
|
@@ -42,6 +42,7 @@ function buildRequest (opts) {
|
|
|
42
42
|
const baseUrl = opts.base && new URL(opts.base).origin
|
|
43
43
|
const undiciOpts = opts.undici || {}
|
|
44
44
|
const globalAgent = opts.globalAgent
|
|
45
|
+
const destroyAgent = opts.destroyAgent
|
|
45
46
|
let http2Client
|
|
46
47
|
let undiciAgent
|
|
47
48
|
let undiciInstance
|
|
@@ -85,7 +86,7 @@ function buildRequest (opts) {
|
|
|
85
86
|
}
|
|
86
87
|
|
|
87
88
|
function close () {
|
|
88
|
-
if (globalAgent) {
|
|
89
|
+
if (globalAgent || destroyAgent === false) {
|
|
89
90
|
return
|
|
90
91
|
}
|
|
91
92
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fastify/reply-from",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.1.0",
|
|
4
4
|
"description": "forward your HTTP request to another server, for fastify",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
"msgpack5": "^6.0.1",
|
|
42
42
|
"nock": "^13.2.6",
|
|
43
43
|
"proxyquire": "^2.1.3",
|
|
44
|
+
"semver": "^7.5.1",
|
|
44
45
|
"simple-get": "^4.0.1",
|
|
45
46
|
"snazzy": "^9.0.0",
|
|
46
47
|
"split2": "^4.1.0",
|
|
@@ -5,6 +5,12 @@ const Fastify = require('fastify')
|
|
|
5
5
|
const From = require('..')
|
|
6
6
|
const http = require('http')
|
|
7
7
|
const get = require('simple-get').concat
|
|
8
|
+
const semver = require('semver')
|
|
9
|
+
|
|
10
|
+
if (semver.gte(process.version, '20.2.0')) {
|
|
11
|
+
t.comment('skip this test on node >= 20.2.0 as it is current broken')
|
|
12
|
+
process.exit(0)
|
|
13
|
+
}
|
|
8
14
|
|
|
9
15
|
const instance = Fastify()
|
|
10
16
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('tap')
|
|
4
|
+
const Fastify = require('fastify')
|
|
5
|
+
const undici = require('undici')
|
|
6
|
+
const From = require('..')
|
|
7
|
+
|
|
8
|
+
test('destroyAgent false', async (t) => {
|
|
9
|
+
const mockAgent = new undici.Agent()
|
|
10
|
+
mockAgent.destroy = () => {
|
|
11
|
+
t.fail()
|
|
12
|
+
}
|
|
13
|
+
const instance = Fastify()
|
|
14
|
+
|
|
15
|
+
t.teardown(instance.close.bind(instance))
|
|
16
|
+
|
|
17
|
+
instance.get('/', (request, reply) => {
|
|
18
|
+
reply.from()
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
instance.register(From, {
|
|
22
|
+
base: 'http://localhost:4242',
|
|
23
|
+
undici: mockAgent,
|
|
24
|
+
destroyAgent: false
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
await instance.ready()
|
|
28
|
+
await instance.close()
|
|
29
|
+
})
|
package/types/index.d.ts
CHANGED