@fastify/reply-from 10.0.0 → 11.0.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/.gitattributes +2 -0
- package/.github/workflows/ci.yml +1 -1
- package/.taprc +1 -9
- package/README.md +114 -29
- package/index.js +55 -47
- package/lib/request.js +32 -12
- package/lib/utils.js +8 -0
- package/package.json +25 -22
- package/test/async-route-handler.test.js +1 -1
- package/test/base-get.test.js +1 -1
- package/test/base-querystring.test.js +1 -1
- package/test/build-url.test.js +9 -2
- package/test/core-with-path-in-base.test.js +1 -1
- package/test/custom-undici-instance.test.js +1 -1
- package/test/disable-request-logging.test.js +1 -1
- package/test/fastify-multipart-incompatibility.test.js +3 -3
- package/test/fix-GHSA-v2v2-hph8-q5xp.test.js +47 -0
- package/test/full-delete-http2.test.js +52 -0
- package/test/full-get-test.test.js +1 -1
- package/test/full-https-get.test.js +3 -3
- package/test/full-post-extended-content-type.test.js +1 -1
- package/test/full-post-http2.test.js +2 -0
- package/test/full-post-stream-core.test.js +1 -1
- package/test/full-post-stream.test.js +1 -1
- package/test/full-post.test.js +1 -1
- package/test/full-querystring-rewrite-option-complex.test.js +1 -1
- package/test/full-querystring-rewrite-option-function-request.test.js +58 -0
- package/test/full-querystring-rewrite-option-function.test.js +2 -2
- package/test/full-querystring-rewrite-option.test.js +1 -1
- package/test/full-querystring-rewrite-string.test.js +1 -1
- package/test/full-querystring-rewrite.test.js +1 -1
- package/test/full-querystring.test.js +1 -1
- package/test/full-rewrite-body-content-type.test.js +1 -1
- package/test/full-rewrite-body-http.test.js +1 -1
- package/test/full-rewrite-body-to-empty-string.test.js +1 -1
- package/test/full-rewrite-body-to-null.test.js +1 -1
- package/test/full-rewrite-body.test.js +1 -1
- package/test/get-upstream-http.test.js +1 -1
- package/test/get-upstream-type.test.js +1 -1
- package/test/get-upstream-undici.test.js +1 -1
- package/test/get-with-body.test.js +1 -1
- package/test/head-with-body.test.js +7 -1
- package/test/http-agents.test.js +2 -2
- package/test/http-global-agent.test.js +1 -1
- package/test/http-http2.test.js +2 -0
- package/test/http-retry.test.js +1 -1
- package/test/http-timeout.test.js +0 -2
- package/test/http2-http2.test.js +4 -2
- package/test/http2-https.test.js +2 -2
- package/test/http2-invalid-base.test.js +1 -1
- package/test/http2-timeout-disabled.test.js +85 -0
- package/test/http2-timeout.test.js +2 -0
- package/test/http2-unix-socket.test.js +1 -1
- package/test/https-agents.test.js +4 -4
- package/test/https-global-agent.test.js +3 -3
- package/test/method.test.js +70 -0
- package/test/modifyCoreObjects-false.test.js +1 -1
- package/test/no-body-opts-with-get.test.js +1 -1
- package/test/no-body-opts-with-head.test.js +1 -1
- package/test/no-stream-body-option.test.js +2 -2
- package/test/on-error.test.js +11 -15
- package/test/onResponse.test.js +4 -3
- package/test/padded-body.test.js +1 -1
- package/test/post-formbody.test.js +1 -1
- package/test/post-plain-text.test.js +1 -1
- package/test/post-with-custom-encoded-contenttype.test.js +2 -2
- package/test/post-with-octet-stream.test.js +2 -2
- package/test/retry-on-503.test.js +1 -1
- package/test/retry-with-a-custom-handler.test.js +186 -0
- package/test/rewrite-headers-type.test.js +1 -1
- package/test/rewrite-headers.test.js +1 -1
- package/test/rewrite-request-headers-type.test.js +1 -1
- package/test/rewrite-request-headers.test.js +1 -1
- package/test/transform-body.test.js +3 -3
- package/test/undici-agent.test.js +2 -2
- package/test/undici-body.test.js +1 -1
- package/test/undici-connect-timeout.test.js +10 -14
- package/test/undici-custom-dispatcher.test.js +73 -0
- package/test/undici-global-agent.test.js +1 -1
- package/test/undici-no-destroy.test.js +29 -0
- package/test/undici-options.test.js +1 -1
- package/test/undici-proxy-agent.test.js +81 -0
- package/test/undici-retry.test.js +1 -1
- package/test/undici-timeout-body-partial.test.js +15 -19
- package/test/undici-timeout-body.test.js +13 -17
- package/test/undici-timeout.test.js +11 -15
- package/test/undici-with-path-in-base.test.js +1 -1
- package/test/undici.test.js +1 -1
- package/test/unix-http-undici-from.test.js +3 -3
- package/test/unix-http-undici.test.js +3 -3
- package/test/unix-http.test.js +3 -3
- package/test/unix-https-undici.test.js +4 -4
- package/test/unix-https.test.js +4 -4
- package/types/index.d.ts +37 -19
- package/types/index.test-d.ts +37 -10
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const t = require('tap')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
5
|
const proxyquire = require('proxyquire')
|
|
6
|
-
const http = require('http')
|
|
6
|
+
const http = require('node:http')
|
|
7
7
|
const get = require('simple-get').concat
|
|
8
8
|
const undici = require('undici')
|
|
9
9
|
const { getUndiciOptions } = require('../lib/request')
|
|
@@ -31,7 +31,7 @@ target.listen({ port: 0 }, err => {
|
|
|
31
31
|
const From = proxyquire('..', {
|
|
32
32
|
'./lib/request.js': proxyquire('../lib/request.js', {
|
|
33
33
|
undici: proxyquire('undici', {
|
|
34
|
-
'./lib/agent': proxyquire('undici/lib/agent.js', {
|
|
34
|
+
'./lib/dispatcher/agent': proxyquire('undici/lib/dispatcher/agent.js', {
|
|
35
35
|
'./pool': class Pool extends undici.Pool {
|
|
36
36
|
constructor (url, options) {
|
|
37
37
|
super(url, options)
|
package/test/undici-body.test.js
CHANGED
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const t = require('tap')
|
|
4
|
-
const http = require('http')
|
|
5
|
-
const net = require('net')
|
|
4
|
+
const http = require('node:http')
|
|
5
|
+
const net = require('node:net')
|
|
6
6
|
const Fastify = require('fastify')
|
|
7
7
|
const From = require('..')
|
|
8
8
|
const got = require('got')
|
|
9
9
|
|
|
10
|
-
t.
|
|
11
|
-
|
|
10
|
+
t.test('undici connect timeout', async (t) => {
|
|
12
11
|
// never connect
|
|
13
|
-
net.connect = function (options) {
|
|
14
|
-
|
|
15
|
-
}
|
|
12
|
+
net.connect = function (options) {
|
|
13
|
+
return new net.Socket(options)
|
|
14
|
+
}
|
|
16
15
|
|
|
17
|
-
const target = http.createServer((req, res) => {
|
|
18
|
-
|
|
19
|
-
})
|
|
16
|
+
const target = http.createServer((req, res) => {
|
|
17
|
+
t.fail('target never called')
|
|
18
|
+
})
|
|
20
19
|
|
|
21
|
-
async function main () {
|
|
22
20
|
t.plan(2)
|
|
23
21
|
await target.listen({ port: 0 })
|
|
24
22
|
|
|
@@ -53,6 +51,4 @@ async function main () {
|
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
t.fail()
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
main()
|
|
54
|
+
})
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('tap')
|
|
4
|
+
const undici = require('undici')
|
|
5
|
+
const Fastify = require('fastify')
|
|
6
|
+
const From = require('..')
|
|
7
|
+
|
|
8
|
+
class CustomDispatcher {
|
|
9
|
+
constructor (...args) {
|
|
10
|
+
this._dispatcher = new undici.Pool(...args)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
request (...args) {
|
|
14
|
+
return this._dispatcher.request(...args)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
close (...args) {
|
|
18
|
+
return this._dispatcher.close(...args)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
destroy (...args) {
|
|
22
|
+
return this._dispatcher.destroy(...args)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
test('use a custom instance of \'undici\'', async t => {
|
|
27
|
+
const target = Fastify({
|
|
28
|
+
keepAliveTimeout: 1
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
target.get('/', (req, reply) => {
|
|
32
|
+
t.pass('request proxied')
|
|
33
|
+
|
|
34
|
+
reply.headers({
|
|
35
|
+
'Content-Type': 'text/plain',
|
|
36
|
+
'x-my-header': 'hello!'
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
reply.statusCode = 205
|
|
40
|
+
reply.send('hello world')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
await target.listen({ port: 3001 })
|
|
44
|
+
t.teardown(async () => {
|
|
45
|
+
await target.close()
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const instance = Fastify({
|
|
49
|
+
keepAliveTimeout: 1
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
instance.register(From, {
|
|
53
|
+
undici: new CustomDispatcher('http://localhost:3001')
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
instance.get('/', (request, reply) => {
|
|
57
|
+
reply.from('http://myserver.local')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
await instance.listen({ port: 0 })
|
|
61
|
+
t.teardown(async () => {
|
|
62
|
+
await instance.close()
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const res = await undici.request(`http://localhost:${instance.server.address().port}`)
|
|
66
|
+
|
|
67
|
+
t.equal(res.headers['content-type'], 'text/plain')
|
|
68
|
+
t.equal(res.headers['x-my-header'], 'hello!')
|
|
69
|
+
t.equal(res.statusCode, 205)
|
|
70
|
+
|
|
71
|
+
const data = await res.body.text()
|
|
72
|
+
t.equal(data, 'hello world')
|
|
73
|
+
})
|
|
@@ -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
|
+
})
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const t = require('tap')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
5
|
const proxyquire = require('proxyquire')
|
|
6
|
-
const http = require('http')
|
|
6
|
+
const http = require('node:http')
|
|
7
7
|
const get = require('simple-get').concat
|
|
8
8
|
const undici = require('undici')
|
|
9
9
|
const { getUndiciOptions } = require('../lib/request')
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { test } = require('tap')
|
|
4
|
+
const { createServer } = require('node:http')
|
|
5
|
+
const Fastify = require('fastify')
|
|
6
|
+
const get = require('simple-get').concat
|
|
7
|
+
const { createProxy } = require('proxy')
|
|
8
|
+
const From = require('..')
|
|
9
|
+
|
|
10
|
+
const configFormat = {
|
|
11
|
+
string: (value) => value,
|
|
12
|
+
'url instance': (value) => new URL(value),
|
|
13
|
+
object: (value) => ({ uri: value })
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
for (const [description, format] of Object.entries(configFormat)) {
|
|
17
|
+
test(`use undici ProxyAgent to connect through proxy - configured via ${description}`, async (t) => {
|
|
18
|
+
t.plan(5)
|
|
19
|
+
const target = await buildServer()
|
|
20
|
+
const proxy = await buildProxy()
|
|
21
|
+
t.teardown(target.close.bind(target))
|
|
22
|
+
t.teardown(proxy.close.bind(proxy))
|
|
23
|
+
|
|
24
|
+
const targetUrl = `http://localhost:${target.address().port}`
|
|
25
|
+
const proxyUrl = `http://localhost:${proxy.address().port}`
|
|
26
|
+
|
|
27
|
+
proxy.on('connect', () => {
|
|
28
|
+
t.ok(true, 'should connect to proxy')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
target.on('request', (req, res) => {
|
|
32
|
+
res.setHeader('content-type', 'application/json')
|
|
33
|
+
res.end(JSON.stringify({ hello: 'world' }))
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const instance = Fastify()
|
|
37
|
+
t.teardown(instance.close.bind(instance))
|
|
38
|
+
|
|
39
|
+
instance.register(From, {
|
|
40
|
+
base: targetUrl,
|
|
41
|
+
undici: {
|
|
42
|
+
proxy: format(proxyUrl)
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
instance.get('/', (request, reply) => {
|
|
47
|
+
reply.from()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
const executionFlow = () => new Promise((resolve) => {
|
|
51
|
+
instance.listen({ port: 0 }, err => {
|
|
52
|
+
t.error(err)
|
|
53
|
+
|
|
54
|
+
get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
|
|
55
|
+
t.error(err)
|
|
56
|
+
t.same(res.statusCode, 200)
|
|
57
|
+
t.match(JSON.parse(data.toString()), { hello: 'world' })
|
|
58
|
+
resolve()
|
|
59
|
+
instance.close()
|
|
60
|
+
target.close()
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
await executionFlow()
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function buildServer () {
|
|
70
|
+
return new Promise((resolve) => {
|
|
71
|
+
const server = createServer()
|
|
72
|
+
server.listen(0, () => resolve(server))
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function buildProxy () {
|
|
77
|
+
return new Promise((resolve) => {
|
|
78
|
+
const server = createProxy(createServer())
|
|
79
|
+
server.listen(0, () => resolve(server))
|
|
80
|
+
})
|
|
81
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const t = require('tap')
|
|
4
|
-
const http = require('http')
|
|
4
|
+
const http = require('node:http')
|
|
5
5
|
const Fastify = require('fastify')
|
|
6
6
|
const From = require('..')
|
|
7
7
|
const got = require('got')
|
|
@@ -9,23 +9,21 @@ const FakeTimers = require('@sinonjs/fake-timers')
|
|
|
9
9
|
|
|
10
10
|
const clock = FakeTimers.createClock()
|
|
11
11
|
|
|
12
|
-
t.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
12
|
+
t.test('undici body timeout', async (t) => {
|
|
13
|
+
const target = http.createServer((req, res) => {
|
|
14
|
+
t.pass('request proxied')
|
|
15
|
+
req.on('data', () => undefined)
|
|
16
|
+
req.on('end', () => {
|
|
17
|
+
res.writeHead(200)
|
|
18
|
+
res.flushHeaders()
|
|
19
|
+
res.write('test')
|
|
20
|
+
clock.setTimeout(() => {
|
|
21
|
+
res.end()
|
|
22
|
+
t.end()
|
|
23
|
+
}, 1000)
|
|
24
|
+
})
|
|
25
25
|
})
|
|
26
|
-
})
|
|
27
26
|
|
|
28
|
-
async function main () {
|
|
29
27
|
await target.listen({ port: 0 })
|
|
30
28
|
|
|
31
29
|
const instance = Fastify()
|
|
@@ -55,6 +53,4 @@ async function main () {
|
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
t.fail()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
main()
|
|
56
|
+
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const t = require('tap')
|
|
4
|
-
const http = require('http')
|
|
4
|
+
const http = require('node:http')
|
|
5
5
|
const Fastify = require('fastify')
|
|
6
6
|
const From = require('..')
|
|
7
7
|
const got = require('got')
|
|
@@ -9,21 +9,19 @@ const FakeTimers = require('@sinonjs/fake-timers')
|
|
|
9
9
|
|
|
10
10
|
const clock = FakeTimers.createClock()
|
|
11
11
|
|
|
12
|
-
t.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
12
|
+
t.test('undici body timeout', async (t) => {
|
|
13
|
+
const target = http.createServer((req, res) => {
|
|
14
|
+
t.pass('request proxied')
|
|
15
|
+
req.on('data', () => undefined)
|
|
16
|
+
req.on('end', () => {
|
|
17
|
+
res.flushHeaders()
|
|
18
|
+
clock.setTimeout(() => {
|
|
19
|
+
res.end()
|
|
20
|
+
t.end()
|
|
21
|
+
}, 1000)
|
|
22
|
+
})
|
|
23
23
|
})
|
|
24
|
-
})
|
|
25
24
|
|
|
26
|
-
async function main () {
|
|
27
25
|
await target.listen({ port: 0 })
|
|
28
26
|
|
|
29
27
|
const instance = Fastify()
|
|
@@ -58,6 +56,4 @@ async function main () {
|
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
t.fail()
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
main()
|
|
59
|
+
})
|
|
@@ -8,21 +8,19 @@ const FakeTimers = require('@sinonjs/fake-timers')
|
|
|
8
8
|
|
|
9
9
|
const clock = FakeTimers.createClock()
|
|
10
10
|
|
|
11
|
-
t.
|
|
11
|
+
t.test('undici request timeout', async (t) => {
|
|
12
|
+
const target = Fastify()
|
|
13
|
+
t.teardown(target.close.bind(target))
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
t.
|
|
15
|
+
target.get('/', (request, reply) => {
|
|
16
|
+
t.pass('request arrives')
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
t.end()
|
|
22
|
-
}, 1000)
|
|
23
|
-
})
|
|
18
|
+
clock.setTimeout(() => {
|
|
19
|
+
reply.status(200).send('hello world')
|
|
20
|
+
t.end()
|
|
21
|
+
}, 1000)
|
|
22
|
+
})
|
|
24
23
|
|
|
25
|
-
async function main () {
|
|
26
24
|
await target.listen({ port: 0 })
|
|
27
25
|
|
|
28
26
|
const instance = Fastify()
|
|
@@ -57,6 +55,4 @@ async function main () {
|
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
t.fail()
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
main()
|
|
58
|
+
})
|
package/test/undici.test.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
const t = require('tap')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
5
|
const From = require('..')
|
|
6
|
-
const fs = require('fs')
|
|
7
|
-
const querystring = require('querystring')
|
|
8
|
-
const http = require('http')
|
|
6
|
+
const fs = require('node:fs')
|
|
7
|
+
const querystring = require('node:querystring')
|
|
8
|
+
const http = require('node:http')
|
|
9
9
|
const get = require('simple-get').concat
|
|
10
10
|
|
|
11
11
|
if (process.platform === 'win32') {
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
const t = require('tap')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
5
|
const From = require('..')
|
|
6
|
-
const fs = require('fs')
|
|
7
|
-
const querystring = require('querystring')
|
|
8
|
-
const http = require('http')
|
|
6
|
+
const fs = require('node:fs')
|
|
7
|
+
const querystring = require('node:querystring')
|
|
8
|
+
const http = require('node:http')
|
|
9
9
|
const get = require('simple-get').concat
|
|
10
10
|
|
|
11
11
|
if (process.platform === 'win32') {
|
package/test/unix-http.test.js
CHANGED
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
const t = require('tap')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
5
|
const From = require('..')
|
|
6
|
-
const fs = require('fs')
|
|
7
|
-
const querystring = require('querystring')
|
|
8
|
-
const http = require('http')
|
|
6
|
+
const fs = require('node:fs')
|
|
7
|
+
const querystring = require('node:querystring')
|
|
8
|
+
const http = require('node:http')
|
|
9
9
|
const get = require('simple-get').concat
|
|
10
10
|
|
|
11
11
|
if (process.platform === 'win32') {
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
const t = require('tap')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
5
|
const From = require('..')
|
|
6
|
-
const https = require('https')
|
|
6
|
+
const https = require('node:https')
|
|
7
7
|
const get = require('simple-get').concat
|
|
8
|
-
const fs = require('fs')
|
|
9
|
-
const querystring = require('querystring')
|
|
10
|
-
const path = require('path')
|
|
8
|
+
const fs = require('node:fs')
|
|
9
|
+
const querystring = require('node:querystring')
|
|
10
|
+
const path = require('node:path')
|
|
11
11
|
const certs = {
|
|
12
12
|
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.key')),
|
|
13
13
|
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.cert'))
|
package/test/unix-https.test.js
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
const t = require('tap')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
5
|
const From = require('..')
|
|
6
|
-
const https = require('https')
|
|
6
|
+
const https = require('node:https')
|
|
7
7
|
const get = require('simple-get').concat
|
|
8
|
-
const fs = require('fs')
|
|
9
|
-
const querystring = require('querystring')
|
|
10
|
-
const path = require('path')
|
|
8
|
+
const fs = require('node:fs')
|
|
9
|
+
const querystring = require('node:querystring')
|
|
10
|
+
const path = require('node:path')
|
|
11
11
|
const certs = {
|
|
12
12
|
key: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.key')),
|
|
13
13
|
cert: fs.readFileSync(path.join(__dirname, 'fixtures', 'fastify.cert'))
|
package/types/index.d.ts
CHANGED
|
@@ -1,33 +1,35 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
FastifyPluginCallback,
|
|
5
5
|
FastifyReply,
|
|
6
|
+
FastifyRequest,
|
|
7
|
+
HTTPMethods,
|
|
6
8
|
RawReplyDefaultExpression,
|
|
7
9
|
RawServerBase,
|
|
8
10
|
RequestGenericInterface,
|
|
9
|
-
|
|
10
|
-
FastifyPluginCallback,
|
|
11
|
+
RouteGenericInterface
|
|
11
12
|
} from 'fastify';
|
|
12
13
|
|
|
13
14
|
import {
|
|
15
|
+
Agent,
|
|
16
|
+
AgentOptions,
|
|
14
17
|
IncomingHttpHeaders,
|
|
15
18
|
RequestOptions,
|
|
16
|
-
AgentOptions,
|
|
17
|
-
Agent,
|
|
18
19
|
} from "http";
|
|
19
20
|
import {
|
|
20
|
-
RequestOptions as SecureRequestOptions,
|
|
21
|
-
AgentOptions as SecureAgentOptions,
|
|
22
|
-
Agent as SecureAgent
|
|
23
|
-
} from "https";
|
|
24
|
-
import {
|
|
25
|
-
IncomingHttpHeaders as Http2IncomingHttpHeaders,
|
|
26
|
-
ClientSessionRequestOptions,
|
|
27
21
|
ClientSessionOptions,
|
|
22
|
+
ClientSessionRequestOptions,
|
|
23
|
+
IncomingHttpHeaders as Http2IncomingHttpHeaders,
|
|
28
24
|
SecureClientSessionOptions,
|
|
29
25
|
} from "http2";
|
|
30
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
Agent as SecureAgent,
|
|
28
|
+
AgentOptions as SecureAgentOptions,
|
|
29
|
+
RequestOptions as SecureRequestOptions
|
|
30
|
+
} from "https";
|
|
31
|
+
import { Pool } from 'undici';
|
|
32
|
+
import { ProxyAgent } from 'undici';
|
|
31
33
|
|
|
32
34
|
declare module "fastify" {
|
|
33
35
|
interface FastifyReply {
|
|
@@ -39,19 +41,33 @@ declare module "fastify" {
|
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
type FastifyReplyFrom = FastifyPluginCallback<fastifyReplyFrom.FastifyReplyFromOptions>
|
|
42
|
-
|
|
43
44
|
declare namespace fastifyReplyFrom {
|
|
44
|
-
type QueryStringFunction = (
|
|
45
|
+
type QueryStringFunction = (
|
|
46
|
+
search: string | undefined,
|
|
47
|
+
reqUrl: string,
|
|
48
|
+
request: FastifyRequest<RequestGenericInterface, RawServerBase>
|
|
49
|
+
) => string;
|
|
50
|
+
|
|
51
|
+
export type RetryDetails = {
|
|
52
|
+
err: Error;
|
|
53
|
+
req: FastifyRequest<RequestGenericInterface, RawServerBase>;
|
|
54
|
+
res: FastifyReply<RouteGenericInterface, RawServerBase>;
|
|
55
|
+
attempt: number;
|
|
56
|
+
retriesCount: number;
|
|
57
|
+
getDefaultDelay: () => number | null;
|
|
58
|
+
}
|
|
45
59
|
export interface FastifyReplyFromHooks {
|
|
46
60
|
queryString?: { [key: string]: unknown } | QueryStringFunction;
|
|
47
61
|
contentType?: string;
|
|
62
|
+
retryDelay?: (details: RetryDetails) => {} | null;
|
|
63
|
+
retriesCount?: number;
|
|
48
64
|
onResponse?: (
|
|
49
65
|
request: FastifyRequest<RequestGenericInterface, RawServerBase>,
|
|
50
|
-
reply: FastifyReply<RawServerBase>,
|
|
66
|
+
reply: FastifyReply<RouteGenericInterface, RawServerBase>,
|
|
51
67
|
res: RawReplyDefaultExpression<RawServerBase>
|
|
52
68
|
) => void;
|
|
53
69
|
onError?: (
|
|
54
|
-
reply: FastifyReply<RawServerBase>,
|
|
70
|
+
reply: FastifyReply<RouteGenericInterface, RawServerBase>,
|
|
55
71
|
error: { error: Error }
|
|
56
72
|
) => void;
|
|
57
73
|
body?: unknown;
|
|
@@ -67,6 +83,7 @@ declare namespace fastifyReplyFrom {
|
|
|
67
83
|
request: FastifyRequest<RequestGenericInterface, RawServerBase>,
|
|
68
84
|
base: string
|
|
69
85
|
) => string;
|
|
86
|
+
method?: HTTPMethods;
|
|
70
87
|
}
|
|
71
88
|
|
|
72
89
|
interface Http2Options {
|
|
@@ -88,16 +105,17 @@ declare namespace fastifyReplyFrom {
|
|
|
88
105
|
disableCache?: boolean;
|
|
89
106
|
http?: HttpOptions;
|
|
90
107
|
http2?: Http2Options | boolean;
|
|
91
|
-
undici?: Pool.Options;
|
|
108
|
+
undici?: Pool.Options & { proxy?: string | URL | ProxyAgent.Options };
|
|
92
109
|
contentTypesToEncode?: string[];
|
|
93
110
|
retryMethods?: (HTTPMethods | 'TRACE')[];
|
|
94
111
|
maxRetriesOn503?: number;
|
|
95
112
|
disableRequestLogging?: boolean;
|
|
96
113
|
globalAgent?: boolean;
|
|
114
|
+
destroyAgent?: boolean;
|
|
97
115
|
}
|
|
98
116
|
|
|
99
117
|
export const fastifyReplyFrom: FastifyReplyFrom
|
|
100
|
-
export { fastifyReplyFrom as default }
|
|
118
|
+
export { fastifyReplyFrom as default };
|
|
101
119
|
}
|
|
102
120
|
|
|
103
121
|
declare function fastifyReplyFrom(...params: Parameters<FastifyReplyFrom>): ReturnType<FastifyReplyFrom>
|