fastify 5.8.2 → 5.8.3

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 (42) hide show
  1. package/AGENTS.md +290 -0
  2. package/README.md +1 -0
  3. package/SECURITY.md +10 -1
  4. package/docs/Guides/Migration-Guide-V5.md +1 -1
  5. package/docs/Guides/Plugins-Guide.md +2 -2
  6. package/docs/Guides/Recommendations.md +30 -5
  7. package/docs/Reference/ContentTypeParser.md +8 -0
  8. package/docs/Reference/Decorators.md +2 -2
  9. package/docs/Reference/Errors.md +3 -3
  10. package/docs/Reference/Reply.md +3 -3
  11. package/docs/Reference/Request.md +1 -1
  12. package/docs/Reference/Routes.md +4 -4
  13. package/docs/Reference/Server.md +13 -13
  14. package/docs/Reference/Validation-and-Serialization.md +28 -19
  15. package/docs/Reference/Warnings.md +5 -5
  16. package/fastify.js +1 -1
  17. package/lib/request.js +8 -6
  18. package/package.json +1 -1
  19. package/test/client-timeout.test.js +1 -1
  20. package/test/close.test.js +2 -2
  21. package/test/constrained-routes.test.js +6 -6
  22. package/test/hooks.test.js +18 -18
  23. package/test/http-methods/get.test.js +1 -1
  24. package/test/http-methods/lock.test.js +3 -3
  25. package/test/http-methods/propfind.test.js +1 -1
  26. package/test/http-methods/proppatch.test.js +3 -3
  27. package/test/https/https.test.js +2 -2
  28. package/test/internals/reply.test.js +4 -4
  29. package/test/internals/request.test.js +9 -9
  30. package/test/max-requests-per-socket.test.js +6 -6
  31. package/test/request-error.test.js +3 -3
  32. package/test/schema-examples.test.js +2 -2
  33. package/test/schema-feature.test.js +15 -15
  34. package/test/schema-serialization.test.js +6 -6
  35. package/test/schema-special-usage.test.js +5 -5
  36. package/test/schema-validation.test.js +2 -2
  37. package/test/skip-reply-send.test.js +1 -1
  38. package/test/trust-proxy.test.js +68 -9
  39. package/test/types/logger.test-d.ts +25 -25
  40. package/test/types/request.test-d.ts +1 -1
  41. package/test/types/route.test-d.ts +3 -3
  42. package/types/request.d.ts +1 -1
@@ -12,14 +12,14 @@ a `content` field, it must enumerate all possible content types the
12
12
  application expects to handle with the associated handler.
13
13
 
14
14
  All examples use the
15
- [JSON Schema Draft 7](https://json-schema.org/specification-links.html#draft-7)
15
+ [JSON Schema Draft 7](https://json-schema.org/draft-07)
16
16
  specification.
17
17
 
18
18
  > ⚠ Warning:
19
19
  > Treat schema definitions as application code. Validation and serialization
20
20
  > features use `new Function()`, which is unsafe with user-provided schemas. See
21
- > [Ajv](https://npm.im/ajv) and
22
- > [fast-json-stringify](https://npm.im/fast-json-stringify) for details.
21
+ > [Ajv](https://www.npmjs.com/package/ajv) and
22
+ > [fast-json-stringify](https://www.npmjs.com/package/fast-json-stringify) for details.
23
23
  >
24
24
  > Whilst Fastify supports the
25
25
  > [`$async` Ajv feature](https://ajv.js.org/guide/async-validation.html),
@@ -50,7 +50,7 @@ The `addSchema` API allows adding multiple schemas to the Fastify instance for
50
50
  reuse throughout the application. This API is encapsulated.
51
51
 
52
52
  Shared schemas can be reused with the JSON Schema
53
- [**`$ref`**](https://tools.ietf.org/html/draft-handrews-json-schema-01#section-8)
53
+ [**`$ref`**](https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-01#section-8)
54
54
  keyword. Here is an overview of how references work:
55
55
 
56
56
  + `myField: { $ref: '#foo' }` searches for `$id: '#foo'` in the current schema
@@ -67,7 +67,7 @@ keyword. Here is an overview of how references work:
67
67
 
68
68
  ```js
69
69
  fastify.addSchema({
70
- $id: 'http://example.com/',
70
+ $id: 'http://fastify.example/',
71
71
  type: 'object',
72
72
  properties: {
73
73
  hello: { type: 'string' }
@@ -79,7 +79,7 @@ fastify.post('/', {
79
79
  schema: {
80
80
  body: {
81
81
  type: 'array',
82
- items: { $ref: 'http://example.com#/properties/hello' }
82
+ items: { $ref: 'http://fastify.example#/properties/hello' }
83
83
  }
84
84
  }
85
85
  })
@@ -257,12 +257,21 @@ fastify.post('/the/url', {
257
257
  }, handler)
258
258
  ```
259
259
 
260
- > **Important:** When using [custom content type
261
- > parsers](./ContentTypeParser.md), the parsed body will **only** be validated
262
- > if the request's content type is listed in the `content` object above. If
263
- > a parser for a content type (e.g., `application/yaml`) is defined,
264
- > but it is not not included in the body schema's `content` property,
265
- > the incoming data will be parsed but **not validated**.
260
+ > Warning:
261
+ > When using [custom content type parsers](./ContentTypeParser.md), the parsed
262
+ > body is validated **only** when the request content type matches a key in the
263
+ > schema `content` map.
264
+ >
265
+ > Schema selection uses an exact match on the request's
266
+ > [essence MIME type](https://mimesniff.spec.whatwg.org/#mime-type-miscellaneous)
267
+ > (for example, `application/json`). If a parser is registered with a regular
268
+ > expression (for example, `/^application\/.*json$/`), the parser can accept
269
+ > more content types than the `content` map covers. Requests in that gap are
270
+ > parsed but **not validated**.
271
+ >
272
+ > Ensure every content type accepted by the parser has a corresponding key in
273
+ > the `content` map, or use a catch-all body schema without `content` when
274
+ > strict per-content-type discrimination is not required.
266
275
  >
267
276
  > ```js
268
277
  > // Add a custom parser for YAML
@@ -579,13 +588,13 @@ fastify.post('/the/url', {
579
588
  When implementing custom validators, follow these patterns to ensure compatibility
580
589
  with all Fastify features:
581
590
 
582
- ** Always return objects, never throw:**
591
+ **Always return objects, never throw:**
583
592
  ```js
584
593
  return { value: validatedData } // On success
585
594
  return { error: validationError } // On failure
586
595
  ```
587
596
 
588
- ** Use try-catch for safety:**
597
+ **Use try-catch for safety:**
589
598
  ```js
590
599
  fastify.setValidatorCompiler(({ schema }) => {
591
600
  return (data) => {
@@ -907,7 +916,7 @@ fastify.setErrorHandler(function (error, request, reply) {
907
916
  ```
908
917
 
909
918
  For custom error responses in the schema, see
910
- [`ajv-errors`](https://github.com/epoberezkin/ajv-errors). Check out the
919
+ [`ajv-errors`](https://github.com/ajv-validator/ajv-errors). Check out the
911
920
  [example](https://github.com/fastify/example/blob/HEAD/validation-messages/custom-errors-messages.js)
912
921
  usage.
913
922
 
@@ -969,7 +978,7 @@ fastify.post('/', { schema, }, (request, reply) => {
969
978
  ```
970
979
 
971
980
  To return localized error messages, see
972
- [ajv-i18n](https://github.com/epoberezkin/ajv-i18n).
981
+ [ajv-i18n](https://github.com/ajv-validator/ajv-i18n).
973
982
 
974
983
  ```js
975
984
  const localize = require('ajv-i18n')
@@ -1114,8 +1123,8 @@ const refToSharedSchemaDefinitions = {
1114
1123
  Schema](https://json-schema.org/understanding-json-schema/about)
1115
1124
  - [fast-json-stringify
1116
1125
  documentation](https://github.com/fastify/fast-json-stringify)
1117
- - [Ajv documentation](https://github.com/epoberezkin/ajv/blob/master/README.md)
1118
- - [Ajv i18n](https://github.com/epoberezkin/ajv-i18n)
1119
- - [Ajv custom errors](https://github.com/epoberezkin/ajv-errors)
1126
+ - [Ajv documentation](https://github.com/ajv-validator/ajv/blob/master/README.md)
1127
+ - [Ajv i18n](https://github.com/ajv-validator/ajv-i18n)
1128
+ - [Ajv custom errors](https://github.com/ajv-validator/ajv-errors)
1120
1129
  - Custom error handling with core methods with error file dumping
1121
1130
  [example](https://github.com/fastify/example/tree/main/validation-messages)
@@ -18,8 +18,8 @@ Fastify uses Node.js's [warning event](https://nodejs.org/api/process.html#event
18
18
  API to notify users of deprecated features and coding mistakes. Fastify's
19
19
  warnings are recognizable by the `FSTWRN` and `FSTDEP` prefixes. When
20
20
  encountering such a warning, it is highly recommended to determine the cause
21
- using the [`--trace-warnings`](https://nodejs.org/api/cli.html#--trace-warnings)
22
- and [`--trace-deprecation`](https://nodejs.org/api/cli.html#--trace-deprecation)
21
+ using the [`--trace-warnings`](https://nodejs.org/api/cli.html#trace-warnings)
22
+ and [`--trace-deprecation`](https://nodejs.org/api/cli.html#trace-deprecation)
23
23
  flags. These produce stack traces pointing to where the issue occurs in the
24
24
  application's code. Issues opened about warnings without this information will
25
25
  be closed due to lack of details.
@@ -48,9 +48,9 @@ experienced users should consider disabling warnings.
48
48
 
49
49
  Deprecation codes are supported by the Node.js CLI options:
50
50
 
51
- - [--no-deprecation](https://nodejs.org/api/cli.html#--no-deprecation)
52
- - [--throw-deprecation](https://nodejs.org/api/cli.html#--throw-deprecation)
53
- - [--trace-deprecation](https://nodejs.org/api/cli.html#--trace-deprecation)
51
+ - [--no-deprecation](https://nodejs.org/api/cli.html#no-deprecation)
52
+ - [--throw-deprecation](https://nodejs.org/api/cli.html#throw-deprecation)
53
+ - [--trace-deprecation](https://nodejs.org/api/cli.html#trace-deprecation)
54
54
 
55
55
 
56
56
  | Code | Description | How to solve | Discussion |
package/fastify.js CHANGED
@@ -922,7 +922,7 @@ function defaultBuildPrettyMeta (route) {
922
922
 
923
923
  function defaultClientErrorHandler (err, socket) {
924
924
  // In case of a connection reset, the socket has been destroyed and there is nothing that needs to be done.
925
- // https://nodejs.org/api/http.html#http_event_clienterror
925
+ // https://nodejs.org/api/http.html#event-clienterror
926
926
  if (err.code === 'ECONNRESET' || socket.destroyed) {
927
927
  return
928
928
  }
package/lib/request.js CHANGED
@@ -43,18 +43,20 @@ function getTrustProxyFn (tp) {
43
43
  }
44
44
  if (tp === true) {
45
45
  // Support trusting everything
46
- return null
46
+ return function () { return true }
47
47
  }
48
48
  if (typeof tp === 'number') {
49
49
  // Support trusting hop count
50
- return function (a, i) { return i < tp }
50
+ return function (a, i) { return a != null && i < tp }
51
51
  }
52
52
  if (typeof tp === 'string') {
53
53
  // Support comma-separated tps
54
54
  const values = tp.split(',').map(it => it.trim())
55
- return proxyAddr.compile(values)
55
+ const trust = proxyAddr.compile(values)
56
+ return function (a, i) { return a != null && trust(a, i) }
56
57
  }
57
- return proxyAddr.compile(tp)
58
+ const trust = proxyAddr.compile(tp)
59
+ return function (a, i) { return a != null && trust(a, i) }
58
60
  }
59
61
 
60
62
  function buildRequest (R, trustProxy) {
@@ -117,7 +119,7 @@ function buildRequestWithTrustProxy (R, trustProxy) {
117
119
  },
118
120
  host: {
119
121
  get () {
120
- if (this.ip !== undefined && this.headers['x-forwarded-host']) {
122
+ if (this.headers['x-forwarded-host'] && proxyFn(this.raw.socket?.remoteAddress, 0)) {
121
123
  return getLastEntryInMultiHeaderValue(this.headers['x-forwarded-host'])
122
124
  }
123
125
  /**
@@ -131,7 +133,7 @@ function buildRequestWithTrustProxy (R, trustProxy) {
131
133
  },
132
134
  protocol: {
133
135
  get () {
134
- if (this.headers['x-forwarded-proto']) {
136
+ if (this.headers['x-forwarded-proto'] && proxyFn(this.raw.socket?.remoteAddress, 0)) {
135
137
  return getLastEntryInMultiHeaderValue(this.headers['x-forwarded-proto'])
136
138
  }
137
139
  if (this.socket) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify",
3
- "version": "5.8.2",
3
+ "version": "5.8.3",
4
4
  "description": "Fast and low overhead web framework, for Node.js",
5
5
  "main": "fastify.js",
6
6
  "type": "commonjs",
@@ -24,7 +24,7 @@ test('requestTimeout should return 408', (t, done) => {
24
24
  let data = Buffer.alloc(0)
25
25
  const socket = connect(fastify.server.address().port)
26
26
 
27
- socket.write('POST / HTTP/1.1\r\nHost: example.com\r\nConnection-Length: 1\r\n')
27
+ socket.write('POST / HTTP/1.1\r\nHost: fastify.test\r\nConnection-Length: 1\r\n')
28
28
 
29
29
  socket.on('data', c => (data = Buffer.concat([data, c])))
30
30
  socket.on('end', () => {
@@ -230,7 +230,7 @@ test('Current opened connection should NOT continue to work after closing and re
230
230
 
231
231
  const port = fastify.server.address().port
232
232
  const client = net.createConnection({ port }, () => {
233
- client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
233
+ client.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
234
234
 
235
235
  client.on('error', function () {
236
236
  // Depending on the Operating System
@@ -247,7 +247,7 @@ test('Current opened connection should NOT continue to work after closing and re
247
247
  t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
248
248
  t.assert.match(data.toString(), /200 OK/i)
249
249
 
250
- client.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
250
+ client.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
251
251
  })
252
252
  })
253
253
  })
@@ -33,7 +33,7 @@ test('Should register a host constrained route', async t => {
33
33
  method: 'GET',
34
34
  url: '/',
35
35
  headers: {
36
- host: 'example.com'
36
+ host: 'fastify.test'
37
37
  }
38
38
  })
39
39
 
@@ -65,9 +65,9 @@ test('Should register the same route with host constraints', async t => {
65
65
  fastify.route({
66
66
  method: 'GET',
67
67
  url: '/',
68
- constraints: { host: 'example.com' },
68
+ constraints: { host: 'fastify.test' },
69
69
  handler: (req, reply) => {
70
- reply.send('example.com')
70
+ reply.send('fastify.test')
71
71
  }
72
72
  })
73
73
 
@@ -88,12 +88,12 @@ test('Should register the same route with host constraints', async t => {
88
88
  method: 'GET',
89
89
  url: '/',
90
90
  headers: {
91
- host: 'example.com'
91
+ host: 'fastify.test'
92
92
  }
93
93
  })
94
94
 
95
95
  t.assert.strictEqual(res.statusCode, 200)
96
- t.assert.strictEqual(res.payload, 'example.com')
96
+ t.assert.strictEqual(res.payload, 'fastify.test')
97
97
  }
98
98
 
99
99
  {
@@ -568,7 +568,7 @@ test('Should allow registering an unconstrained route after a constrained route'
568
568
  method: 'GET',
569
569
  url: '/',
570
570
  headers: {
571
- host: 'example.com'
571
+ host: 'fastify.test'
572
572
  }
573
573
  })
574
574
  t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'from any other domain' })
@@ -204,10 +204,10 @@ test('onRequest hook should support encapsulation / 2', (t, testDone) => {
204
204
  const fastify = Fastify()
205
205
  let pluginInstance
206
206
 
207
- fastify.addHook('onRequest', () => {})
207
+ fastify.addHook('onRequest', () => { })
208
208
 
209
209
  fastify.register((instance, opts, done) => {
210
- instance.addHook('onRequest', () => {})
210
+ instance.addHook('onRequest', () => { })
211
211
  pluginInstance = instance
212
212
  done()
213
213
  })
@@ -650,7 +650,7 @@ test('onRoute hook should preserve system route configuration', (t, testDone) =>
650
650
  test('onRoute hook should preserve handler function in options of shorthand route system configuration', (t, testDone) => {
651
651
  t.plan(2)
652
652
 
653
- const handler = (req, reply) => {}
653
+ const handler = (req, reply) => { }
654
654
 
655
655
  const fastify = Fastify({ exposeHeadRoutes: false })
656
656
  fastify.register((instance, opts, done) => {
@@ -889,10 +889,10 @@ test('onResponse hook should support encapsulation / 2', (t, testDone) => {
889
889
  const fastify = Fastify()
890
890
  let pluginInstance
891
891
 
892
- fastify.addHook('onResponse', () => {})
892
+ fastify.addHook('onResponse', () => { })
893
893
 
894
894
  fastify.register((instance, opts, done) => {
895
- instance.addHook('onResponse', () => {})
895
+ instance.addHook('onResponse', () => { })
896
896
  pluginInstance = instance
897
897
  done()
898
898
  })
@@ -959,10 +959,10 @@ test('onSend hook should support encapsulation / 1', (t, testDone) => {
959
959
  const fastify = Fastify()
960
960
  let pluginInstance
961
961
 
962
- fastify.addHook('onSend', () => {})
962
+ fastify.addHook('onSend', () => { })
963
963
 
964
964
  fastify.register((instance, opts, done) => {
965
- instance.addHook('onSend', () => {})
965
+ instance.addHook('onSend', () => { })
966
966
  pluginInstance = instance
967
967
  done()
968
968
  })
@@ -1426,7 +1426,7 @@ test('cannot add hook after binding', (t, testDone) => {
1426
1426
  t.assert.ifError(err)
1427
1427
 
1428
1428
  try {
1429
- instance.addHook('onRequest', () => {})
1429
+ instance.addHook('onRequest', () => { })
1430
1430
  t.assert.fail()
1431
1431
  } catch (e) {
1432
1432
  testDone()
@@ -2396,10 +2396,10 @@ test('preValidation hook should support encapsulation / 2', (t, testDone) => {
2396
2396
  const fastify = Fastify()
2397
2397
  let pluginInstance
2398
2398
 
2399
- fastify.addHook('preValidation', () => {})
2399
+ fastify.addHook('preValidation', () => { })
2400
2400
 
2401
2401
  fastify.register((instance, opts, done) => {
2402
- instance.addHook('preValidation', () => {})
2402
+ instance.addHook('preValidation', () => { })
2403
2403
  pluginInstance = instance
2404
2404
  done()
2405
2405
  })
@@ -2739,10 +2739,10 @@ test('preParsing hook should support encapsulation / 2', (t, testDone) => {
2739
2739
  const fastify = Fastify()
2740
2740
  let pluginInstance
2741
2741
 
2742
- fastify.addHook('preParsing', function a () {})
2742
+ fastify.addHook('preParsing', function a () { })
2743
2743
 
2744
2744
  fastify.register((instance, opts, done) => {
2745
- instance.addHook('preParsing', function b () {})
2745
+ instance.addHook('preParsing', function b () { })
2746
2746
  pluginInstance = instance
2747
2747
  done()
2748
2748
  })
@@ -3383,7 +3383,7 @@ test('onRequestAbort should be triggered', (t, testDone) => {
3383
3383
 
3384
3384
  const socket = connect(fastify.server.address().port)
3385
3385
 
3386
- socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
3386
+ socket.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
3387
3387
 
3388
3388
  sleep(500).then(() => socket.destroy())
3389
3389
  })
@@ -3434,7 +3434,7 @@ test('onRequestAbort should support encapsulation', (t, testDone) => {
3434
3434
 
3435
3435
  const socket = connect(fastify.server.address().port)
3436
3436
 
3437
- socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
3437
+ socket.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
3438
3438
 
3439
3439
  sleep(500).then(() => socket.destroy())
3440
3440
  })
@@ -3468,7 +3468,7 @@ test('onRequestAbort should handle errors / 1', (t, testDone) => {
3468
3468
 
3469
3469
  const socket = connect(fastify.server.address().port)
3470
3470
 
3471
- socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
3471
+ socket.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
3472
3472
 
3473
3473
  sleep(500).then(() => socket.destroy())
3474
3474
  })
@@ -3502,7 +3502,7 @@ test('onRequestAbort should handle errors / 2', (t, testDone) => {
3502
3502
 
3503
3503
  const socket = connect(fastify.server.address().port)
3504
3504
 
3505
- socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
3505
+ socket.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
3506
3506
 
3507
3507
  sleep(500).then(() => socket.destroy())
3508
3508
  })
@@ -3536,7 +3536,7 @@ test('onRequestAbort should handle async errors / 1', (t, testDone) => {
3536
3536
 
3537
3537
  const socket = connect(fastify.server.address().port)
3538
3538
 
3539
- socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
3539
+ socket.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
3540
3540
 
3541
3541
  sleep(500).then(() => socket.destroy())
3542
3542
  })
@@ -3571,7 +3571,7 @@ test('onRequestAbort should handle async errors / 2', (t, testDone) => {
3571
3571
 
3572
3572
  const socket = connect(fastify.server.address().port)
3573
3573
 
3574
- socket.write('GET / HTTP/1.1\r\nHost: example.com\r\n\r\n')
3574
+ socket.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
3575
3575
 
3576
3576
  sleep(500).then(() => socket.destroy())
3577
3577
  })
@@ -401,7 +401,7 @@ test('get test', async t => {
401
401
  path: '/port',
402
402
  method: 'GET',
403
403
  headers: {
404
- host: 'example.com'
404
+ host: 'fastify.test'
405
405
  }
406
406
  })
407
407
 
@@ -9,7 +9,7 @@ const bodySample = `<?xml version="1.0" encoding="utf-8" ?>
9
9
  <D:lockscope> <D:exclusive/> </D:lockscope>
10
10
  <D:locktype> <D:write/> </D:locktype>
11
11
  <D:owner>
12
- <D:href>http://example.org/~ejw/contact.html</D:href>
12
+ <D:href>http://fastify.test/~ejw/contact.html</D:href>
13
13
  </D:owner>
14
14
  </D:lockinfo> `
15
15
 
@@ -34,14 +34,14 @@ test('can be created - lock', t => {
34
34
  </D:lockscope>
35
35
  <D:depth>infinity</D:depth>
36
36
  <D:owner>
37
- <D:href>http://example.org/~ejw/contact.html</D:href>
37
+ <D:href>http://fastify.test/~ejw/contact.html</D:href>
38
38
  </D:owner>
39
39
  <D:timeout>Second-604800</D:timeout>
40
40
  <D:locktoken>
41
41
  <D:href>urn:uuid:e71d4fae-5dec-22d6-fea5-00a0c91e6be4</:href>
42
42
  </D:locktoken>
43
43
  <D:lockroot>
44
- <D:href>http://example.com/workspace/webdav/proposal.oc</D:href>
44
+ <D:href>http://fastify.test/workspace/webdav/proposal.oc</D:href>
45
45
  </D:lockroot>
46
46
  </D:activelock>
47
47
  </D:lockdiscovery>
@@ -6,7 +6,7 @@ fastify.addHttpMethod('PROPFIND', { hasBody: true })
6
6
 
7
7
  const bodySample = `<?xml version="1.0" encoding="utf-8" ?>
8
8
  <D:propfind xmlns:D="DAV:">
9
- <D:prop xmlns:R="http://ns.example.com/boxschema/">
9
+ <D:prop xmlns:R="http://ns.fastify.test/boxschema/">
10
10
  <R:bigbox/> <R:author/> <R:DingALing/> <R:Random/>
11
11
  </D:prop>
12
12
  </D:propfind>
@@ -6,7 +6,7 @@ fastify.addHttpMethod('PROPPATCH', { hasBody: true })
6
6
 
7
7
  const bodySample = `<?xml version="1.0" encoding="utf-8" ?>
8
8
  <D:propertyupdate xmlns:D="DAV:"
9
- xmlns:Z="http://ns.example.com/standards/z39.50/">
9
+ xmlns:Z="http://ns.fastify.test/standards/z39.50/">
10
10
  <D:set>
11
11
  <D:prop>
12
12
  <Z:Authors>
@@ -33,9 +33,9 @@ test('shorthand - proppatch', t => {
33
33
  .code(207)
34
34
  .send(`<?xml version="1.0" encoding="utf-8" ?>
35
35
  <D:multistatus xmlns:D="DAV:"
36
- xmlns:Z="http://ns.example.com/standards/z39.50/">
36
+ xmlns:Z="http://ns.fastify.test/standards/z39.50/">
37
37
  <D:response>
38
- <D:href>http://www.example.com/bar.html</D:href>
38
+ <D:href>http://www.fastify.test/bar.html</D:href>
39
39
  <D:propstat>
40
40
  <D:prop>
41
41
  <Z:Authors/>
@@ -121,7 +121,7 @@ test('https - headers', async (t) => {
121
121
  const result = await request('https://localhost:' + fastify.server.address().port, {
122
122
  method: 'GET',
123
123
  headers: {
124
- host: 'example.com'
124
+ host: 'fastify.test'
125
125
  },
126
126
  dispatcher: new Agent({
127
127
  connect: {
@@ -131,6 +131,6 @@ test('https - headers', async (t) => {
131
131
  })
132
132
 
133
133
  t.assert.strictEqual(result.statusCode, 200)
134
- t.assert.deepStrictEqual(await result.body.json(), { hello: 'world', hostname: 'example.com', port: null })
134
+ t.assert.deepStrictEqual(await result.body.json(), { hello: 'world', hostname: 'fastify.test', port: null })
135
135
  })
136
136
  })
@@ -692,11 +692,11 @@ test('plain string with custom json content type should NOT be serialized as jso
692
692
  const customSamples = {
693
693
  collectionjson: {
694
694
  mimeType: 'application/vnd.collection+json',
695
- sample: '{"collection":{"version":"1.0","href":"http://api.example.com/people/"}}'
695
+ sample: '{"collection":{"version":"1.0","href":"http://api.fastify.test/people/"}}'
696
696
  },
697
697
  hal: {
698
698
  mimeType: 'application/hal+json',
699
- sample: '{"_links":{"self":{"href":"https://api.example.com/people/1"}},"name":"John Doe"}'
699
+ sample: '{"_links":{"self":{"href":"https://api.fastify.test/people/1"}},"name":"John Doe"}'
700
700
  },
701
701
  jsonapi: {
702
702
  mimeType: 'application/vnd.api+json',
@@ -777,11 +777,11 @@ test('non-string with custom json content type SHOULD be serialized as json', as
777
777
  const customSamples = {
778
778
  collectionjson: {
779
779
  mimeType: 'application/vnd.collection+json',
780
- sample: JSON.parse('{"collection":{"version":"1.0","href":"http://api.example.com/people/"}}')
780
+ sample: JSON.parse('{"collection":{"version":"1.0","href":"http://api.fastify.test/people/"}}')
781
781
  },
782
782
  hal: {
783
783
  mimeType: 'application/hal+json',
784
- sample: JSON.parse('{"_links":{"self":{"href":"https://api.example.com/people/1"}},"name":"John Doe"}')
784
+ sample: JSON.parse('{"_links":{"self":{"href":"https://api.fastify.test/people/1"}},"name":"John Doe"}')
785
785
  },
786
786
  jsonapi: {
787
787
  mimeType: 'application/vnd.api+json',
@@ -214,7 +214,7 @@ test('Request with trust proxy', t => {
214
214
  t.plan(18)
215
215
  const headers = {
216
216
  'x-forwarded-for': '2.2.2.2, 1.1.1.1',
217
- 'x-forwarded-host': 'example.com'
217
+ 'x-forwarded-host': 'fastify.test'
218
218
  }
219
219
  const req = {
220
220
  method: 'GET',
@@ -257,7 +257,7 @@ test('Request with trust proxy', t => {
257
257
  t.assert.strictEqual(request.log, 'log')
258
258
  t.assert.strictEqual(request.ip, '2.2.2.2')
259
259
  t.assert.deepStrictEqual(request.ips, ['ip', '1.1.1.1', '2.2.2.2'])
260
- t.assert.strictEqual(request.host, 'example.com')
260
+ t.assert.strictEqual(request.host, 'fastify.test')
261
261
  t.assert.strictEqual(request.body, undefined)
262
262
  t.assert.strictEqual(request.method, 'GET')
263
263
  t.assert.strictEqual(request.url, '/')
@@ -272,7 +272,7 @@ test('Request with trust proxy, encrypted', t => {
272
272
  t.plan(2)
273
273
  const headers = {
274
274
  'x-forwarded-for': '2.2.2.2, 1.1.1.1',
275
- 'x-forwarded-host': 'example.com'
275
+ 'x-forwarded-host': 'fastify.test'
276
276
  }
277
277
  const req = {
278
278
  method: 'GET',
@@ -377,7 +377,7 @@ test('Request with trust proxy - x-forwarded-host header has precedence over hos
377
377
  t.plan(2)
378
378
  const headers = {
379
379
  'x-forwarded-for': ' 2.2.2.2, 1.1.1.1',
380
- 'x-forwarded-host': 'example.com',
380
+ 'x-forwarded-host': 'fastify.test',
381
381
  host: 'hostname'
382
382
  }
383
383
  const req = {
@@ -390,13 +390,13 @@ test('Request with trust proxy - x-forwarded-host header has precedence over hos
390
390
  const TpRequest = Request.buildRequest(Request, true)
391
391
  const request = new TpRequest('id', 'params', req, 'query', 'log')
392
392
  t.assert.ok(request instanceof TpRequest)
393
- t.assert.strictEqual(request.host, 'example.com')
393
+ t.assert.strictEqual(request.host, 'fastify.test')
394
394
  })
395
395
 
396
396
  test('Request with trust proxy - handles multiple entries in x-forwarded-host/proto', t => {
397
397
  t.plan(3)
398
398
  const headers = {
399
- 'x-forwarded-host': 'example2.com, example.com',
399
+ 'x-forwarded-host': 'example2.com, fastify.test',
400
400
  'x-forwarded-proto': 'http, https'
401
401
  }
402
402
  const req = {
@@ -409,7 +409,7 @@ test('Request with trust proxy - handles multiple entries in x-forwarded-host/pr
409
409
  const TpRequest = Request.buildRequest(Request, true)
410
410
  const request = new TpRequest('id', 'params', req, 'query', 'log')
411
411
  t.assert.ok(request instanceof TpRequest)
412
- t.assert.strictEqual(request.host, 'example.com')
412
+ t.assert.strictEqual(request.host, 'fastify.test')
413
413
  t.assert.strictEqual(request.protocol, 'https')
414
414
  })
415
415
 
@@ -417,7 +417,7 @@ test('Request with trust proxy - plain', t => {
417
417
  t.plan(1)
418
418
  const headers = {
419
419
  'x-forwarded-for': '2.2.2.2, 1.1.1.1',
420
- 'x-forwarded-host': 'example.com'
420
+ 'x-forwarded-host': 'fastify.test'
421
421
  }
422
422
  const req = {
423
423
  method: 'GET',
@@ -491,7 +491,7 @@ test('Request with trust proxy and undefined socket', t => {
491
491
  t.plan(1)
492
492
  const headers = {
493
493
  'x-forwarded-for': '2.2.2.2, 1.1.1.1',
494
- 'x-forwarded-host': 'example.com'
494
+ 'x-forwarded-host': 'fastify.test'
495
495
  }
496
496
  const req = {
497
497
  method: 'GET',