@fastify/reply-from 7.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.
Files changed (88) hide show
  1. package/.github/dependabot.yml +13 -0
  2. package/.github/stale.yml +21 -0
  3. package/.github/workflows/ci.yml +60 -0
  4. package/.taprc +5 -0
  5. package/LICENSE +21 -0
  6. package/README.md +335 -0
  7. package/example.js +36 -0
  8. package/index.d.ts +99 -0
  9. package/index.js +262 -0
  10. package/lib/request.js +288 -0
  11. package/lib/utils.js +81 -0
  12. package/package.json +70 -0
  13. package/test/async-route-handler.js +50 -0
  14. package/test/base-get.js +48 -0
  15. package/test/base-path.js +38 -0
  16. package/test/base-querystring.js +48 -0
  17. package/test/build-url.js +69 -0
  18. package/test/core-with-path-in-base.js +50 -0
  19. package/test/custom-undici-instance.js +77 -0
  20. package/test/fastify-multipart-incompatibility.js +90 -0
  21. package/test/fixtures/fastify.cert +19 -0
  22. package/test/fixtures/fastify.key +27 -0
  23. package/test/fixtures/file.txt +1 -0
  24. package/test/full-get.js +45 -0
  25. package/test/full-https-get.js +55 -0
  26. package/test/full-post-extended-content-type.js +59 -0
  27. package/test/full-post-http2.js +49 -0
  28. package/test/full-post-stream-core.js +66 -0
  29. package/test/full-post-stream.js +64 -0
  30. package/test/full-post.js +56 -0
  31. package/test/full-querystring-rewrite-option-complex.js +48 -0
  32. package/test/full-querystring-rewrite-option-function.js +51 -0
  33. package/test/full-querystring-rewrite-option.js +48 -0
  34. package/test/full-querystring-rewrite-string.js +46 -0
  35. package/test/full-querystring-rewrite.js +46 -0
  36. package/test/full-querystring.js +46 -0
  37. package/test/full-rewrite-body-content-type.js +59 -0
  38. package/test/full-rewrite-body-http.js +63 -0
  39. package/test/full-rewrite-body-to-empty-string.js +61 -0
  40. package/test/full-rewrite-body-to-null.js +61 -0
  41. package/test/full-rewrite-body.js +61 -0
  42. package/test/get-upstream-http.js +70 -0
  43. package/test/get-upstream-undici.js +45 -0
  44. package/test/get-with-body.js +55 -0
  45. package/test/head-with-body.js +57 -0
  46. package/test/host-header.js +67 -0
  47. package/test/http-agents.js +55 -0
  48. package/test/http-http2.js +50 -0
  49. package/test/http-invalid-target.js +35 -0
  50. package/test/http-retry.js +109 -0
  51. package/test/http-timeout.js +56 -0
  52. package/test/http2-http2.js +57 -0
  53. package/test/http2-https.js +80 -0
  54. package/test/http2-invalid-target.js +36 -0
  55. package/test/http2-target-crash.js +53 -0
  56. package/test/http2-target-multi-crash.js +60 -0
  57. package/test/http2-timeout.js +92 -0
  58. package/test/https-agents.js +67 -0
  59. package/test/index.test-d.ts +136 -0
  60. package/test/modifyCoreObjects-false.js +48 -0
  61. package/test/no-body-opts-with-get.js +49 -0
  62. package/test/no-body-opts-with-head.js +51 -0
  63. package/test/no-stream-body-option.js +58 -0
  64. package/test/on-error.js +62 -0
  65. package/test/onResponse.js +48 -0
  66. package/test/padded-body.js +64 -0
  67. package/test/post-formbody.js +59 -0
  68. package/test/post-plain-text.js +56 -0
  69. package/test/post-with-custom-encoded-contenttype.js +65 -0
  70. package/test/retry-on-503.js +101 -0
  71. package/test/rewrite-headers.js +52 -0
  72. package/test/rewrite-request-headers.js +47 -0
  73. package/test/transform-body.js +61 -0
  74. package/test/undici-agent.js +77 -0
  75. package/test/undici-body.js +70 -0
  76. package/test/undici-options.js +73 -0
  77. package/test/undici-retry.js +109 -0
  78. package/test/undici-timeout-body-partial.js +60 -0
  79. package/test/undici-timeout-body.js +63 -0
  80. package/test/undici-timeout.js +61 -0
  81. package/test/undici-with-path-in-base.js +50 -0
  82. package/test/undici.js +50 -0
  83. package/test/unexpected-error.js +46 -0
  84. package/test/unix-http-undici-from.js +51 -0
  85. package/test/unix-http-undici.js +62 -0
  86. package/test/unix-http.js +65 -0
  87. package/test/unix-https-undici.js +71 -0
  88. package/test/unix-https.js +71 -0
@@ -0,0 +1,49 @@
1
+ 'use strict'
2
+
3
+ const { test } = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const got = require('got')
7
+
8
+ test('http -> http2', async function (t) {
9
+ const instance = Fastify()
10
+
11
+ t.teardown(instance.close.bind(instance))
12
+
13
+ const target = Fastify({
14
+ http2: true
15
+ })
16
+
17
+ target.post('/', (request, reply) => {
18
+ t.pass('request proxied')
19
+ t.same(request.body, { something: 'else' })
20
+ reply.code(200).header('x-my-header', 'hello!').send({
21
+ hello: 'world'
22
+ })
23
+ })
24
+
25
+ instance.post('/', (request, reply) => {
26
+ reply.from()
27
+ })
28
+
29
+ t.teardown(target.close.bind(target))
30
+
31
+ await target.listen(0)
32
+
33
+ instance.register(From, {
34
+ base: `http://localhost:${target.server.address().port}`,
35
+ http2: true
36
+ })
37
+
38
+ await instance.listen(0)
39
+
40
+ const { headers, body, statusCode } = await got(`http://localhost:${instance.server.address().port}`, {
41
+ method: 'POST',
42
+ json: { something: 'else' },
43
+ responseType: 'json'
44
+ })
45
+ t.equal(statusCode, 200)
46
+ t.equal(headers['x-my-header'], 'hello!')
47
+ t.match(headers['content-type'], /application\/json/)
48
+ t.same(body, { hello: 'world' })
49
+ })
@@ -0,0 +1,66 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const http = require('http')
7
+ const get = require('simple-get').concat
8
+
9
+ const instance = Fastify()
10
+ instance.register(From, {
11
+ http: true
12
+ })
13
+
14
+ t.plan(8)
15
+ t.teardown(instance.close.bind(instance))
16
+
17
+ instance.addContentTypeParser('application/octet-stream', function (req, payload, done) {
18
+ done(null, payload)
19
+ })
20
+
21
+ t.teardown(instance.close.bind(instance))
22
+
23
+ const target = http.createServer((req, res) => {
24
+ t.pass('request proxied')
25
+ t.equal(req.method, 'POST')
26
+ t.equal(req.headers['content-type'], 'application/octet-stream')
27
+ let data = ''
28
+ req.setEncoding('utf8')
29
+ req.on('data', (d) => {
30
+ data += d
31
+ })
32
+ req.on('end', () => {
33
+ t.same(JSON.parse(data), { hello: 'world' })
34
+ res.statusCode = 200
35
+ res.setHeader('content-type', 'application/octet-stream')
36
+ res.end(JSON.stringify({ something: 'else' }))
37
+ })
38
+ })
39
+
40
+ instance.post('/', (request, reply) => {
41
+ reply.from(`http://localhost:${target.address().port}`)
42
+ })
43
+
44
+ t.teardown(target.close.bind(target))
45
+
46
+ instance.listen(0, (err) => {
47
+ t.error(err)
48
+
49
+ target.listen(0, (err) => {
50
+ t.error(err)
51
+
52
+ get({
53
+ url: `http://localhost:${instance.server.address().port}`,
54
+ method: 'POST',
55
+ headers: {
56
+ 'content-type': 'application/octet-stream'
57
+ },
58
+ body: JSON.stringify({
59
+ hello: 'world'
60
+ })
61
+ }, (err, res, data) => {
62
+ t.error(err)
63
+ t.same(JSON.parse(data), { something: 'else' })
64
+ })
65
+ })
66
+ })
@@ -0,0 +1,64 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const http = require('http')
7
+ const get = require('simple-get').concat
8
+
9
+ const instance = Fastify()
10
+ instance.register(From)
11
+
12
+ t.plan(8)
13
+ t.teardown(instance.close.bind(instance))
14
+
15
+ instance.addContentTypeParser('application/octet-stream', function (req, payload, done) {
16
+ done(null, payload)
17
+ })
18
+
19
+ t.teardown(instance.close.bind(instance))
20
+
21
+ const target = http.createServer((req, res) => {
22
+ t.pass('request proxied')
23
+ t.equal(req.method, 'POST')
24
+ t.equal(req.headers['content-type'], 'application/octet-stream')
25
+ let data = ''
26
+ req.setEncoding('utf8')
27
+ req.on('data', (d) => {
28
+ data += d
29
+ })
30
+ req.on('end', () => {
31
+ t.same(JSON.parse(data), { hello: 'world' })
32
+ res.statusCode = 200
33
+ res.setHeader('content-type', 'application/octet-stream')
34
+ res.end(JSON.stringify({ something: 'else' }))
35
+ })
36
+ })
37
+
38
+ instance.post('/', (request, reply) => {
39
+ reply.from(`http://localhost:${target.address().port}`)
40
+ })
41
+
42
+ t.teardown(target.close.bind(target))
43
+
44
+ instance.listen(0, (err) => {
45
+ t.error(err)
46
+
47
+ target.listen(0, (err) => {
48
+ t.error(err)
49
+
50
+ get({
51
+ url: `http://localhost:${instance.server.address().port}`,
52
+ method: 'POST',
53
+ headers: {
54
+ 'content-type': 'application/octet-stream'
55
+ },
56
+ body: JSON.stringify({
57
+ hello: 'world'
58
+ })
59
+ }, (err, res, data) => {
60
+ t.error(err)
61
+ t.same(JSON.parse(data), { something: 'else' })
62
+ })
63
+ })
64
+ })
@@ -0,0 +1,56 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const http = require('http')
7
+ const get = require('simple-get').concat
8
+
9
+ const instance = Fastify()
10
+ instance.register(From)
11
+
12
+ t.plan(8)
13
+ t.teardown(instance.close.bind(instance))
14
+
15
+ const target = http.createServer((req, res) => {
16
+ t.pass('request proxied')
17
+ t.equal(req.method, 'POST')
18
+ t.equal(req.headers['content-type'], 'application/json')
19
+ let data = ''
20
+ req.setEncoding('utf8')
21
+ req.on('data', (d) => {
22
+ data += d
23
+ })
24
+ req.on('end', () => {
25
+ t.same(JSON.parse(data), { hello: 'world' })
26
+ res.statusCode = 200
27
+ res.setHeader('content-type', 'application/json')
28
+ res.end(JSON.stringify({ something: 'else' }))
29
+ })
30
+ })
31
+
32
+ instance.post('/', (request, reply) => {
33
+ reply.from(`http://localhost:${target.address().port}`)
34
+ })
35
+
36
+ t.teardown(target.close.bind(target))
37
+
38
+ instance.listen(0, (err) => {
39
+ t.error(err)
40
+
41
+ target.listen(0, (err) => {
42
+ t.error(err)
43
+
44
+ get({
45
+ url: `http://localhost:${instance.server.address().port}`,
46
+ method: 'POST',
47
+ json: true,
48
+ body: {
49
+ hello: 'world'
50
+ }
51
+ }, (err, res, data) => {
52
+ t.error(err)
53
+ t.same(data, { something: 'else' })
54
+ })
55
+ })
56
+ })
@@ -0,0 +1,48 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const http = require('http')
7
+ const get = require('simple-get').concat
8
+
9
+ const instance = Fastify()
10
+
11
+ t.plan(10)
12
+ t.teardown(instance.close.bind(instance))
13
+
14
+ const target = http.createServer((req, res) => {
15
+ t.pass('request proxied')
16
+ t.equal(req.method, 'GET')
17
+ t.equal(req.url, '/world?b=c')
18
+ res.statusCode = 205
19
+ res.setHeader('Content-Type', 'text/plain')
20
+ res.setHeader('x-my-header', 'hello!')
21
+ res.end('hello world')
22
+ })
23
+
24
+ instance.get('/hello', (request, reply) => {
25
+ reply.from(`http://localhost:${target.address().port}/world?a=b`, {
26
+ queryString: { b: 'c' }
27
+ })
28
+ })
29
+
30
+ t.teardown(target.close.bind(target))
31
+
32
+ target.listen(0, (err) => {
33
+ t.error(err)
34
+
35
+ instance.register(From)
36
+
37
+ instance.listen(0, (err) => {
38
+ t.error(err)
39
+
40
+ get(`http://localhost:${instance.server.address().port}/hello?a=b`, (err, res, data) => {
41
+ t.error(err)
42
+ t.equal(res.headers['content-type'], 'text/plain')
43
+ t.equal(res.headers['x-my-header'], 'hello!')
44
+ t.equal(res.statusCode, 205)
45
+ t.equal(data.toString(), 'hello world')
46
+ })
47
+ })
48
+ })
@@ -0,0 +1,51 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const http = require('http')
7
+ const get = require('simple-get').concat
8
+ const querystring = require('querystring')
9
+
10
+ const instance = Fastify()
11
+
12
+ t.plan(10)
13
+ t.teardown(instance.close.bind(instance))
14
+
15
+ const target = http.createServer((req, res) => {
16
+ t.pass('request proxied')
17
+ t.equal(req.method, 'GET')
18
+ t.equal(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
+ })
24
+
25
+ instance.get('/hello', (request, reply) => {
26
+ reply.from(`http://localhost:${target.address().port}/world?a=b`, {
27
+ queryString () {
28
+ return querystring.stringify({ b: 'c' })
29
+ }
30
+ })
31
+ })
32
+
33
+ t.teardown(target.close.bind(target))
34
+
35
+ target.listen(0, (err) => {
36
+ t.error(err)
37
+
38
+ instance.register(From)
39
+
40
+ instance.listen(0, (err) => {
41
+ t.error(err)
42
+
43
+ get(`http://localhost:${instance.server.address().port}/hello?a=b`, (err, res, data) => {
44
+ t.error(err)
45
+ t.equal(res.headers['content-type'], 'text/plain')
46
+ t.equal(res.headers['x-my-header'], 'hello!')
47
+ t.equal(res.statusCode, 205)
48
+ t.equal(data.toString(), 'hello world')
49
+ })
50
+ })
51
+ })
@@ -0,0 +1,48 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const http = require('http')
7
+ const get = require('simple-get').concat
8
+
9
+ const instance = Fastify()
10
+
11
+ t.plan(10)
12
+ t.teardown(instance.close.bind(instance))
13
+
14
+ const target = http.createServer((req, res) => {
15
+ t.pass('request proxied')
16
+ t.equal(req.method, 'GET')
17
+ t.equal(req.url, '/world?b=c')
18
+ res.statusCode = 205
19
+ res.setHeader('Content-Type', 'text/plain')
20
+ res.setHeader('x-my-header', 'hello!')
21
+ res.end('hello world')
22
+ })
23
+
24
+ instance.get('/hello', (request, reply) => {
25
+ reply.from(`http://localhost:${target.address().port}/world`, {
26
+ queryString: { b: 'c' }
27
+ })
28
+ })
29
+
30
+ t.teardown(target.close.bind(target))
31
+
32
+ target.listen(0, (err) => {
33
+ t.error(err)
34
+
35
+ instance.register(From)
36
+
37
+ instance.listen(0, (err) => {
38
+ t.error(err)
39
+
40
+ get(`http://localhost:${instance.server.address().port}/hello?a=b`, (err, res, data) => {
41
+ t.error(err)
42
+ t.equal(res.headers['content-type'], 'text/plain')
43
+ t.equal(res.headers['x-my-header'], 'hello!')
44
+ t.equal(res.statusCode, 205)
45
+ t.equal(data.toString(), 'hello world')
46
+ })
47
+ })
48
+ })
@@ -0,0 +1,46 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const http = require('http')
7
+ const get = require('simple-get').concat
8
+
9
+ const instance = Fastify()
10
+
11
+ t.plan(10)
12
+ t.teardown(instance.close.bind(instance))
13
+
14
+ const target = http.createServer((req, res) => {
15
+ t.pass('request proxied')
16
+ t.equal(req.method, 'GET')
17
+ t.equal(req.url, '/world?b=c')
18
+ res.statusCode = 205
19
+ res.setHeader('Content-Type', 'text/plain')
20
+ res.setHeader('x-my-header', 'hello!')
21
+ res.end('hello world')
22
+ })
23
+
24
+ instance.get('/hello', (request, reply) => {
25
+ reply.from(`http://localhost:${target.address().port}/world?b=c`)
26
+ })
27
+
28
+ t.teardown(target.close.bind(target))
29
+
30
+ target.listen(0, (err) => {
31
+ t.error(err)
32
+
33
+ instance.register(From)
34
+
35
+ instance.listen(0, (err) => {
36
+ t.error(err)
37
+
38
+ get(`http://localhost:${instance.server.address().port}/hello?a=b`, (err, res, data) => {
39
+ t.error(err)
40
+ t.equal(res.headers['content-type'], 'text/plain')
41
+ t.equal(res.headers['x-my-header'], 'hello!')
42
+ t.equal(res.statusCode, 205)
43
+ t.equal(data.toString(), 'hello world')
44
+ })
45
+ })
46
+ })
@@ -0,0 +1,46 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const http = require('http')
7
+ const get = require('simple-get').concat
8
+
9
+ const instance = Fastify()
10
+
11
+ t.plan(10)
12
+ t.teardown(instance.close.bind(instance))
13
+
14
+ const target = http.createServer((req, res) => {
15
+ t.pass('request proxied')
16
+ t.equal(req.method, 'GET')
17
+ t.equal(req.url, '/world?a=b')
18
+ res.statusCode = 205
19
+ res.setHeader('Content-Type', 'text/plain')
20
+ res.setHeader('x-my-header', 'hello!')
21
+ res.end('hello world')
22
+ })
23
+
24
+ instance.get('/hello', (request, reply) => {
25
+ reply.from(`http://localhost:${target.address().port}/world`)
26
+ })
27
+
28
+ t.teardown(target.close.bind(target))
29
+
30
+ target.listen(0, (err) => {
31
+ t.error(err)
32
+
33
+ instance.register(From)
34
+
35
+ instance.listen(0, (err) => {
36
+ t.error(err)
37
+
38
+ get(`http://localhost:${instance.server.address().port}/hello?a=b`, (err, res, data) => {
39
+ t.error(err)
40
+ t.equal(res.headers['content-type'], 'text/plain')
41
+ t.equal(res.headers['x-my-header'], 'hello!')
42
+ t.equal(res.statusCode, 205)
43
+ t.equal(data.toString(), 'hello world')
44
+ })
45
+ })
46
+ })
@@ -0,0 +1,46 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const http = require('http')
7
+ const get = require('simple-get').concat
8
+
9
+ const instance = Fastify()
10
+
11
+ t.plan(10)
12
+ t.teardown(instance.close.bind(instance))
13
+
14
+ const target = http.createServer((req, res) => {
15
+ t.pass('request proxied')
16
+ t.equal(req.method, 'GET')
17
+ t.equal(req.url, '/world?a=b')
18
+ res.statusCode = 205
19
+ res.setHeader('Content-Type', 'text/plain')
20
+ res.setHeader('x-my-header', 'hello!')
21
+ res.end('hello world')
22
+ })
23
+
24
+ instance.get('/hello', (request, reply) => {
25
+ reply.from(`http://localhost:${target.address().port}/world`)
26
+ })
27
+
28
+ t.teardown(target.close.bind(target))
29
+
30
+ target.listen(0, (err) => {
31
+ t.error(err)
32
+
33
+ instance.register(From)
34
+
35
+ instance.listen(0, (err) => {
36
+ t.error(err)
37
+
38
+ get(`http://localhost:${instance.server.address().port}/hello?a=b`, (err, res, data) => {
39
+ t.error(err)
40
+ t.equal(res.headers['content-type'], 'text/plain')
41
+ t.equal(res.headers['x-my-header'], 'hello!')
42
+ t.equal(res.statusCode, 205)
43
+ t.equal(data.toString(), 'hello world')
44
+ })
45
+ })
46
+ })
@@ -0,0 +1,59 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const http = require('http')
7
+ const get = require('simple-get').concat
8
+ const msgpack = require('msgpack5')()
9
+
10
+ const instance = Fastify()
11
+ instance.register(From)
12
+
13
+ t.plan(8)
14
+ t.teardown(instance.close.bind(instance))
15
+
16
+ const target = http.createServer((req, res) => {
17
+ t.pass('request proxied')
18
+ t.equal(req.method, 'POST')
19
+ t.equal(req.headers['content-type'], 'application/msgpack')
20
+ const data = []
21
+ req.on('data', (d) => {
22
+ data.push(d)
23
+ })
24
+ req.on('end', () => {
25
+ t.same(msgpack.decode(Buffer.concat(data)), { hello: 'world' })
26
+ res.statusCode = 200
27
+ res.setHeader('content-type', 'application/json')
28
+ res.end(JSON.stringify({ something: 'else' }))
29
+ })
30
+ })
31
+
32
+ instance.post('/', (request, reply) => {
33
+ reply.from(`http://localhost:${target.address().port}`, {
34
+ contentType: 'application/msgpack',
35
+ body: msgpack.encode(request.body)
36
+ })
37
+ })
38
+
39
+ t.teardown(target.close.bind(target))
40
+
41
+ instance.listen(0, (err) => {
42
+ t.error(err)
43
+
44
+ target.listen(0, (err) => {
45
+ t.error(err)
46
+
47
+ get({
48
+ url: `http://localhost:${instance.server.address().port}`,
49
+ method: 'POST',
50
+ json: true,
51
+ body: {
52
+ hello: 'world'
53
+ }
54
+ }, (err, res, data) => {
55
+ t.error(err)
56
+ t.same(data, { something: 'else' })
57
+ })
58
+ })
59
+ })
@@ -0,0 +1,63 @@
1
+ 'use strict'
2
+
3
+ const t = require('tap')
4
+ const Fastify = require('fastify')
5
+ const From = require('..')
6
+ const http = require('http')
7
+ const get = require('simple-get').concat
8
+
9
+ const instance = Fastify()
10
+ instance.register(From, {
11
+ http: true
12
+ })
13
+
14
+ t.plan(9)
15
+ t.teardown(instance.close.bind(instance))
16
+
17
+ const target = http.createServer((req, res) => {
18
+ t.pass('request proxied')
19
+ t.equal(req.method, 'POST')
20
+ t.equal(req.headers['content-type'], 'application/json')
21
+ t.equal(req.headers['content-length'], '20')
22
+ let data = ''
23
+ req.setEncoding('utf8')
24
+ req.on('data', (d) => {
25
+ data += d
26
+ })
27
+ req.on('end', () => {
28
+ t.same(JSON.parse(data), { something: 'else' })
29
+ res.statusCode = 200
30
+ res.setHeader('content-type', 'application/json')
31
+ res.end(JSON.stringify({ hello: 'fastify' }))
32
+ })
33
+ })
34
+
35
+ instance.post('/', (request, reply) => {
36
+ reply.from(`http://localhost:${target.address().port}`, {
37
+ body: {
38
+ something: 'else'
39
+ }
40
+ })
41
+ })
42
+
43
+ t.teardown(target.close.bind(target))
44
+
45
+ instance.listen(0, (err) => {
46
+ t.error(err)
47
+
48
+ target.listen(0, (err) => {
49
+ t.error(err)
50
+
51
+ get({
52
+ url: `http://localhost:${instance.server.address().port}`,
53
+ method: 'POST',
54
+ json: true,
55
+ body: {
56
+ hello: 'world'
57
+ }
58
+ }, (err, res, data) => {
59
+ t.error(err)
60
+ t.same(data, { hello: 'fastify' })
61
+ })
62
+ })
63
+ })