fastify 5.8.1 → 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.
- package/README.md +1 -0
- package/SECURITY.md +10 -1
- package/docs/Guides/Ecosystem.md +10 -0
- package/docs/Guides/Migration-Guide-V4.md +8 -13
- package/docs/Guides/Migration-Guide-V5.md +1 -1
- package/docs/Guides/Plugins-Guide.md +2 -2
- package/docs/Guides/Recommendations.md +30 -5
- package/docs/Reference/ContentTypeParser.md +15 -0
- package/docs/Reference/Decorators.md +2 -2
- package/docs/Reference/Errors.md +3 -3
- package/docs/Reference/Reply.md +3 -3
- package/docs/Reference/Request.md +1 -1
- package/docs/Reference/Routes.md +4 -4
- package/docs/Reference/Server.md +17 -14
- package/docs/Reference/Validation-and-Serialization.md +60 -14
- package/docs/Reference/Warnings.md +5 -5
- package/fastify.js +2 -2
- package/lib/content-type.js +4 -2
- package/lib/request.js +8 -6
- package/package.json +2 -2
- package/test/client-timeout.test.js +1 -1
- package/test/close.test.js +2 -2
- package/test/constrained-routes.test.js +6 -6
- package/test/hooks.test.js +18 -18
- package/test/http-methods/get.test.js +1 -1
- package/test/http-methods/lock.test.js +3 -3
- package/test/http-methods/propfind.test.js +1 -1
- package/test/http-methods/proppatch.test.js +3 -3
- package/test/https/https.test.js +2 -2
- package/test/internals/reply.test.js +4 -4
- package/test/internals/request.test.js +9 -9
- package/test/max-requests-per-socket.test.js +6 -6
- package/test/request-error.test.js +3 -3
- package/test/schema-examples.test.js +2 -2
- package/test/schema-feature.test.js +15 -15
- package/test/schema-serialization.test.js +6 -6
- package/test/schema-special-usage.test.js +5 -5
- package/test/schema-validation.test.js +2 -2
- package/test/skip-reply-send.test.js +1 -1
- package/test/trust-proxy.test.js +68 -9
- package/test/types/logger.test-d.ts +25 -25
- package/test/types/request.test-d.ts +1 -1
- package/test/types/route.test-d.ts +3 -3
- package/types/request.d.ts +1 -1
|
@@ -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
|
|
22
|
-
and [`--trace-deprecation`](https://nodejs.org/api/cli.html
|
|
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
|
|
52
|
-
- [--throw-deprecation](https://nodejs.org/api/cli.html
|
|
53
|
-
- [--trace-deprecation](https://nodejs.org/api/cli.html
|
|
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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const VERSION = '5.8.
|
|
3
|
+
const VERSION = '5.8.2'
|
|
4
4
|
|
|
5
5
|
const Avvio = require('avvio')
|
|
6
6
|
const http = require('node:http')
|
|
@@ -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#
|
|
925
|
+
// https://nodejs.org/api/http.html#event-clienterror
|
|
926
926
|
if (err.code === 'ECONNRESET' || socket.destroyed) {
|
|
927
927
|
return
|
|
928
928
|
}
|
package/lib/content-type.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* keyValuePairsReg is used to split the parameters list into associated
|
|
5
|
-
* key value pairings.
|
|
5
|
+
* key value pairings. The leading `(?:^|;)\s*` anchor ensures the regex
|
|
6
|
+
* only attempts matches at parameter boundaries, preventing quadratic
|
|
7
|
+
* backtracking on malformed input.
|
|
6
8
|
*
|
|
7
9
|
* @see https://httpwg.org/specs/rfc9110.html#parameter
|
|
8
10
|
* @type {RegExp}
|
|
9
11
|
*/
|
|
10
|
-
const keyValuePairsReg = /([\w!#$%&'*+.^`|~-]+)=([^;]*)/gm
|
|
12
|
+
const keyValuePairsReg = /(?:^|;)\s*([\w!#$%&'*+.^`|~-]+)=([^;]*)/gm
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* typeNameReg is used to validate that the first part of the media-type
|
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
|
|
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
|
-
|
|
55
|
+
const trust = proxyAddr.compile(values)
|
|
56
|
+
return function (a, i) { return a != null && trust(a, i) }
|
|
56
57
|
}
|
|
57
|
-
|
|
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.
|
|
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.
|
|
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",
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
"ajv-i18n": "^4.2.0",
|
|
178
178
|
"ajv-merge-patch": "^5.0.1",
|
|
179
179
|
"autocannon": "^8.0.0",
|
|
180
|
-
"borp": "^
|
|
180
|
+
"borp": "^0.21.0",
|
|
181
181
|
"branch-comparer": "^1.1.0",
|
|
182
182
|
"concurrently": "^9.1.2",
|
|
183
183
|
"cross-env": "^10.0.0",
|
|
@@ -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:
|
|
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', () => {
|
package/test/close.test.js
CHANGED
|
@@ -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:
|
|
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:
|
|
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: '
|
|
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: '
|
|
68
|
+
constraints: { host: 'fastify.test' },
|
|
69
69
|
handler: (req, reply) => {
|
|
70
|
-
reply.send('
|
|
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: '
|
|
91
|
+
host: 'fastify.test'
|
|
92
92
|
}
|
|
93
93
|
})
|
|
94
94
|
|
|
95
95
|
t.assert.strictEqual(res.statusCode, 200)
|
|
96
|
-
t.assert.strictEqual(res.payload, '
|
|
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: '
|
|
571
|
+
host: 'fastify.test'
|
|
572
572
|
}
|
|
573
573
|
})
|
|
574
574
|
t.assert.deepStrictEqual(JSON.parse(res.payload), { hello: 'from any other domain' })
|
package/test/hooks.test.js
CHANGED
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
})
|
|
@@ -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://
|
|
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://
|
|
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://
|
|
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.
|
|
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.
|
|
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.
|
|
36
|
+
xmlns:Z="http://ns.fastify.test/standards/z39.50/">
|
|
37
37
|
<D:response>
|
|
38
|
-
<D:href>http://www.
|
|
38
|
+
<D:href>http://www.fastify.test/bar.html</D:href>
|
|
39
39
|
<D:propstat>
|
|
40
40
|
<D:prop>
|
|
41
41
|
<Z:Authors/>
|
package/test/https/https.test.js
CHANGED
|
@@ -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: '
|
|
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: '
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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': '
|
|
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, '
|
|
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': '
|
|
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': '
|
|
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, '
|
|
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,
|
|
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, '
|
|
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': '
|
|
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': '
|
|
494
|
+
'x-forwarded-host': 'fastify.test'
|
|
495
495
|
}
|
|
496
496
|
const req = {
|
|
497
497
|
method: 'GET',
|
|
@@ -17,20 +17,20 @@ test('maxRequestsPerSocket', (t, done) => {
|
|
|
17
17
|
|
|
18
18
|
const port = fastify.server.address().port
|
|
19
19
|
const client = net.createConnection({ port }, () => {
|
|
20
|
-
client.write('GET / HTTP/1.1\r\nHost:
|
|
20
|
+
client.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
|
|
21
21
|
|
|
22
22
|
client.once('data', data => {
|
|
23
23
|
t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
24
24
|
t.assert.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
|
|
25
25
|
t.assert.match(data.toString(), /200 OK/i)
|
|
26
26
|
|
|
27
|
-
client.write('GET / HTTP/1.1\r\nHost:
|
|
27
|
+
client.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
|
|
28
28
|
|
|
29
29
|
client.once('data', data => {
|
|
30
30
|
t.assert.match(data.toString(), /Connection:\s*close/i)
|
|
31
31
|
t.assert.match(data.toString(), /200 OK/i)
|
|
32
32
|
|
|
33
|
-
client.write('GET / HTTP/1.1\r\nHost:
|
|
33
|
+
client.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
|
|
34
34
|
|
|
35
35
|
client.once('data', data => {
|
|
36
36
|
t.assert.match(data.toString(), /Connection:\s*close/i)
|
|
@@ -58,21 +58,21 @@ test('maxRequestsPerSocket zero should behave same as null', (t, done) => {
|
|
|
58
58
|
|
|
59
59
|
const port = fastify.server.address().port
|
|
60
60
|
const client = net.createConnection({ port }, () => {
|
|
61
|
-
client.write('GET / HTTP/1.1\r\nHost:
|
|
61
|
+
client.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
|
|
62
62
|
|
|
63
63
|
client.once('data', data => {
|
|
64
64
|
t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
65
65
|
t.assert.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
|
|
66
66
|
t.assert.match(data.toString(), /200 OK/i)
|
|
67
67
|
|
|
68
|
-
client.write('GET / HTTP/1.1\r\nHost:
|
|
68
|
+
client.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
|
|
69
69
|
|
|
70
70
|
client.once('data', data => {
|
|
71
71
|
t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
72
72
|
t.assert.match(data.toString(), /Keep-Alive:\s*timeout=\d+/i)
|
|
73
73
|
t.assert.match(data.toString(), /200 OK/i)
|
|
74
74
|
|
|
75
|
-
client.write('GET / HTTP/1.1\r\nHost:
|
|
75
|
+
client.write('GET / HTTP/1.1\r\nHost: fastify.test\r\n\r\n')
|
|
76
76
|
|
|
77
77
|
client.once('data', data => {
|
|
78
78
|
t.assert.match(data.toString(), /Connection:\s*keep-alive/i)
|
|
@@ -127,7 +127,7 @@ test('default clientError handler ignores ECONNRESET', (t, done) => {
|
|
|
127
127
|
|
|
128
128
|
client.resume()
|
|
129
129
|
client.write('GET / HTTP/1.1\r\n')
|
|
130
|
-
client.write('Host:
|
|
130
|
+
client.write('Host: fastify.test\r\n')
|
|
131
131
|
client.write('Connection: close\r\n')
|
|
132
132
|
client.write('\r\n\r\n')
|
|
133
133
|
})
|
|
@@ -316,10 +316,10 @@ test('default clientError replies with bad request on reused keep-alive connecti
|
|
|
316
316
|
|
|
317
317
|
client.resume()
|
|
318
318
|
client.write('GET / HTTP/1.1\r\n')
|
|
319
|
-
client.write('Host:
|
|
319
|
+
client.write('Host: fastify.test\r\n')
|
|
320
320
|
client.write('\r\n\r\n')
|
|
321
321
|
client.write('GET /?a b HTTP/1.1\r\n')
|
|
322
|
-
client.write('Host:
|
|
322
|
+
client.write('Host: fastify.test\r\n')
|
|
323
323
|
client.write('Connection: close\r\n')
|
|
324
324
|
client.write('\r\n\r\n')
|
|
325
325
|
})
|
|
@@ -8,7 +8,7 @@ test('Example - URI $id', (t, done) => {
|
|
|
8
8
|
t.plan(1)
|
|
9
9
|
const fastify = Fastify()
|
|
10
10
|
fastify.addSchema({
|
|
11
|
-
$id: 'http://
|
|
11
|
+
$id: 'http://fastify.test/',
|
|
12
12
|
type: 'object',
|
|
13
13
|
properties: {
|
|
14
14
|
hello: { type: 'string' }
|
|
@@ -20,7 +20,7 @@ test('Example - URI $id', (t, done) => {
|
|
|
20
20
|
schema: {
|
|
21
21
|
body: {
|
|
22
22
|
type: 'array',
|
|
23
|
-
items: { $ref: 'http://
|
|
23
|
+
items: { $ref: 'http://fastify.test#/properties/hello' }
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
})
|