@fastify/reply-from 12.0.2 → 12.2.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/.github/workflows/ci.yml +6 -0
- package/CLAUDE.md +66 -0
- package/LICENSE +4 -1
- package/README.md +24 -0
- package/index.js +12 -1
- package/lib/request.js +16 -6
- package/lib/utils.js +1 -0
- package/package.json +6 -8
- package/test/async-route-handler.test.js +29 -32
- package/test/balanced-pool.test.js +48 -0
- package/test/base-get.test.js +27 -30
- package/test/base-path.test.js +27 -24
- package/test/base-querystring.test.js +27 -30
- package/test/build-url.test.js +17 -15
- package/test/core-with-path-in-base.test.js +30 -33
- package/test/custom-undici-instance.test.js +28 -36
- package/test/disable-request-logging.test.js +38 -52
- package/test/fastify-multipart-incompatibility.test.js +43 -49
- package/test/fix-GHSA-v2v2-hph8-q5xp.test.js +3 -2
- package/test/full-delete-http2.test.js +12 -11
- package/test/full-get-test.test.js +27 -30
- package/test/full-https-get.test.js +30 -30
- package/test/full-post-extended-content-type.test.js +40 -44
- package/test/full-post-http2.test.js +18 -13
- package/test/full-post-stream-core.test.js +39 -43
- package/test/full-post-stream.test.js +39 -43
- package/test/full-post.test.js +36 -38
- package/test/full-querystring-rewrite-option-complex.test.js +27 -31
- package/test/full-querystring-rewrite-option-function-request.test.js +30 -36
- package/test/full-querystring-rewrite-option-function.test.js +30 -33
- package/test/full-querystring-rewrite-option.test.js +28 -31
- package/test/full-querystring-rewrite-string.test.js +27 -30
- package/test/full-querystring-rewrite.test.js +27 -30
- package/test/full-querystring.test.js +27 -30
- package/test/full-rewrite-body-content-type.test.js +37 -41
- package/test/full-rewrite-body-http.test.js +39 -43
- package/test/full-rewrite-body-to-empty-string.test.js +37 -41
- package/test/full-rewrite-body-to-null.test.js +37 -41
- package/test/full-rewrite-body.test.js +39 -43
- package/test/get-upstream-cache.test.js +12 -11
- package/test/get-upstream-http.test.js +35 -41
- package/test/get-upstream-type.test.js +24 -27
- package/test/get-upstream-undici.test.js +23 -26
- package/test/host-header.test.js +22 -18
- package/test/http-agents.test.js +27 -30
- package/test/http-global-agent.test.js +20 -33
- package/test/http-http2.test.js +13 -18
- package/test/http-invalid-target.test.js +13 -17
- package/test/http-retry.test.js +22 -29
- package/test/http-timeout.test.js +87 -27
- package/test/http2-canceled-streams-cleanup.test.js +117 -0
- package/test/http2-http2.test.js +8 -8
- package/test/http2-https.test.js +29 -27
- package/test/http2-invalid-base.test.js +2 -2
- package/test/http2-invalid-target.test.js +13 -17
- package/test/http2-target-crash.test.js +16 -20
- package/test/http2-target-multi-crash.test.js +22 -27
- package/test/http2-timeout-disabled.test.js +20 -15
- package/test/http2-timeout.test.js +94 -43
- package/test/http2-unix-socket.test.js +2 -2
- package/test/https-agents.test.js +31 -30
- package/test/https-global-agent.test.js +22 -31
- package/test/method.test.js +37 -42
- package/test/modifyCoreObjects-false.test.js +27 -30
- package/test/no-body-opts-with-get.test.js +25 -31
- package/test/no-body-opts-with-head.test.js +28 -32
- package/test/no-stream-body-option.test.js +34 -36
- package/test/on-error.test.js +21 -23
- package/test/on-invalid-upstream-response.test.js +30 -37
- package/test/onResponse.test.js +25 -32
- package/test/padded-body.test.js +38 -43
- package/test/post-formbody.test.js +35 -40
- package/test/post-plain-text.test.js +35 -39
- package/test/post-with-custom-encoded-contenttype.test.js +37 -39
- package/test/post-with-octet-stream.test.js +18 -88
- package/test/retry-on-503.test.js +27 -26
- package/test/retry-with-a-custom-handler.test.js +33 -40
- package/test/rewrite-headers-type.test.js +24 -29
- package/test/rewrite-headers.test.js +31 -36
- package/test/rewrite-request-headers-type.test.js +25 -28
- package/test/rewrite-request-headers.test.js +26 -30
- package/test/transform-body.test.js +37 -43
- package/test/undici-agent.test.js +27 -31
- package/test/undici-body.test.js +37 -42
- package/test/undici-chaining.test.js +35 -42
- package/test/undici-connect-timeout.test.js +13 -13
- package/test/undici-custom-dispatcher.test.js +11 -11
- package/test/undici-global-agent.test.js +14 -33
- package/test/undici-no-destroy.test.js +2 -2
- package/test/undici-options.test.js +21 -24
- package/test/undici-proxy-agent.test.js +4 -3
- package/test/undici-retry.test.js +24 -31
- package/test/undici-timeout-body-partial.test.js +14 -16
- package/test/undici-timeout-body.test.js +17 -19
- package/test/undici-timeout.test.js +86 -23
- package/test/undici-with-path-in-base.test.js +28 -31
- package/test/undici.test.js +28 -31
- package/test/unexpected-error.test.js +13 -18
- package/test/unix-http-undici-from.test.js +22 -31
- package/test/unix-http-undici.test.js +32 -40
- package/test/unix-http.test.js +31 -39
- package/test/unix-https-undici.test.js +30 -35
- package/test/unix-https.test.js +35 -40
- package/types/index.d.ts +13 -5
- package/types/index.test-d.ts +6 -6
- package/test/get-with-body.test.js +0 -55
- package/test/head-with-body.test.js +0 -57
|
@@ -1,48 +1,44 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const t = require('
|
|
3
|
+
const t = require('node:test')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
|
+
const { request } = require('undici')
|
|
5
6
|
const From = require('..')
|
|
6
7
|
const http = require('node:http')
|
|
7
|
-
const get = require('simple-get').concat
|
|
8
8
|
|
|
9
9
|
const instance = Fastify()
|
|
10
10
|
|
|
11
|
-
t.
|
|
12
|
-
t.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
t.test('full querystring rewrite option complex', async (t) => {
|
|
12
|
+
t.plan(7)
|
|
13
|
+
t.after(() => instance.close())
|
|
14
|
+
|
|
15
|
+
const target = http.createServer((req, res) => {
|
|
16
|
+
t.assert.ok('request proxied')
|
|
17
|
+
t.assert.strictEqual(req.method, 'GET')
|
|
18
|
+
t.assert.strictEqual(req.url, '/world?b=c')
|
|
19
|
+
res.statusCode = 205
|
|
20
|
+
res.setHeader('Content-Type', 'text/plain')
|
|
21
|
+
res.setHeader('x-my-header', 'hello!')
|
|
22
|
+
res.end('hello world')
|
|
23
|
+
})
|
|
23
24
|
|
|
24
|
-
instance.get('/hello', (_request, reply) => {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
instance.get('/hello', (_request, reply) => {
|
|
26
|
+
reply.from(`http://localhost:${target.address().port}/world?a=b`, {
|
|
27
|
+
queryString: { b: 'c' }
|
|
28
|
+
})
|
|
27
29
|
})
|
|
28
|
-
})
|
|
29
30
|
|
|
30
|
-
t.
|
|
31
|
+
t.after(() => target.close())
|
|
31
32
|
|
|
32
|
-
target.listen({ port: 0 },
|
|
33
|
-
t.error(err)
|
|
33
|
+
await new Promise(resolve => target.listen({ port: 0 }, resolve))
|
|
34
34
|
|
|
35
35
|
instance.register(From)
|
|
36
36
|
|
|
37
|
-
instance.listen({ port: 0 },
|
|
38
|
-
t.error(err)
|
|
37
|
+
await new Promise(resolve => instance.listen({ port: 0 }, resolve))
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
t.equal(data.toString(), 'hello world')
|
|
46
|
-
})
|
|
47
|
-
})
|
|
39
|
+
const result = await request(`http://localhost:${instance.server.address().port}/hello?a=b`)
|
|
40
|
+
t.assert.strictEqual(result.headers['content-type'], 'text/plain')
|
|
41
|
+
t.assert.strictEqual(result.headers['x-my-header'], 'hello!')
|
|
42
|
+
t.assert.strictEqual(result.statusCode, 205)
|
|
43
|
+
t.assert.strictEqual(await result.body.text(), 'hello world')
|
|
48
44
|
})
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const t = require('
|
|
3
|
+
const t = require('node:test')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
|
+
const { request } = require('undici')
|
|
5
6
|
const From = require('..')
|
|
6
7
|
const http = require('node:http')
|
|
7
|
-
const get = require('simple-get').concat
|
|
8
8
|
const querystring = require('node:querystring')
|
|
9
9
|
|
|
10
10
|
const instance = Fastify()
|
|
@@ -14,45 +14,39 @@ instance.addHook('preHandler', (request, _reply, done) => {
|
|
|
14
14
|
done()
|
|
15
15
|
})
|
|
16
16
|
|
|
17
|
-
t.
|
|
18
|
-
t.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
t.test('full querystring rewrite option function request', async (t) => {
|
|
18
|
+
t.plan(7)
|
|
19
|
+
t.after(() => instance.close())
|
|
20
|
+
|
|
21
|
+
const target = http.createServer((req, res) => {
|
|
22
|
+
t.assert.ok('request proxied')
|
|
23
|
+
t.assert.strictEqual(req.method, 'GET')
|
|
24
|
+
t.assert.strictEqual(req.url, '/world?q=test')
|
|
25
|
+
res.statusCode = 205
|
|
26
|
+
res.setHeader('Content-Type', 'text/plain')
|
|
27
|
+
res.setHeader('x-my-header', 'hello!')
|
|
28
|
+
res.end('hello world')
|
|
29
|
+
})
|
|
29
30
|
|
|
30
|
-
instance.get('/hello', (_request, reply) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
instance.get('/hello', (_request, reply) => {
|
|
32
|
+
reply.from(`http://localhost:${target.address().port}/world?a=b`, {
|
|
33
|
+
queryString (_search, _reqUrl, request) {
|
|
34
|
+
return querystring.stringify({ q: request.addedVal })
|
|
35
|
+
}
|
|
36
|
+
})
|
|
35
37
|
})
|
|
36
|
-
})
|
|
37
38
|
|
|
38
|
-
t.
|
|
39
|
+
t.after(() => target.close())
|
|
39
40
|
|
|
40
|
-
target.listen({ port: 0 },
|
|
41
|
-
t.error(err)
|
|
41
|
+
await new Promise(resolve => target.listen({ port: 0 }, resolve))
|
|
42
42
|
|
|
43
43
|
instance.register(From)
|
|
44
44
|
|
|
45
|
-
instance.listen({ port: 0 },
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
t.equal(res.statusCode, 205)
|
|
53
|
-
t.equal(data.toString(), 'hello world')
|
|
54
|
-
instance.close()
|
|
55
|
-
target.close()
|
|
56
|
-
})
|
|
57
|
-
})
|
|
45
|
+
await new Promise(resolve => instance.listen({ port: 0 }, resolve))
|
|
46
|
+
|
|
47
|
+
const result = await request(`http://localhost:${instance.server.address().port}/hello?a=b`)
|
|
48
|
+
t.assert.strictEqual(result.headers['content-type'], 'text/plain')
|
|
49
|
+
t.assert.strictEqual(result.headers['x-my-header'], 'hello!')
|
|
50
|
+
t.assert.strictEqual(result.statusCode, 205)
|
|
51
|
+
t.assert.strictEqual(await result.body.text(), 'hello world')
|
|
58
52
|
})
|
|
@@ -1,51 +1,48 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const t = require('
|
|
3
|
+
const t = require('node:test')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
|
+
const { request } = require('undici')
|
|
5
6
|
const From = require('..')
|
|
6
7
|
const http = require('node:http')
|
|
7
|
-
const get = require('simple-get').concat
|
|
8
8
|
const querystring = require('node:querystring')
|
|
9
9
|
|
|
10
10
|
const instance = Fastify()
|
|
11
11
|
|
|
12
|
-
t.
|
|
13
|
-
t.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
t.test('full querystring rewrite option function', async (t) => {
|
|
13
|
+
t.plan(7)
|
|
14
|
+
t.after(() => instance.close())
|
|
15
|
+
|
|
16
|
+
const target = http.createServer((req, res) => {
|
|
17
|
+
t.assert.ok('request proxied')
|
|
18
|
+
t.assert.strictEqual(req.method, 'GET')
|
|
19
|
+
t.assert.strictEqual(req.url, '/world?b=c')
|
|
20
|
+
res.statusCode = 205
|
|
21
|
+
res.setHeader('Content-Type', 'text/plain')
|
|
22
|
+
res.setHeader('x-my-header', 'hello!')
|
|
23
|
+
res.end('hello world')
|
|
24
|
+
})
|
|
24
25
|
|
|
25
|
-
instance.get('/hello', (_request, reply) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
instance.get('/hello', (_request, reply) => {
|
|
27
|
+
reply.from(`http://localhost:${target.address().port}/world?a=b`, {
|
|
28
|
+
queryString () {
|
|
29
|
+
return querystring.stringify({ b: 'c' })
|
|
30
|
+
}
|
|
31
|
+
})
|
|
30
32
|
})
|
|
31
|
-
})
|
|
32
33
|
|
|
33
|
-
t.
|
|
34
|
+
t.after(() => target.close())
|
|
34
35
|
|
|
35
|
-
target.listen({ port: 0 },
|
|
36
|
-
t.error(err)
|
|
36
|
+
await new Promise(resolve => target.listen({ port: 0 }, resolve))
|
|
37
37
|
|
|
38
38
|
instance.register(From)
|
|
39
39
|
|
|
40
|
-
instance.listen({ port: 0 },
|
|
41
|
-
t.error(err)
|
|
40
|
+
await new Promise(resolve => instance.listen({ port: 0 }, resolve))
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})
|
|
50
|
-
})
|
|
42
|
+
const result = await request(`http://localhost:${instance.server.address().port}/hello?a=b`)
|
|
43
|
+
|
|
44
|
+
t.assert.strictEqual(result.headers['content-type'], 'text/plain')
|
|
45
|
+
t.assert.strictEqual(result.headers['x-my-header'], 'hello!')
|
|
46
|
+
t.assert.strictEqual(result.statusCode, 205)
|
|
47
|
+
t.assert.strictEqual(await result.body.text(), 'hello world')
|
|
51
48
|
})
|
|
@@ -1,48 +1,45 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const t = require('
|
|
3
|
+
const t = require('node:test')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
|
+
const { request } = require('undici')
|
|
5
6
|
const From = require('..')
|
|
6
7
|
const http = require('node:http')
|
|
7
|
-
const get = require('simple-get').concat
|
|
8
8
|
|
|
9
9
|
const instance = Fastify()
|
|
10
10
|
|
|
11
|
-
t.
|
|
12
|
-
t.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
t.test('full querystring rewrite option', async (t) => {
|
|
12
|
+
t.plan(7)
|
|
13
|
+
t.after(() => instance.close())
|
|
14
|
+
|
|
15
|
+
const target = http.createServer((req, res) => {
|
|
16
|
+
t.assert.ok('request proxied')
|
|
17
|
+
t.assert.strictEqual(req.method, 'GET')
|
|
18
|
+
t.assert.strictEqual(req.url, '/world?b=c')
|
|
19
|
+
res.statusCode = 205
|
|
20
|
+
res.setHeader('Content-Type', 'text/plain')
|
|
21
|
+
res.setHeader('x-my-header', 'hello!')
|
|
22
|
+
res.end('hello world')
|
|
23
|
+
})
|
|
23
24
|
|
|
24
|
-
instance.get('/hello', (_request, reply) => {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
instance.get('/hello', (_request, reply) => {
|
|
26
|
+
reply.from(`http://localhost:${target.address().port}/world`, {
|
|
27
|
+
queryString: { b: 'c' }
|
|
28
|
+
})
|
|
27
29
|
})
|
|
28
|
-
})
|
|
29
30
|
|
|
30
|
-
t.
|
|
31
|
+
t.after(() => target.close())
|
|
31
32
|
|
|
32
|
-
target.listen({ port: 0 },
|
|
33
|
-
t.error(err)
|
|
33
|
+
await new Promise(resolve => target.listen({ port: 0 }, resolve))
|
|
34
34
|
|
|
35
35
|
instance.register(From)
|
|
36
36
|
|
|
37
|
-
instance.listen({ port: 0 },
|
|
38
|
-
t.error(err)
|
|
37
|
+
await new Promise(resolve => instance.listen({ port: 0 }, resolve))
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|
|
47
|
-
})
|
|
39
|
+
const result = await request(`http://localhost:${instance.server.address().port}/hello?a=b`)
|
|
40
|
+
|
|
41
|
+
t.assert.strictEqual(result.headers['content-type'], 'text/plain')
|
|
42
|
+
t.assert.strictEqual(result.headers['x-my-header'], 'hello!')
|
|
43
|
+
t.assert.strictEqual(result.statusCode, 205)
|
|
44
|
+
t.assert.strictEqual(await result.body.text(), 'hello world')
|
|
48
45
|
})
|
|
@@ -1,46 +1,43 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const t = require('
|
|
3
|
+
const t = require('node:test')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
|
+
const { request } = require('undici')
|
|
5
6
|
const From = require('..')
|
|
6
7
|
const http = require('node:http')
|
|
7
|
-
const get = require('simple-get').concat
|
|
8
8
|
|
|
9
9
|
const instance = Fastify()
|
|
10
10
|
|
|
11
|
-
t.
|
|
12
|
-
t.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
t.test('full querystring rewrite string', async (t) => {
|
|
12
|
+
t.plan(7)
|
|
13
|
+
t.after(() => instance.close())
|
|
14
|
+
|
|
15
|
+
const target = http.createServer((req, res) => {
|
|
16
|
+
t.assert.ok('request proxied')
|
|
17
|
+
t.assert.strictEqual(req.method, 'GET')
|
|
18
|
+
t.assert.strictEqual(req.url, '/world?b=c')
|
|
19
|
+
res.statusCode = 205
|
|
20
|
+
res.setHeader('Content-Type', 'text/plain')
|
|
21
|
+
res.setHeader('x-my-header', 'hello!')
|
|
22
|
+
res.end('hello world')
|
|
23
|
+
})
|
|
23
24
|
|
|
24
|
-
instance.get('/hello', (_request, reply) => {
|
|
25
|
-
|
|
26
|
-
})
|
|
25
|
+
instance.get('/hello', (_request, reply) => {
|
|
26
|
+
reply.from(`http://localhost:${target.address().port}/world?b=c`)
|
|
27
|
+
})
|
|
27
28
|
|
|
28
|
-
t.
|
|
29
|
+
t.after(() => target.close())
|
|
29
30
|
|
|
30
|
-
target.listen({ port: 0 },
|
|
31
|
-
t.error(err)
|
|
31
|
+
await new Promise(resolve => target.listen({ port: 0 }, resolve))
|
|
32
32
|
|
|
33
33
|
instance.register(From)
|
|
34
34
|
|
|
35
|
-
instance.listen({ port: 0 },
|
|
36
|
-
t.error(err)
|
|
35
|
+
await new Promise(resolve => instance.listen({ port: 0 }, resolve))
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
})
|
|
45
|
-
})
|
|
37
|
+
const result = await request(`http://localhost:${instance.server.address().port}/hello?a=b`)
|
|
38
|
+
|
|
39
|
+
t.assert.strictEqual(result.headers['content-type'], 'text/plain')
|
|
40
|
+
t.assert.strictEqual(result.headers['x-my-header'], 'hello!')
|
|
41
|
+
t.assert.strictEqual(result.statusCode, 205)
|
|
42
|
+
t.assert.strictEqual(await result.body.text(), 'hello world')
|
|
46
43
|
})
|
|
@@ -1,46 +1,43 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const t = require('
|
|
3
|
+
const t = require('node:test')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
|
+
const { request } = require('undici')
|
|
5
6
|
const From = require('..')
|
|
6
7
|
const http = require('node:http')
|
|
7
|
-
const get = require('simple-get').concat
|
|
8
8
|
|
|
9
9
|
const instance = Fastify()
|
|
10
10
|
|
|
11
|
-
t.
|
|
12
|
-
t.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
t.test('full querystring rewrite', async (t) => {
|
|
12
|
+
t.plan(7)
|
|
13
|
+
t.after(() => instance.close())
|
|
14
|
+
|
|
15
|
+
const target = http.createServer((req, res) => {
|
|
16
|
+
t.assert.ok('request proxied')
|
|
17
|
+
t.assert.strictEqual(req.method, 'GET')
|
|
18
|
+
t.assert.strictEqual(req.url, '/world?a=b')
|
|
19
|
+
res.statusCode = 205
|
|
20
|
+
res.setHeader('Content-Type', 'text/plain')
|
|
21
|
+
res.setHeader('x-my-header', 'hello!')
|
|
22
|
+
res.end('hello world')
|
|
23
|
+
})
|
|
23
24
|
|
|
24
|
-
instance.get('/hello', (_request, reply) => {
|
|
25
|
-
|
|
26
|
-
})
|
|
25
|
+
instance.get('/hello', (_request, reply) => {
|
|
26
|
+
reply.from(`http://localhost:${target.address().port}/world`)
|
|
27
|
+
})
|
|
27
28
|
|
|
28
|
-
t.
|
|
29
|
+
t.after(() => target.close())
|
|
29
30
|
|
|
30
|
-
target.listen({ port: 0 },
|
|
31
|
-
t.error(err)
|
|
31
|
+
await new Promise(resolve => target.listen({ port: 0 }, resolve))
|
|
32
32
|
|
|
33
33
|
instance.register(From)
|
|
34
34
|
|
|
35
|
-
instance.listen({ port: 0 },
|
|
36
|
-
t.error(err)
|
|
35
|
+
await new Promise(resolve => instance.listen({ port: 0 }, resolve))
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
})
|
|
45
|
-
})
|
|
37
|
+
const result = await request(`http://localhost:${instance.server.address().port}/hello?a=b`)
|
|
38
|
+
|
|
39
|
+
t.assert.strictEqual(result.headers['content-type'], 'text/plain')
|
|
40
|
+
t.assert.strictEqual(result.headers['x-my-header'], 'hello!')
|
|
41
|
+
t.assert.strictEqual(result.statusCode, 205)
|
|
42
|
+
t.assert.strictEqual(await result.body.text(), 'hello world')
|
|
46
43
|
})
|
|
@@ -1,46 +1,43 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const t = require('
|
|
3
|
+
const t = require('node:test')
|
|
4
4
|
const Fastify = require('fastify')
|
|
5
|
+
const { request } = require('undici')
|
|
5
6
|
const From = require('..')
|
|
6
7
|
const http = require('node:http')
|
|
7
|
-
const get = require('simple-get').concat
|
|
8
8
|
|
|
9
9
|
const instance = Fastify()
|
|
10
10
|
|
|
11
|
-
t.
|
|
12
|
-
t.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
11
|
+
t.test('full querystring rewrite', async (t) => {
|
|
12
|
+
t.plan(7)
|
|
13
|
+
t.after(() => instance.close())
|
|
14
|
+
|
|
15
|
+
const target = http.createServer((req, res) => {
|
|
16
|
+
t.assert.ok('request proxied')
|
|
17
|
+
t.assert.strictEqual(req.method, 'GET')
|
|
18
|
+
t.assert.strictEqual(req.url, '/world?a=b')
|
|
19
|
+
res.statusCode = 205
|
|
20
|
+
res.setHeader('Content-Type', 'text/plain')
|
|
21
|
+
res.setHeader('x-my-header', 'hello!')
|
|
22
|
+
res.end('hello world')
|
|
23
|
+
})
|
|
23
24
|
|
|
24
|
-
instance.get('/hello', (_request, reply) => {
|
|
25
|
-
|
|
26
|
-
})
|
|
25
|
+
instance.get('/hello', (_request, reply) => {
|
|
26
|
+
reply.from(`http://localhost:${target.address().port}/world`)
|
|
27
|
+
})
|
|
27
28
|
|
|
28
|
-
t.
|
|
29
|
+
t.after(() => target.close())
|
|
29
30
|
|
|
30
|
-
target.listen({ port: 0 },
|
|
31
|
-
t.error(err)
|
|
31
|
+
await new Promise(resolve => target.listen({ port: 0 }, resolve))
|
|
32
32
|
|
|
33
33
|
instance.register(From)
|
|
34
34
|
|
|
35
|
-
instance.listen({ port: 0 },
|
|
36
|
-
t.error(err)
|
|
35
|
+
await new Promise(resolve => instance.listen({ port: 0 }, resolve))
|
|
37
36
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
})
|
|
45
|
-
})
|
|
37
|
+
const result = await request(`http://localhost:${instance.server.address().port}/hello?a=b`)
|
|
38
|
+
|
|
39
|
+
t.assert.strictEqual(result.headers['content-type'], 'text/plain')
|
|
40
|
+
t.assert.strictEqual(result.headers['x-my-header'], 'hello!')
|
|
41
|
+
t.assert.strictEqual(result.statusCode, 205)
|
|
42
|
+
t.assert.strictEqual(await result.body.text(), 'hello world')
|
|
46
43
|
})
|