fastify 5.3.2 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/build/build-validation.js +2 -1
- package/docs/Guides/Delay-Accepting-Requests.md +3 -3
- package/docs/Guides/Ecosystem.md +16 -7
- package/docs/Guides/Serverless.md +28 -69
- package/docs/Reference/ContentTypeParser.md +1 -1
- package/docs/Reference/Errors.md +2 -4
- package/docs/Reference/Hooks.md +14 -14
- package/docs/Reference/Logging.md +3 -3
- package/docs/Reference/Middleware.md +1 -1
- package/docs/Reference/Reply.md +8 -8
- package/docs/Reference/Request.md +1 -1
- package/docs/Reference/Routes.md +3 -3
- package/docs/Reference/Server.md +40 -10
- package/docs/Reference/Validation-and-Serialization.md +1 -1
- package/eslint.config.js +17 -9
- package/fastify.d.ts +2 -1
- package/fastify.js +20 -4
- package/lib/configValidator.js +1 -1
- package/lib/decorate.js +2 -2
- package/lib/errors.js +6 -8
- package/lib/logger-factory.js +1 -1
- package/lib/logger-pino.js +2 -2
- package/lib/pluginOverride.js +3 -1
- package/lib/reply.js +9 -13
- package/lib/request.js +4 -11
- package/lib/server.js +30 -51
- package/lib/symbols.js +1 -0
- package/lib/warnings.js +8 -0
- package/package.json +11 -7
- package/test/404s.test.js +226 -325
- package/test/allow-unsafe-regex.test.js +19 -48
- package/test/als.test.js +28 -40
- package/test/async-await.test.js +11 -2
- package/test/body-limit.test.js +41 -65
- package/test/build-certificate.js +1 -1
- package/test/close-pipelining.test.js +5 -4
- package/test/custom-parser-async.test.js +17 -22
- package/test/decorator-namespace.test._js_ +3 -4
- package/test/decorator.test.js +422 -341
- package/test/diagnostics-channel/async-delay-request.test.js +7 -16
- package/test/diagnostics-channel/sync-delay-request.test.js +7 -16
- package/test/helper.js +108 -70
- package/test/hooks-async.test.js +248 -218
- package/test/hooks.on-listen.test.js +255 -239
- package/test/hooks.on-ready.test.js +110 -92
- package/test/hooks.test.js +910 -769
- package/test/http-methods/lock.test.js +31 -31
- package/test/http-methods/mkcol.test.js +5 -9
- package/test/http-methods/proppatch.test.js +23 -29
- package/test/http-methods/report.test.js +44 -69
- package/test/http-methods/search.test.js +67 -82
- package/test/http2/closing.test.js +38 -20
- package/test/http2/secure-with-fallback.test.js +28 -27
- package/test/https/https.test.js +56 -53
- package/test/inject.test.js +114 -97
- package/test/input-validation.js +63 -53
- package/test/internals/errors.test.js +0 -10
- package/test/internals/handle-request.test.js +49 -66
- package/test/internals/hooks.test.js +17 -0
- package/test/issue-4959.test.js +14 -5
- package/test/listen.4.test.js +31 -43
- package/test/logger/response.test.js +19 -20
- package/test/nullable-validation.test.js +33 -46
- package/test/options.error-handler.test.js +1 -1
- package/test/options.test.js +1 -1
- package/test/output-validation.test.js +49 -72
- package/test/patch.error-handler.test.js +1 -1
- package/test/patch.test.js +1 -1
- package/test/plugin.1.test.js +71 -60
- package/test/plugin.2.test.js +104 -86
- package/test/plugin.3.test.js +56 -35
- package/test/plugin.4.test.js +124 -119
- package/test/promises.test.js +36 -30
- package/test/proto-poisoning.test.js +78 -97
- package/test/put.error-handler.test.js +1 -1
- package/test/put.test.js +1 -1
- package/test/reply-error.test.js +169 -148
- package/test/reply-trailers.test.js +119 -108
- package/test/request-error.test.js +0 -46
- package/test/route-hooks.test.js +112 -92
- package/test/route-prefix.test.js +194 -133
- package/test/schema-feature.test.js +309 -238
- package/test/schema-serialization.test.js +177 -154
- package/test/schema-special-usage.test.js +165 -132
- package/test/schema-validation.test.js +278 -199
- package/test/set-error-handler.test.js +58 -1
- package/test/skip-reply-send.test.js +64 -69
- package/test/stream.1.test.js +30 -27
- package/test/stream.2.test.js +20 -10
- package/test/stream.3.test.js +37 -31
- package/test/trust-proxy.test.js +32 -58
- package/test/types/errors.test-d.ts +0 -1
- package/test/types/fastify.test-d.ts +3 -0
- package/test/types/plugin.test-d.ts +1 -1
- package/test/types/register.test-d.ts +1 -1
- package/test/types/request.test-d.ts +1 -0
- package/test/url-rewriting.test.js +45 -62
- package/test/use-semicolon-delimiter.test.js +1 -1
- package/types/errors.d.ts +0 -1
- package/types/request.d.ts +1 -0
- package/.taprc +0 -7
- package/test/http2/missing-http2-module.test.js +0 -17
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../fastify')()
|
|
6
5
|
fastify.addHttpMethod('LOCK', { hasBody: true })
|
|
7
6
|
|
|
@@ -57,52 +56,53 @@ test('can be created - lock', t => {
|
|
|
57
56
|
})
|
|
58
57
|
|
|
59
58
|
test('lock test', async t => {
|
|
60
|
-
await fastify.listen({ port: 0 })
|
|
59
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
61
60
|
t.after(() => {
|
|
62
61
|
fastify.close()
|
|
63
62
|
})
|
|
64
63
|
// the body test uses a text/plain content type instead of application/xml because it requires
|
|
65
64
|
// a specific content type parser
|
|
66
|
-
await t.test('request with body - lock', (t
|
|
65
|
+
await t.test('request with body - lock', async (t) => {
|
|
67
66
|
t.plan(3)
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
|
|
68
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
69
|
+
method: 'LOCK',
|
|
70
70
|
headers: { 'content-type': 'text/plain' },
|
|
71
|
-
body: bodySample
|
|
72
|
-
method: 'LOCK'
|
|
73
|
-
}, (err, response, body) => {
|
|
74
|
-
t.assert.ifError(err)
|
|
75
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
76
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
77
|
-
done()
|
|
71
|
+
body: bodySample
|
|
78
72
|
})
|
|
73
|
+
|
|
74
|
+
t.assert.ok(result.ok)
|
|
75
|
+
t.assert.strictEqual(result.status, 200)
|
|
76
|
+
const body = await result.text()
|
|
77
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
79
78
|
})
|
|
80
79
|
|
|
81
|
-
await t.test('request with body and no content type (415 error) - lock', (t
|
|
80
|
+
await t.test('request with body and no content type (415 error) - lock', async (t) => {
|
|
82
81
|
t.plan(3)
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
|
|
83
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
84
|
+
method: 'LOCK',
|
|
85
85
|
body: bodySample,
|
|
86
|
-
|
|
87
|
-
}, (err, response, body) => {
|
|
88
|
-
t.assert.ifError(err)
|
|
89
|
-
t.assert.strictEqual(response.statusCode, 415)
|
|
90
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
91
|
-
done()
|
|
86
|
+
headers: { 'content-type': undefined }
|
|
92
87
|
})
|
|
88
|
+
|
|
89
|
+
t.assert.ok(!result.ok)
|
|
90
|
+
t.assert.strictEqual(result.status, 415)
|
|
91
|
+
const body = await result.text()
|
|
92
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
93
93
|
})
|
|
94
94
|
|
|
95
|
-
await t.test('request without body - lock', (t
|
|
95
|
+
await t.test('request without body - lock', async (t) => {
|
|
96
96
|
t.plan(3)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}, (err, response, body) => {
|
|
102
|
-
t.assert.ifError(err)
|
|
103
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
104
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
105
|
-
done()
|
|
97
|
+
|
|
98
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
99
|
+
method: 'LOCK',
|
|
100
|
+
headers: { 'content-type': 'text/plain' }
|
|
106
101
|
})
|
|
102
|
+
|
|
103
|
+
t.assert.ok(result.ok)
|
|
104
|
+
t.assert.strictEqual(result.status, 200)
|
|
105
|
+
const body = await result.text()
|
|
106
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
107
107
|
})
|
|
108
108
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../')()
|
|
6
5
|
fastify.addHttpMethod('MKCOL')
|
|
7
6
|
|
|
@@ -22,18 +21,15 @@ test('can be created - mkcol', t => {
|
|
|
22
21
|
})
|
|
23
22
|
|
|
24
23
|
test('mkcol test', async t => {
|
|
25
|
-
await fastify.listen({ port: 0 })
|
|
24
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
26
25
|
t.after(() => { fastify.close() })
|
|
27
26
|
|
|
28
|
-
await t.test('request - mkcol',
|
|
27
|
+
await t.test('request - mkcol', async t => {
|
|
29
28
|
t.plan(2)
|
|
30
|
-
|
|
31
|
-
url: `http://localhost:${fastify.server.address().port}/test/`,
|
|
29
|
+
const result = await fetch(`${fastifyServer}/test/`, {
|
|
32
30
|
method: 'MKCOL'
|
|
33
|
-
}, (err, response, body) => {
|
|
34
|
-
t.assert.ifError(err)
|
|
35
|
-
t.assert.strictEqual(response.statusCode, 201)
|
|
36
|
-
done()
|
|
37
31
|
})
|
|
32
|
+
t.assert.ok(result.ok)
|
|
33
|
+
t.assert.strictEqual(result.status, 201)
|
|
38
34
|
})
|
|
39
35
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../')()
|
|
6
5
|
fastify.addHttpMethod('PROPPATCH', { hasBody: true })
|
|
7
6
|
|
|
@@ -62,50 +61,45 @@ test('shorthand - proppatch', t => {
|
|
|
62
61
|
})
|
|
63
62
|
|
|
64
63
|
test('proppatch test', async t => {
|
|
65
|
-
await fastify.listen({ port: 0 })
|
|
64
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
66
65
|
|
|
67
66
|
t.after(() => { fastify.close() })
|
|
68
67
|
// the body test uses a text/plain content type instead of application/xml because it requires
|
|
69
68
|
// a specific content type parser
|
|
70
|
-
await t.test('request with body - proppatch',
|
|
69
|
+
await t.test('request with body - proppatch', async t => {
|
|
71
70
|
t.plan(3)
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
72
|
+
method: 'PROPPATCH',
|
|
74
73
|
headers: { 'content-type': 'text/plain' },
|
|
75
|
-
body: bodySample
|
|
76
|
-
method: 'PROPPATCH'
|
|
77
|
-
}, (err, response, body) => {
|
|
78
|
-
t.assert.ifError(err)
|
|
79
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
80
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
81
|
-
done()
|
|
74
|
+
body: bodySample
|
|
82
75
|
})
|
|
76
|
+
t.assert.ok(result.ok)
|
|
77
|
+
t.assert.strictEqual(result.status, 207)
|
|
78
|
+
const body = await result.text()
|
|
79
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
83
80
|
})
|
|
84
81
|
|
|
85
|
-
await t.test('request with body and no content type (415 error) - proppatch',
|
|
82
|
+
await t.test('request with body and no content type (415 error) - proppatch', async t => {
|
|
86
83
|
t.plan(3)
|
|
87
|
-
|
|
88
|
-
|
|
84
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
85
|
+
method: 'PROPPATCH',
|
|
89
86
|
body: bodySample,
|
|
90
|
-
|
|
91
|
-
}, (err, response, body) => {
|
|
92
|
-
t.assert.ifError(err)
|
|
93
|
-
t.assert.strictEqual(response.statusCode, 415)
|
|
94
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
95
|
-
done()
|
|
87
|
+
headers: { 'content-type': undefined }
|
|
96
88
|
})
|
|
89
|
+
t.assert.ok(!result.ok)
|
|
90
|
+
t.assert.strictEqual(result.status, 415)
|
|
91
|
+
const body = await result.text()
|
|
92
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
97
93
|
})
|
|
98
94
|
|
|
99
|
-
await t.test('request without body - proppatch',
|
|
95
|
+
await t.test('request without body - proppatch', async t => {
|
|
100
96
|
t.plan(3)
|
|
101
|
-
|
|
102
|
-
url: `http://localhost:${fastify.server.address().port}/test/a.txt`,
|
|
97
|
+
const result = await fetch(`${fastifyServer}/test/a.txt`, {
|
|
103
98
|
method: 'PROPPATCH'
|
|
104
|
-
}, (err, response, body) => {
|
|
105
|
-
t.assert.ifError(err)
|
|
106
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
107
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
108
|
-
done()
|
|
109
99
|
})
|
|
100
|
+
t.assert.ok(result.ok)
|
|
101
|
+
t.assert.strictEqual(result.status, 207)
|
|
102
|
+
const body = await result.text()
|
|
103
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
110
104
|
})
|
|
111
105
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../fastify')()
|
|
6
5
|
fastify.addHttpMethod('REPORT', { hasBody: true })
|
|
7
6
|
|
|
@@ -80,88 +79,64 @@ test('report test', async t => {
|
|
|
80
79
|
fastify.close()
|
|
81
80
|
})
|
|
82
81
|
|
|
83
|
-
await t.test('request - report', (t
|
|
82
|
+
await t.test('request - report', async (t) => {
|
|
84
83
|
t.plan(3)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
93
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
94
|
-
done()
|
|
95
|
-
}
|
|
96
|
-
)
|
|
84
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/`, {
|
|
85
|
+
method: 'REPORT'
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
t.assert.ok(result.ok)
|
|
89
|
+
t.assert.strictEqual(result.status, 207)
|
|
90
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + (await result.text()).length)
|
|
97
91
|
})
|
|
98
92
|
|
|
99
|
-
await t.test('request with other path - report', (t
|
|
93
|
+
await t.test('request with other path - report', async (t) => {
|
|
100
94
|
t.plan(3)
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
109
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
110
|
-
done()
|
|
111
|
-
}
|
|
112
|
-
)
|
|
95
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
96
|
+
method: 'REPORT'
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
t.assert.ok(result.ok)
|
|
100
|
+
t.assert.strictEqual(result.status, 207)
|
|
101
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + (await result.text()).length)
|
|
113
102
|
})
|
|
114
103
|
|
|
115
104
|
// the body test uses a text/plain content type instead of application/xml because it requires
|
|
116
105
|
// a specific content type parser
|
|
117
|
-
await t.test('request with body - report', (t
|
|
106
|
+
await t.test('request with body - report', async (t) => {
|
|
118
107
|
t.plan(3)
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
129
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
130
|
-
done()
|
|
131
|
-
}
|
|
132
|
-
)
|
|
108
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
109
|
+
method: 'REPORT',
|
|
110
|
+
headers: { 'content-type': 'text/plain' },
|
|
111
|
+
body: bodySample
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
t.assert.ok(result.ok)
|
|
115
|
+
t.assert.strictEqual(result.status, 207)
|
|
116
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + (await result.text()).length)
|
|
133
117
|
})
|
|
134
118
|
|
|
135
|
-
await t.test('request with body and no content type (415 error) - report', (t
|
|
119
|
+
await t.test('request with body and no content type (415 error) - report', async (t) => {
|
|
136
120
|
t.plan(3)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
147
|
-
done()
|
|
148
|
-
}
|
|
149
|
-
)
|
|
121
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
122
|
+
method: 'REPORT',
|
|
123
|
+
body: bodySample,
|
|
124
|
+
headers: { 'content-type': '' }
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
t.assert.ok(!result.ok)
|
|
128
|
+
t.assert.strictEqual(result.status, 415)
|
|
129
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + (await result.text()).length)
|
|
150
130
|
})
|
|
151
131
|
|
|
152
|
-
await t.test('request without body - report', (t
|
|
132
|
+
await t.test('request without body - report', async (t) => {
|
|
153
133
|
t.plan(3)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
t.assert.strictEqual(response.statusCode, 207)
|
|
162
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
163
|
-
done()
|
|
164
|
-
}
|
|
165
|
-
)
|
|
134
|
+
const result = await fetch(`http://localhost:${fastify.server.address().port}/test`, {
|
|
135
|
+
method: 'REPORT'
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
t.assert.ok(result.ok)
|
|
139
|
+
t.assert.strictEqual(result.status, 207)
|
|
140
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + (await result.text()).length)
|
|
166
141
|
})
|
|
167
142
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { test } = require('node:test')
|
|
4
|
-
const sget = require('simple-get').concat
|
|
5
4
|
const fastify = require('../../fastify')()
|
|
6
5
|
fastify.addHttpMethod('SEARCH', { hasBody: true })
|
|
7
6
|
|
|
@@ -130,119 +129,105 @@ test('search test', async t => {
|
|
|
130
129
|
t.after(() => { fastify.close() })
|
|
131
130
|
const url = `http://localhost:${fastify.server.address().port}`
|
|
132
131
|
|
|
133
|
-
await t.test('request - search',
|
|
132
|
+
await t.test('request - search', async t => {
|
|
134
133
|
t.plan(4)
|
|
135
|
-
|
|
136
|
-
method: 'SEARCH'
|
|
137
|
-
url
|
|
138
|
-
}, (err, response, body) => {
|
|
139
|
-
t.assert.ifError(err)
|
|
140
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
141
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
142
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
143
|
-
done()
|
|
134
|
+
const result = await fetch(url, {
|
|
135
|
+
method: 'SEARCH'
|
|
144
136
|
})
|
|
137
|
+
const body = await result.text()
|
|
138
|
+
t.assert.ok(result.ok)
|
|
139
|
+
t.assert.strictEqual(result.status, 200)
|
|
140
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
141
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 'world' })
|
|
145
142
|
})
|
|
146
143
|
|
|
147
|
-
await t.test('request search params schema',
|
|
144
|
+
await t.test('request search params schema', async t => {
|
|
148
145
|
t.plan(4)
|
|
149
|
-
|
|
150
|
-
method: 'SEARCH'
|
|
151
|
-
url: `${url}/params/world/123`
|
|
152
|
-
}, (err, response, body) => {
|
|
153
|
-
t.assert.ifError(err)
|
|
154
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
155
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
156
|
-
t.assert.deepStrictEqual(JSON.parse(body), { foo: 'world', test: 123 })
|
|
157
|
-
done()
|
|
146
|
+
const result = await fetch(`${url}/params/world/123`, {
|
|
147
|
+
method: 'SEARCH'
|
|
158
148
|
})
|
|
149
|
+
const body = await result.text()
|
|
150
|
+
t.assert.ok(result.ok)
|
|
151
|
+
t.assert.strictEqual(result.status, 200)
|
|
152
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
153
|
+
t.assert.deepStrictEqual(JSON.parse(body), { foo: 'world', test: 123 })
|
|
159
154
|
})
|
|
160
155
|
|
|
161
|
-
await t.test('request search params schema error',
|
|
156
|
+
await t.test('request search params schema error', async t => {
|
|
162
157
|
t.plan(3)
|
|
163
|
-
|
|
164
|
-
method: 'SEARCH'
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
})
|
|
175
|
-
done()
|
|
158
|
+
const result = await fetch(`${url}/params/world/string`, {
|
|
159
|
+
method: 'SEARCH'
|
|
160
|
+
})
|
|
161
|
+
const body = await result.text()
|
|
162
|
+
t.assert.strictEqual(result.status, 400)
|
|
163
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
164
|
+
t.assert.deepStrictEqual(JSON.parse(body), {
|
|
165
|
+
error: 'Bad Request',
|
|
166
|
+
code: 'FST_ERR_VALIDATION',
|
|
167
|
+
message: 'params/test must be integer',
|
|
168
|
+
statusCode: 400
|
|
176
169
|
})
|
|
177
170
|
})
|
|
178
171
|
|
|
179
|
-
await t.test('request search querystring schema',
|
|
172
|
+
await t.test('request search querystring schema', async t => {
|
|
180
173
|
t.plan(4)
|
|
181
|
-
|
|
182
|
-
method: 'SEARCH'
|
|
183
|
-
url: `${url}/query?hello=123`
|
|
184
|
-
}, (err, response, body) => {
|
|
185
|
-
t.assert.ifError(err)
|
|
186
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
187
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
188
|
-
t.assert.deepStrictEqual(JSON.parse(body), { hello: 123 })
|
|
189
|
-
done()
|
|
174
|
+
const result = await fetch(`${url}/query?hello=123`, {
|
|
175
|
+
method: 'SEARCH'
|
|
190
176
|
})
|
|
177
|
+
const body = await result.text()
|
|
178
|
+
t.assert.ok(result.ok)
|
|
179
|
+
t.assert.strictEqual(result.status, 200)
|
|
180
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
181
|
+
t.assert.deepStrictEqual(JSON.parse(body), { hello: 123 })
|
|
191
182
|
})
|
|
192
183
|
|
|
193
|
-
await t.test('request search querystring schema error',
|
|
184
|
+
await t.test('request search querystring schema error', async t => {
|
|
194
185
|
t.plan(3)
|
|
195
|
-
|
|
196
|
-
method: 'SEARCH'
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
})
|
|
207
|
-
done()
|
|
186
|
+
const result = await fetch(`${url}/query?hello=world`, {
|
|
187
|
+
method: 'SEARCH'
|
|
188
|
+
})
|
|
189
|
+
const body = await result.text()
|
|
190
|
+
t.assert.strictEqual(result.status, 400)
|
|
191
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
192
|
+
t.assert.deepStrictEqual(JSON.parse(body), {
|
|
193
|
+
error: 'Bad Request',
|
|
194
|
+
code: 'FST_ERR_VALIDATION',
|
|
195
|
+
message: 'querystring/hello must be integer',
|
|
196
|
+
statusCode: 400
|
|
208
197
|
})
|
|
209
198
|
})
|
|
210
199
|
|
|
211
|
-
await t.test('request search body schema',
|
|
200
|
+
await t.test('request search body schema', async t => {
|
|
212
201
|
t.plan(4)
|
|
213
202
|
const replyBody = { foo: 'bar', test: 5 }
|
|
214
|
-
|
|
203
|
+
const result = await fetch(`${url}/body`, {
|
|
215
204
|
method: 'SEARCH',
|
|
216
|
-
url: `${url}/body`,
|
|
217
205
|
body: JSON.stringify(replyBody),
|
|
218
206
|
headers: { 'content-type': 'application/json' }
|
|
219
|
-
}, (err, response, body) => {
|
|
220
|
-
t.assert.ifError(err)
|
|
221
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
222
|
-
t.assert.strictEqual(response.headers['content-length'], '' + body.length)
|
|
223
|
-
t.assert.deepStrictEqual(JSON.parse(body), replyBody)
|
|
224
|
-
done()
|
|
225
207
|
})
|
|
208
|
+
const body = await result.text()
|
|
209
|
+
t.assert.ok(result.ok)
|
|
210
|
+
t.assert.strictEqual(result.status, 200)
|
|
211
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
212
|
+
t.assert.deepStrictEqual(JSON.parse(body), replyBody)
|
|
226
213
|
})
|
|
227
214
|
|
|
228
|
-
await t.test('request search body schema error',
|
|
215
|
+
await t.test('request search body schema error', async t => {
|
|
229
216
|
t.plan(4)
|
|
230
|
-
|
|
217
|
+
const result = await fetch(`${url}/body`, {
|
|
231
218
|
method: 'SEARCH',
|
|
232
|
-
url: `${url}/body`,
|
|
233
219
|
body: JSON.stringify({ foo: 'bar', test: 'test' }),
|
|
234
220
|
headers: { 'content-type': 'application/json' }
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
done()
|
|
221
|
+
})
|
|
222
|
+
const body = await result.text()
|
|
223
|
+
t.assert.ok(!result.ok)
|
|
224
|
+
t.assert.strictEqual(result.status, 400)
|
|
225
|
+
t.assert.strictEqual(result.headers.get('content-length'), '' + body.length)
|
|
226
|
+
t.assert.deepStrictEqual(JSON.parse(body), {
|
|
227
|
+
error: 'Bad Request',
|
|
228
|
+
code: 'FST_ERR_VALIDATION',
|
|
229
|
+
message: 'body/test must be integer',
|
|
230
|
+
statusCode: 400
|
|
246
231
|
})
|
|
247
232
|
})
|
|
248
233
|
})
|
|
@@ -11,16 +11,13 @@ const { getServerUrl } = require('../helper')
|
|
|
11
11
|
|
|
12
12
|
test.before(buildCertificate)
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
} catch (e) {
|
|
22
|
-
t.assert.fail('http2 loading failed')
|
|
23
|
-
}
|
|
14
|
+
const isNode24OrGreater = Number(process.versions.node.split('.')[0]) >= 24
|
|
15
|
+
|
|
16
|
+
test('http/2 request while fastify closing Node <24', { skip: isNode24OrGreater }, (t, done) => {
|
|
17
|
+
const fastify = Fastify({
|
|
18
|
+
http2: true
|
|
19
|
+
})
|
|
20
|
+
t.assert.ok('http2 successfully loaded')
|
|
24
21
|
|
|
25
22
|
fastify.get('/', () => Promise.resolve({}))
|
|
26
23
|
|
|
@@ -53,17 +50,38 @@ test('http/2 request while fastify closing', (t, done) => {
|
|
|
53
50
|
})
|
|
54
51
|
})
|
|
55
52
|
|
|
56
|
-
test('http/2 request while fastify closing
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
test('http/2 request while fastify closing Node >=24', { skip: !isNode24OrGreater }, (t, done) => {
|
|
54
|
+
const fastify = Fastify({
|
|
55
|
+
http2: true
|
|
56
|
+
})
|
|
57
|
+
t.assert.ok('http2 successfully loaded')
|
|
58
|
+
|
|
59
|
+
fastify.get('/', () => Promise.resolve({}))
|
|
60
|
+
|
|
61
|
+
t.after(() => { fastify.close() })
|
|
62
|
+
fastify.listen({ port: 0 }, err => {
|
|
63
|
+
t.assert.ifError(err)
|
|
64
|
+
|
|
65
|
+
const url = getServerUrl(fastify)
|
|
66
|
+
const session = http2.connect(url, function () {
|
|
67
|
+
session.on('error', () => {
|
|
68
|
+
// Nothing to do here,
|
|
69
|
+
// we are not interested in this error that might
|
|
70
|
+
// happen or not
|
|
71
|
+
})
|
|
72
|
+
session.on('close', () => {
|
|
73
|
+
done()
|
|
74
|
+
})
|
|
75
|
+
fastify.close()
|
|
62
76
|
})
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('http/2 request while fastify closing - return503OnClosing: false', { skip: isNode24OrGreater }, (t, done) => {
|
|
81
|
+
const fastify = Fastify({
|
|
82
|
+
http2: true,
|
|
83
|
+
return503OnClosing: false
|
|
84
|
+
})
|
|
67
85
|
|
|
68
86
|
t.after(() => { fastify.close() })
|
|
69
87
|
|