@fastify/reply-from 7.0.0 → 8.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.
Files changed (78) hide show
  1. package/.github/workflows/ci.yml +6 -51
  2. package/README.md +26 -15
  3. package/index.d.ts +1 -0
  4. package/index.js +8 -4
  5. package/package.json +18 -21
  6. package/test/async-route-handler.js +2 -2
  7. package/test/base-get.js +2 -2
  8. package/test/base-path.js +1 -1
  9. package/test/base-querystring.js +2 -2
  10. package/test/core-with-path-in-base.js +2 -2
  11. package/test/custom-undici-instance.js +3 -3
  12. package/test/disable-request-logging.js +159 -0
  13. package/test/fastify-multipart-incompatibility.js +4 -4
  14. package/test/full-get.js +2 -2
  15. package/test/full-https-get.js +2 -2
  16. package/test/full-post-extended-content-type.js +2 -2
  17. package/test/full-post-http2.js +2 -2
  18. package/test/full-post-stream-core.js +2 -2
  19. package/test/full-post-stream.js +2 -2
  20. package/test/full-post.js +2 -2
  21. package/test/full-querystring-rewrite-option-complex.js +2 -2
  22. package/test/full-querystring-rewrite-option-function.js +2 -2
  23. package/test/full-querystring-rewrite-option.js +2 -2
  24. package/test/full-querystring-rewrite-string.js +2 -2
  25. package/test/full-querystring-rewrite.js +2 -2
  26. package/test/full-querystring.js +2 -2
  27. package/test/full-rewrite-body-content-type.js +2 -2
  28. package/test/full-rewrite-body-http.js +2 -2
  29. package/test/full-rewrite-body-to-empty-string.js +2 -2
  30. package/test/full-rewrite-body-to-null.js +2 -2
  31. package/test/full-rewrite-body.js +2 -2
  32. package/test/get-upstream-http.js +3 -3
  33. package/test/get-upstream-undici.js +2 -2
  34. package/test/get-with-body.js +2 -2
  35. package/test/head-with-body.js +2 -2
  36. package/test/host-header.js +2 -2
  37. package/test/http-agents.js +2 -2
  38. package/test/http-http2.js +2 -2
  39. package/test/http-invalid-target.js +1 -1
  40. package/test/http-retry.js +6 -6
  41. package/test/http-timeout.js +2 -2
  42. package/test/http2-http2.js +2 -2
  43. package/test/http2-https.js +2 -2
  44. package/test/http2-invalid-target.js +1 -1
  45. package/test/http2-target-crash.js +2 -2
  46. package/test/http2-target-multi-crash.js +3 -3
  47. package/test/http2-timeout.js +4 -4
  48. package/test/https-agents.js +2 -2
  49. package/test/index.test-d.ts +3 -2
  50. package/test/modifyCoreObjects-false.js +2 -2
  51. package/test/no-body-opts-with-get.js +2 -2
  52. package/test/no-body-opts-with-head.js +2 -2
  53. package/test/no-stream-body-option.js +2 -2
  54. package/test/on-error.js +2 -2
  55. package/test/onResponse.js +2 -2
  56. package/test/padded-body.js +2 -2
  57. package/test/post-formbody.js +3 -3
  58. package/test/post-plain-text.js +2 -2
  59. package/test/post-with-custom-encoded-contenttype.js +2 -2
  60. package/test/retry-on-503.js +6 -6
  61. package/test/rewrite-headers.js +2 -2
  62. package/test/rewrite-request-headers.js +2 -2
  63. package/test/transform-body.js +2 -2
  64. package/test/undici-agent.js +2 -2
  65. package/test/undici-body.js +2 -2
  66. package/test/undici-options.js +2 -2
  67. package/test/undici-retry.js +6 -6
  68. package/test/undici-timeout-body-partial.js +2 -2
  69. package/test/undici-timeout-body.js +2 -2
  70. package/test/undici-timeout.js +2 -2
  71. package/test/undici-with-path-in-base.js +2 -2
  72. package/test/undici.js +2 -2
  73. package/test/unexpected-error.js +1 -1
  74. package/test/unix-http-undici-from.js +1 -1
  75. package/test/unix-http-undici.js +1 -1
  76. package/test/unix-http.js +1 -1
  77. package/test/unix-https-undici.js +1 -1
  78. package/test/unix-https.js +1 -1
@@ -1,60 +1,15 @@
1
1
  name: CI
2
- 'on':
2
+
3
+ on:
3
4
  push:
4
5
  paths-ignore:
5
- - docs/**
6
+ - 'docs/**'
6
7
  - '*.md'
7
8
  pull_request:
8
9
  paths-ignore:
9
- - docs/**
10
+ - 'docs/**'
10
11
  - '*.md'
12
+
11
13
  jobs:
12
14
  test:
13
- runs-on: ${{ matrix.os }}
14
- strategy:
15
- matrix:
16
- node-version:
17
- - 12
18
- - 14
19
- - 16
20
- os:
21
- - macos-latest
22
- - ubuntu-latest
23
- - windows-latest
24
- steps:
25
- - uses: actions/checkout@v3
26
- - name: Use Node.js
27
- uses: actions/setup-node@v3
28
- with:
29
- node-version: ${{ matrix.node-version }}
30
- - name: Install Dependencies
31
- run: |
32
- npm install --ignore-scripts
33
- - name: Run Tests
34
- run: |
35
- npm run test:ci
36
- - name: Coveralls Parallel
37
- uses: coverallsapp/github-action@1.1.3
38
- with:
39
- github-token: ${{ secrets.GITHUB_TOKEN }}
40
- parallel: true
41
- flag-name: run-${{ matrix.node-version }}-${{ matrix.os }}
42
- coverage:
43
- needs: test
44
- runs-on: ubuntu-latest
45
- steps:
46
- - name: Coveralls Finished
47
- uses: coverallsapp/github-action@1.1.3
48
- with:
49
- github-token: ${{ secrets.GITHUB_TOKEN }}
50
- parallel-finished: true
51
- automerge:
52
- needs: test
53
- runs-on: ubuntu-latest
54
- permissions:
55
- pull-requests: write
56
- contents: write
57
- steps:
58
- - uses: fastify/github-action-merge-dependabot@v3.0.2
59
- with:
60
- github-token: ${{ secrets.GITHUB_TOKEN }}
15
+ uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
package/README.md CHANGED
@@ -1,9 +1,7 @@
1
- # fastify-reply-from
1
+ # @fastify/reply-from
2
2
 
3
3
  ![CI](https://github.com/fastify/fastify-reply-from/workflows/CI/badge.svg)
4
- [![NPM version](https://img.shields.io/npm/v/fastify-reply-from.svg?style=flat)](https://www.npmjs.com/package/fastify-reply-from)
5
- [![Known Vulnerabilities](https://snyk.io/test/github/fastify/fastify-reply-from/badge.svg)](https://snyk.io/test/github/fastify/fastify-reply-from)
6
- [![Coverage Status](https://coveralls.io/repos/github/fastify/fastify-reply-from/badge.svg?branch=master)](https://coveralls.io/github/fastify/fastify-reply-from?branch=master)
4
+ [![NPM version](https://img.shields.io/npm/v/@fastify/reply-from.svg?style=flat)](https://www.npmjs.com/package/@fastify/reply-from)
7
5
  [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://standardjs.com/)
8
6
 
9
7
  Fastify plugin to forward the current HTTP request to another server.
@@ -12,11 +10,11 @@ HTTP2 to HTTP is supported too.
12
10
  ## Install
13
11
 
14
12
  ```
15
- npm i fastify-reply-from
13
+ npm i @fastify/reply-from
16
14
  ```
17
15
 
18
- ## Compatibility with fastify-multipart
19
- `fastify-reply-from` and [`fastify-multipart`](https://github.com/fastify/fastify-multipart) should not be registered as sibling plugins nor should they be registered in plugins which have a parent-child relationship.<br> The two plugins are incompatible, in the sense that the behavior of `fastify-reply-from` might not be the expected one when the above-mentioned conditions are not respected.<br> This is due to the fact that `fastify-multipart` consumes the multipart content by parsing it, hence this content is not forwarded to the target service by `fastify-reply-from`.<br>
16
+ ## Compatibility with @fastify/multipart
17
+ `@fastify/reply-from` and [`@fastify/multipart`](https://github.com/fastify/fastify-multipart) should not be registered as sibling plugins nor should they be registered in plugins which have a parent-child relationship.<br> The two plugins are incompatible, in the sense that the behavior of `@fastify/reply-from` might not be the expected one when the above-mentioned conditions are not respected.<br> This is due to the fact that `@fastify/multipart` consumes the multipart content by parsing it, hence this content is not forwarded to the target service by `@fastify/reply-from`.<br>
20
18
  However, the two plugins may be used within the same fastify instance, at the condition that they belong to disjoint branches of the fastify plugins hierarchy tree.
21
19
 
22
20
  ## Usage
@@ -41,7 +39,7 @@ const proxy = Fastify({
41
39
  logger: true
42
40
  })
43
41
 
44
- proxy.register(require('fastify-reply-from'), {
42
+ proxy.register(require('@fastify/reply-from'), {
45
43
  base: 'http://localhost:3001/'
46
44
  })
47
45
 
@@ -77,7 +75,7 @@ for http2 nor undici. To illustrate:
77
75
 
78
76
  ```js
79
77
  const socketPath = require('querystring').escape('/run/http-daemon.socket')
80
- proxy.register(require('fastify-reply-from'), {
78
+ proxy.register(require('@fastify/reply-from'), {
81
79
  base: 'unix+http://${socketPath}/'
82
80
  });
83
81
  ```
@@ -91,7 +89,7 @@ requests. Enabling this flag should guarantee
91
89
  This flag could controls the settings of the undici client, like so:
92
90
 
93
91
  ```js
94
- proxy.register(require('fastify-reply-from'), {
92
+ proxy.register(require('@fastify/reply-from'), {
95
93
  base: 'http://localhost:3001/',
96
94
  // default settings
97
95
  undici: {
@@ -109,7 +107,7 @@ See undici own options for more configurations.
109
107
  You can also pass the plugin a custom instance:
110
108
 
111
109
  ```js
112
- proxy.register(require('fastify-reply-from'), {
110
+ proxy.register(require('@fastify/reply-from'), {
113
111
  base: 'http://localhost:3001/',
114
112
  undici: new undici.Pool('http://localhost:3001')
115
113
  })
@@ -124,7 +122,7 @@ you can pass in [`agentOptions`](https://nodejs.org/api/http.html#http_new_agent
124
122
  [`requestOptions`](https://nodejs.org/api/http.html#http_http_request_options_callback). To illustrate:
125
123
 
126
124
  ```js
127
- proxy.register(require('fastify-reply-from'), {
125
+ proxy.register(require('@fastify/reply-from'), {
128
126
  base: 'http://localhost:3001/',
129
127
  http: {
130
128
  agentOptions: { // pass in any options from https://nodejs.org/api/http.html#http_new_agent_options
@@ -139,7 +137,7 @@ proxy.register(require('fastify-reply-from'), {
139
137
 
140
138
  You can also pass custom HTTP agents. If you pass the agents, then the http.agentOptions will be ignored. To illustrate:
141
139
  ```js
142
- proxy.register(require('fastify-reply-from'), {
140
+ proxy.register(require('@fastify/reply-from'), {
143
141
  base: 'http://localhost:3001/',
144
142
  http: {
145
143
  agents: {
@@ -160,7 +158,7 @@ You can either set `http2` to `true` or set the settings object to connect to a
160
158
  The `http2` settings object has the shape of:
161
159
 
162
160
  ```js
163
- proxy.register(require('fastify-reply-from'), {
161
+ proxy.register(require('@fastify/reply-from'), {
164
162
  base: 'http://localhost:3001/',
165
163
  http2: {
166
164
  sessionTimeout: 10000, // HTTP/2 session timeout in msecs, defaults to 60000 (1 minute)
@@ -175,6 +173,19 @@ proxy.register(require('fastify-reply-from'), {
175
173
  })
176
174
  ```
177
175
 
176
+ #### `disableRequestLogging`
177
+
178
+ By default package will issue log messages when a request is received. By setting this option to true, these log messages will be disabled.
179
+
180
+ Default for `disableRequestLogging` will be `false`. To disable the log messages set `disableRequestLogging` to `true`.
181
+
182
+ ```js
183
+ proxy.register(require('@fastify/reply-from'), {
184
+ base: 'http://localhost:3001/',
185
+ disableRequestLogging: true // request log messages will be disabled
186
+ })
187
+ ```
188
+
178
189
  #### `cacheURLs`
179
190
 
180
191
  The number of parsed URLs that will be cached. Default: `100`.
@@ -301,7 +312,7 @@ By default: 0 (disabled)
301
312
  Override the `'Content-Type'` header of the forwarded request, if we are
302
313
  already overriding the [`body`](#body).
303
314
 
304
- ### Combining with [fastify-formbody](https://github.com/fastify/fastify-formbody)
315
+ ### Combining with [@fastify/formbody](https://github.com/fastify/fastify-formbody)
305
316
 
306
317
  `formbody` expects the body to be returned as a string and not an object.
307
318
  Use the [`contentTypesToEncode`](#contentTypesToEncode) option to pass in `['application/x-www-form-urlencoded']`
package/index.d.ts CHANGED
@@ -91,6 +91,7 @@ export interface FastifyReplyFromOptions {
91
91
  contentTypesToEncode?: string[];
92
92
  retryMethods?: (HTTPMethods | 'TRACE')[];
93
93
  maxRetriesOn503?: number;
94
+ disableRequestLogging?: boolean;
94
95
  }
95
96
 
96
97
  declare const fastifyReplyFrom:
package/index.js CHANGED
@@ -33,6 +33,7 @@ module.exports = fp(function from (fastify, opts, next) {
33
33
  base,
34
34
  undici: opts.undici
35
35
  })
36
+ const disableRequestLogging = opts.disableRequestLogging || false
36
37
 
37
38
  fastify.decorateReply('from', function (source, opts) {
38
39
  opts = opts || {}
@@ -120,7 +121,7 @@ module.exports = fp(function from (fastify, opts, next) {
120
121
  }
121
122
  }
122
123
 
123
- this.request.log.info({ source }, 'fetching from remote server')
124
+ !disableRequestLogging && this.request.log.info({ source }, 'fetching from remote server')
124
125
 
125
126
  const requestHeaders = rewriteRequestHeaders(req, headers)
126
127
  const contentLength = requestHeaders['content-length']
@@ -145,7 +146,7 @@ module.exports = fp(function from (fastify, opts, next) {
145
146
  }
146
147
  return
147
148
  }
148
- this.request.log.info('response received')
149
+ !disableRequestLogging && this.request.log.info('response received')
149
150
  if (sourceHttp2) {
150
151
  copyHeaders(
151
152
  rewriteHeaders(stripHttp1ConnectionHeaders(res.headers), req),
@@ -166,7 +167,7 @@ module.exports = fp(function from (fastify, opts, next) {
166
167
 
167
168
  fastify.addHook('onReady', (done) => {
168
169
  if (isFastifyMultipartRegistered(fastify)) {
169
- fastify.log.warn('fastify-reply-from might not behave as expected when used with fastify-multipart')
170
+ fastify.log.warn('@fastify/reply-from might not behave as expected when used with @fastify/multipart')
170
171
  }
171
172
  done()
172
173
  })
@@ -179,7 +180,10 @@ module.exports = fp(function from (fastify, opts, next) {
179
180
  })
180
181
 
181
182
  next()
182
- }, '>=3')
183
+ }, {
184
+ fastify: '4.x',
185
+ name: '@fastify/reply-from'
186
+ })
183
187
 
184
188
  function getQueryString (search, reqUrl, opts) {
185
189
  if (typeof opts.queryString === 'function') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fastify/reply-from",
3
- "version": "7.0.0",
3
+ "version": "8.1.0",
4
4
  "description": "forward your HTTP request to another server, for fastify",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -26,40 +26,37 @@
26
26
  "bugs": {
27
27
  "url": "https://github.com/fastify/fastify-reply-from/issues"
28
28
  },
29
- "engines": {
30
- "node": ">=12.18"
31
- },
32
29
  "homepage": "https://github.com/fastify/fastify-reply-from#readme",
33
30
  "devDependencies": {
34
- "@sinonjs/fake-timers": "^9.0.0",
35
- "@types/node": "^17.0.0",
36
- "@types/tap": "^15.0.3",
37
- "fastify": "^3.17.0",
38
- "fastify-formbody": "^5.0.0",
39
- "fastify-multipart": "^5.0.0",
31
+ "@fastify/formbody": "^7.0.1",
32
+ "@fastify/multipart": "^7.1.0",
33
+ "@sinonjs/fake-timers": "^9.1.2",
34
+ "@types/node": "^18.0.0",
35
+ "@types/tap": "^15.0.7",
36
+ "fastify": "^4.0.2",
40
37
  "form-data": "^4.0.0",
41
38
  "got": "^11.8.2",
42
39
  "h2url": "^0.2.0",
43
- "msgpack5": "^6.0.0",
44
- "nock": "^13.1.0",
40
+ "msgpack5": "^6.0.1",
41
+ "nock": "^13.2.6",
45
42
  "pre-commit": "^1.2.2",
46
43
  "proxyquire": "^2.1.3",
47
- "simple-get": "^4.0.0",
44
+ "simple-get": "^4.0.1",
48
45
  "snazzy": "^9.0.0",
49
- "split2": "^4.0.0",
46
+ "split2": "^4.1.0",
50
47
  "standard": "^17.0.0",
51
- "tap": "^16.0.0",
52
- "tsd": "^0.20.0",
53
- "typescript": "^4.3.2"
48
+ "tap": "^16.2.0",
49
+ "tsd": "^0.21.0",
50
+ "typescript": "^4.7.3"
54
51
  },
55
52
  "dependencies": {
56
53
  "end-of-stream": "^1.4.4",
57
- "fastify-plugin": "^3.0.0",
54
+ "fastify-plugin": "^3.0.1",
58
55
  "http-errors": "^2.0.0",
59
56
  "pump": "^3.0.0",
60
- "semver": "^7.3.5",
61
- "tiny-lru": "^8.0.1",
62
- "undici": "^5.0.0"
57
+ "semver": "^7.3.7",
58
+ "tiny-lru": "^8.0.2",
59
+ "undici": "^5.5.1"
63
60
  },
64
61
  "tsd": {
65
62
  "directory": "test"
@@ -29,14 +29,14 @@ instance.get('/', async (request, reply) => {
29
29
 
30
30
  t.teardown(target.close.bind(target))
31
31
 
32
- target.listen(0, (err) => {
32
+ target.listen({ port: 0 }, (err) => {
33
33
  t.error(err)
34
34
 
35
35
  instance.register(From, {
36
36
  base: `http://localhost:${target.address().port}`
37
37
  })
38
38
 
39
- instance.listen(0, (err) => {
39
+ instance.listen({ port: 0 }, (err) => {
40
40
  t.error(err)
41
41
 
42
42
  get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
package/test/base-get.js CHANGED
@@ -27,14 +27,14 @@ instance.get('/', (request, reply) => {
27
27
 
28
28
  t.teardown(target.close.bind(target))
29
29
 
30
- target.listen(0, (err) => {
30
+ target.listen({ port: 0 }, (err) => {
31
31
  t.error(err)
32
32
 
33
33
  instance.register(From, {
34
34
  base: `http://localhost:${target.address().port}`
35
35
  })
36
36
 
37
- instance.listen(0, (err) => {
37
+ instance.listen({ port: 0 }, (err) => {
38
38
  t.error(err)
39
39
 
40
40
  get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
package/test/base-path.js CHANGED
@@ -26,7 +26,7 @@ instance.register(From, {
26
26
  undici: false
27
27
  })
28
28
 
29
- instance.listen(0, (err) => {
29
+ instance.listen({ port: 0 }, (err) => {
30
30
  t.error(err)
31
31
 
32
32
  get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
@@ -27,14 +27,14 @@ instance.get('/hello', (request, reply) => {
27
27
 
28
28
  t.teardown(target.close.bind(target))
29
29
 
30
- target.listen(0, (err) => {
30
+ target.listen({ port: 0 }, (err) => {
31
31
  t.error(err)
32
32
 
33
33
  instance.register(From, {
34
34
  base: `http://localhost:${target.address().port}`
35
35
  })
36
36
 
37
- instance.listen(0, (err) => {
37
+ instance.listen({ port: 0 }, (err) => {
38
38
  t.error(err)
39
39
 
40
40
  get(`http://localhost:${instance.server.address().port}/hello?a=b`, (err, res, data) => {
@@ -28,7 +28,7 @@ instance.get('/', (request, reply) => {
28
28
 
29
29
  t.teardown(target.close.bind(target))
30
30
 
31
- target.listen(0, (err) => {
31
+ target.listen({ port: 0 }, (err) => {
32
32
  t.error(err)
33
33
 
34
34
  instance.register(From, {
@@ -36,7 +36,7 @@ target.listen(0, (err) => {
36
36
  http: true
37
37
  })
38
38
 
39
- instance.listen(0, (err) => {
39
+ instance.listen({ port: 0 }, (err) => {
40
40
  t.error(err)
41
41
 
42
42
  get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
@@ -21,7 +21,7 @@ const target = http.createServer((req, res) => {
21
21
  t.test('use a custom instance of \'undici\'', async t => {
22
22
  t.teardown(target.close.bind(target))
23
23
 
24
- await new Promise((resolve, reject) => target.listen(0, err => err ? reject(err) : resolve()))
24
+ await new Promise((resolve, reject) => target.listen({ port: 0 }, err => err ? reject(err) : resolve()))
25
25
 
26
26
  t.test('custom Pool', t => {
27
27
  const instance = Fastify()
@@ -35,7 +35,7 @@ t.test('use a custom instance of \'undici\'', async t => {
35
35
  reply.from()
36
36
  })
37
37
 
38
- instance.listen(0, (err) => {
38
+ instance.listen({ port: 0 }, (err) => {
39
39
  t.error(err)
40
40
 
41
41
  get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
@@ -61,7 +61,7 @@ t.test('use a custom instance of \'undici\'', async t => {
61
61
  reply.from()
62
62
  })
63
63
 
64
- instance.listen(0, (err) => {
64
+ instance.listen({ port: 0 }, (err) => {
65
65
  t.error(err)
66
66
 
67
67
  get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
@@ -0,0 +1,159 @@
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 split = require('split2')
9
+
10
+ const target = http.createServer((req, res) => {
11
+ t.pass('request proxied')
12
+ t.equal(req.method, 'GET')
13
+ t.equal(req.url, '/')
14
+ t.equal(req.headers.connection, 'keep-alive')
15
+ res.statusCode = 205
16
+ res.setHeader('Content-Type', 'text/plain')
17
+ res.setHeader('x-my-header', 'hello!')
18
+ res.end('hello world')
19
+ })
20
+
21
+ t.test('use a custom instance of \'undici\'', async t => {
22
+ t.teardown(target.close.bind(target))
23
+
24
+ await new Promise((resolve, reject) => target.listen({ port: 0 }, err => err ? reject(err) : resolve()))
25
+
26
+ t.test('disableRequestLogging is set to true', t => {
27
+ t.plan(10)
28
+ const logStream = split(JSON.parse)
29
+ const instance = Fastify({
30
+ logger: {
31
+ level: 'info',
32
+ stream: logStream
33
+ }
34
+ })
35
+ t.teardown(instance.close.bind(instance))
36
+ instance.register(From, {
37
+ base: `http://localhost:${target.address().port}`,
38
+ disableRequestLogging: true
39
+ })
40
+
41
+ instance.get('/', (request, reply) => {
42
+ reply.from()
43
+ })
44
+
45
+ logStream.on('data', (log) => {
46
+ if (
47
+ log.level === 30 &&
48
+ (
49
+ !log.msg.match('response received') ||
50
+ !log.msg.match('fetching from remote server')
51
+ )
52
+ ) {
53
+ t.pass('request log message does not logged')
54
+ }
55
+ })
56
+
57
+ instance.listen({ port: 0 }, (err) => {
58
+ t.error(err)
59
+
60
+ get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
61
+ t.error(err)
62
+ t.equal(res.headers['content-type'], 'text/plain')
63
+ t.equal(res.headers['x-my-header'], 'hello!')
64
+ t.equal(res.statusCode, 205)
65
+ t.equal(data.toString(), 'hello world')
66
+ t.end()
67
+ })
68
+ })
69
+ })
70
+
71
+ t.test('disableRequestLogging is set to false', t => {
72
+ t.plan(8)
73
+ const logStream = split(JSON.parse)
74
+ const instance = Fastify({
75
+ logger: {
76
+ level: 'info',
77
+ stream: logStream
78
+ }
79
+ })
80
+ t.teardown(instance.close.bind(instance))
81
+ instance.register(From, {
82
+ base: `http://localhost:${target.address().port}`,
83
+ disableRequestLogging: false
84
+ })
85
+
86
+ instance.get('/', (request, reply) => {
87
+ reply.from()
88
+ })
89
+
90
+ logStream.on('data', (log) => {
91
+ if (
92
+ log.level === 30 &&
93
+ (
94
+ log.msg.match('response received') ||
95
+ log.msg.match('fetching from remote server')
96
+ )
97
+ ) {
98
+ t.pass('request log message does not logged')
99
+ }
100
+ })
101
+
102
+ instance.listen({ port: 0 }, (err) => {
103
+ t.error(err)
104
+
105
+ get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
106
+ t.error(err)
107
+ t.equal(res.headers['content-type'], 'text/plain')
108
+ t.equal(res.headers['x-my-header'], 'hello!')
109
+ t.equal(res.statusCode, 205)
110
+ t.equal(data.toString(), 'hello world')
111
+ t.end()
112
+ })
113
+ })
114
+ })
115
+
116
+ t.test('disableRequestLogging is not defined', t => {
117
+ t.plan(8)
118
+ const logStream = split(JSON.parse)
119
+ const instance = Fastify({
120
+ logger: {
121
+ level: 'info',
122
+ stream: logStream
123
+ }
124
+ })
125
+ t.teardown(instance.close.bind(instance))
126
+ instance.register(From, {
127
+ base: `http://localhost:${target.address().port}`
128
+ })
129
+
130
+ instance.get('/', (request, reply) => {
131
+ reply.from()
132
+ })
133
+
134
+ logStream.on('data', (log) => {
135
+ if (
136
+ log.level === 30 &&
137
+ (
138
+ log.msg.match('response received') ||
139
+ log.msg.match('fetching from remote server')
140
+ )
141
+ ) {
142
+ t.pass('request log message does not logged')
143
+ }
144
+ })
145
+
146
+ instance.listen({ port: 0 }, (err) => {
147
+ t.error(err)
148
+
149
+ get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
150
+ t.error(err)
151
+ t.equal(res.headers['content-type'], 'text/plain')
152
+ t.equal(res.headers['x-my-header'], 'hello!')
153
+ t.equal(res.statusCode, 205)
154
+ t.equal(data.toString(), 'hello world')
155
+ t.end()
156
+ })
157
+ })
158
+ })
159
+ })
@@ -5,7 +5,7 @@ const path = require('path')
5
5
  const t = require('tap')
6
6
  const Fastify = require('fastify')
7
7
  const From = require('..')
8
- const Multipart = require('fastify-multipart')
8
+ const Multipart = require('@fastify/multipart')
9
9
  const http = require('http')
10
10
  const get = require('simple-get').concat
11
11
  const FormData = require('form-data')
@@ -56,19 +56,19 @@ instance.post('/', (request, reply) => {
56
56
 
57
57
  t.teardown(target.close.bind(target))
58
58
 
59
- instance.listen(0, (err) => {
59
+ instance.listen({ port: 0 }, (err) => {
60
60
  t.error(err)
61
61
 
62
62
  logStream.on('data', (log) => {
63
63
  if (
64
64
  log.level === 40 &&
65
- log.msg.match(/fastify-reply-from might not behave as expected when used with fastify-multipart/)
65
+ log.msg.match(/@fastify\/reply-from might not behave as expected when used with @fastify\/multipart/)
66
66
  ) {
67
67
  t.pass('incompatibility warn message logged')
68
68
  }
69
69
  })
70
70
 
71
- target.listen(0, (err) => {
71
+ target.listen({ port: 0 }, (err) => {
72
72
  t.error(err)
73
73
 
74
74
  const form = new FormData()
package/test/full-get.js CHANGED
@@ -28,10 +28,10 @@ instance.get('/', (request, reply) => {
28
28
 
29
29
  t.teardown(target.close.bind(target))
30
30
 
31
- instance.listen(0, (err) => {
31
+ instance.listen({ port: 0 }, (err) => {
32
32
  t.error(err)
33
33
 
34
- target.listen(0, (err) => {
34
+ target.listen({ port: 0 }, (err) => {
35
35
  t.error(err)
36
36
 
37
37
  get(`http://localhost:${instance.server.address().port}`, (err, res, data) => {
@@ -35,10 +35,10 @@ instance.get('/', (request, reply) => {
35
35
 
36
36
  t.teardown(target.close.bind(target))
37
37
 
38
- instance.listen(0, (err) => {
38
+ instance.listen({ port: 0 }, (err) => {
39
39
  t.error(err)
40
40
 
41
- target.listen(0, (err) => {
41
+ target.listen({ port: 0 }, (err) => {
42
42
  t.error(err)
43
43
 
44
44
  get({
@@ -35,10 +35,10 @@ instance.post('/', (request, reply) => {
35
35
 
36
36
  t.teardown(target.close.bind(target))
37
37
 
38
- instance.listen(0, (err) => {
38
+ instance.listen({ port: 0 }, (err) => {
39
39
  t.error(err)
40
40
 
41
- target.listen(0, (err) => {
41
+ target.listen({ port: 0 }, (err) => {
42
42
  t.error(err)
43
43
 
44
44
  get.concat({
@@ -28,14 +28,14 @@ test('http -> http2', async function (t) {
28
28
 
29
29
  t.teardown(target.close.bind(target))
30
30
 
31
- await target.listen(0)
31
+ await target.listen({ port: 0 })
32
32
 
33
33
  instance.register(From, {
34
34
  base: `http://localhost:${target.server.address().port}`,
35
35
  http2: true
36
36
  })
37
37
 
38
- await instance.listen(0)
38
+ await instance.listen({ port: 0 })
39
39
 
40
40
  const { headers, body, statusCode } = await got(`http://localhost:${instance.server.address().port}`, {
41
41
  method: 'POST',