fastify 5.4.0 → 5.5.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/.vscode/settings.json +22 -0
- package/LICENSE +1 -1
- package/SECURITY.md +158 -2
- package/build/build-validation.js +19 -1
- package/docs/Guides/Delay-Accepting-Requests.md +8 -5
- package/docs/Guides/Ecosystem.md +11 -0
- package/docs/Guides/Migration-Guide-V5.md +6 -10
- package/docs/Guides/Recommendations.md +1 -1
- package/docs/Reference/Errors.md +3 -1
- package/docs/Reference/Hooks.md +2 -6
- package/docs/Reference/Lifecycle.md +2 -2
- package/docs/Reference/Request.md +1 -1
- package/docs/Reference/Routes.md +4 -3
- package/docs/Reference/Server.md +306 -179
- package/docs/Reference/TypeScript.md +1 -3
- package/docs/Reference/Validation-and-Serialization.md +55 -3
- package/docs/Reference/Warnings.md +2 -1
- package/fastify.d.ts +2 -2
- package/fastify.js +34 -33
- package/lib/configValidator.js +196 -28
- package/lib/contentTypeParser.js +41 -48
- package/lib/error-handler.js +3 -3
- package/lib/errors.js +5 -0
- package/lib/handleRequest.js +13 -17
- package/lib/promise.js +23 -0
- package/lib/reply.js +17 -19
- package/lib/route.js +37 -3
- package/lib/server.js +36 -35
- package/lib/warnings.js +11 -1
- package/package.json +7 -7
- package/test/async-await.test.js +81 -134
- package/test/async_hooks.test.js +18 -37
- package/test/body-limit.test.js +51 -0
- package/test/buffer.test.js +22 -0
- package/test/case-insensitive.test.js +44 -65
- package/test/check.test.js +17 -21
- package/test/close-pipelining.test.js +24 -15
- package/test/constrained-routes.test.js +231 -0
- package/test/custom-http-server.test.js +7 -15
- package/test/custom-parser.0.test.js +267 -348
- package/test/custom-parser.1.test.js +141 -191
- package/test/custom-parser.2.test.js +34 -44
- package/test/custom-parser.3.test.js +56 -104
- package/test/custom-parser.4.test.js +106 -144
- package/test/custom-parser.5.test.js +56 -75
- package/test/custom-querystring-parser.test.js +51 -77
- package/test/decorator.test.js +76 -259
- package/test/delete.test.js +101 -110
- package/test/diagnostics-channel/404.test.js +7 -15
- package/test/diagnostics-channel/async-request.test.js +8 -16
- package/test/diagnostics-channel/error-request.test.js +7 -15
- package/test/diagnostics-channel/sync-request-reply.test.js +9 -16
- package/test/diagnostics-channel/sync-request.test.js +9 -16
- package/test/fastify-instance.test.js +1 -1
- package/test/header-overflow.test.js +18 -29
- package/test/helper.js +138 -134
- package/test/hooks-async.test.js +26 -32
- package/test/hooks.test.js +261 -447
- package/test/http-methods/copy.test.js +14 -19
- package/test/http-methods/get.test.js +131 -143
- package/test/http-methods/head.test.js +53 -84
- package/test/http-methods/mkcalendar.test.js +45 -72
- package/test/http-methods/move.test.js +6 -10
- package/test/http-methods/propfind.test.js +34 -44
- package/test/http-methods/unlock.test.js +5 -9
- package/test/http2/secure-with-fallback.test.js +3 -1
- package/test/https/custom-https-server.test.js +9 -13
- package/test/input-validation.js +139 -150
- package/test/internals/errors.test.js +50 -1
- package/test/internals/handle-request.test.js +29 -5
- package/test/internals/promise.test.js +63 -0
- package/test/internals/reply.test.js +277 -496
- package/test/plugin.1.test.js +40 -68
- package/test/plugin.2.test.js +40 -70
- package/test/plugin.3.test.js +25 -68
- package/test/promises.test.js +42 -63
- package/test/register.test.js +8 -18
- package/test/request-error.test.js +57 -100
- package/test/request-id.test.js +30 -49
- package/test/route-hooks.test.js +12 -16
- package/test/route-shorthand.test.js +9 -27
- package/test/route.1.test.js +74 -131
- package/test/route.8.test.js +9 -17
- package/test/router-options.test.js +450 -0
- package/test/schema-validation.test.js +30 -31
- package/test/server.test.js +143 -5
- package/test/stream.1.test.js +33 -50
- package/test/stream.4.test.js +18 -28
- package/test/stream.5.test.js +11 -19
- package/test/types/errors.test-d.ts +13 -1
- package/test/types/type-provider.test-d.ts +55 -0
- package/test/use-semicolon-delimiter.test.js +117 -59
- package/test/versioned-routes.test.js +39 -56
- package/types/errors.d.ts +11 -1
- package/types/hooks.d.ts +1 -1
- package/types/instance.d.ts +1 -1
- package/types/reply.d.ts +2 -2
|
@@ -1,72 +1,61 @@
|
|
|
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
|
const jsonParser = require('fast-json-body')
|
|
7
|
-
const { getServerUrl } = require('./helper')
|
|
8
|
-
const { waitForCb } = require('./toolkit')
|
|
9
6
|
|
|
10
7
|
process.removeAllListeners('warning')
|
|
11
8
|
|
|
12
|
-
test('Should have typeof body object with no custom parser defined, null body and content type = \'text/plain\'', (t
|
|
13
|
-
t.plan(
|
|
9
|
+
test('Should have typeof body object with no custom parser defined, null body and content type = \'text/plain\'', async (t) => {
|
|
10
|
+
t.plan(3)
|
|
14
11
|
const fastify = Fastify()
|
|
15
12
|
|
|
16
13
|
fastify.post('/', (req, reply) => {
|
|
17
14
|
reply.send(req.body)
|
|
18
15
|
})
|
|
19
16
|
|
|
20
|
-
fastify.listen({ port: 0 }
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
}, (err, response, body) => {
|
|
31
|
-
t.assert.ifError(err)
|
|
32
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
33
|
-
t.assert.strictEqual(typeof body, 'object')
|
|
34
|
-
fastify.close()
|
|
35
|
-
testDone()
|
|
36
|
-
})
|
|
17
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
18
|
+
t.after(() => fastify.close())
|
|
19
|
+
|
|
20
|
+
const result = await fetch(fastifyServer, {
|
|
21
|
+
method: 'POST',
|
|
22
|
+
body: null,
|
|
23
|
+
headers: {
|
|
24
|
+
'Content-Type': 'text/plain'
|
|
25
|
+
}
|
|
37
26
|
})
|
|
27
|
+
|
|
28
|
+
t.assert.ok(result.ok)
|
|
29
|
+
t.assert.strictEqual(result.status, 200)
|
|
30
|
+
t.assert.strictEqual(await result.text(), '')
|
|
38
31
|
})
|
|
39
32
|
|
|
40
|
-
test('Should have typeof body object with no custom parser defined, undefined body and content type = \'text/plain\'', (t
|
|
41
|
-
t.plan(
|
|
33
|
+
test('Should have typeof body object with no custom parser defined, undefined body and content type = \'text/plain\'', async (t) => {
|
|
34
|
+
t.plan(3)
|
|
42
35
|
const fastify = Fastify()
|
|
43
36
|
|
|
44
37
|
fastify.post('/', (req, reply) => {
|
|
45
38
|
reply.send(req.body)
|
|
46
39
|
})
|
|
47
40
|
|
|
48
|
-
fastify.listen({ port: 0 }
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
}, (err, response, body) => {
|
|
59
|
-
t.assert.ifError(err)
|
|
60
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
61
|
-
t.assert.strictEqual(typeof body, 'object')
|
|
62
|
-
fastify.close()
|
|
63
|
-
testDone()
|
|
64
|
-
})
|
|
41
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
42
|
+
t.after(() => fastify.close())
|
|
43
|
+
|
|
44
|
+
const result = await fetch(fastifyServer, {
|
|
45
|
+
method: 'POST',
|
|
46
|
+
body: undefined,
|
|
47
|
+
headers: {
|
|
48
|
+
'Content-Type': 'text/plain'
|
|
49
|
+
}
|
|
65
50
|
})
|
|
51
|
+
|
|
52
|
+
t.assert.ok(result.ok)
|
|
53
|
+
t.assert.strictEqual(result.status, 200)
|
|
54
|
+
t.assert.strictEqual(await result.text(), '')
|
|
66
55
|
})
|
|
67
56
|
|
|
68
|
-
test('Should get the body as string /1', (t
|
|
69
|
-
t.plan(
|
|
57
|
+
test('Should get the body as string /1', async (t) => {
|
|
58
|
+
t.plan(4)
|
|
70
59
|
const fastify = Fastify()
|
|
71
60
|
|
|
72
61
|
fastify.post('/', (req, reply) => {
|
|
@@ -85,28 +74,23 @@ test('Should get the body as string /1', (t, testDone) => {
|
|
|
85
74
|
}
|
|
86
75
|
})
|
|
87
76
|
|
|
88
|
-
fastify.listen({ port: 0 }
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
}, (err, response, body) => {
|
|
99
|
-
t.assert.ifError(err)
|
|
100
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
101
|
-
t.assert.strictEqual(body.toString(), 'hello world')
|
|
102
|
-
fastify.close()
|
|
103
|
-
testDone()
|
|
104
|
-
})
|
|
77
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
78
|
+
t.after(() => fastify.close())
|
|
79
|
+
|
|
80
|
+
const result = await fetch(fastifyServer, {
|
|
81
|
+
method: 'POST',
|
|
82
|
+
body: 'hello world',
|
|
83
|
+
headers: {
|
|
84
|
+
'Content-Type': 'text/plain'
|
|
85
|
+
}
|
|
105
86
|
})
|
|
87
|
+
|
|
88
|
+
t.assert.strictEqual(result.status, 200)
|
|
89
|
+
t.assert.strictEqual(await result.text(), 'hello world')
|
|
106
90
|
})
|
|
107
91
|
|
|
108
|
-
test('Should get the body as string /2', (t
|
|
109
|
-
t.plan(
|
|
92
|
+
test('Should get the body as string /2', async (t) => {
|
|
93
|
+
t.plan(4)
|
|
110
94
|
const fastify = Fastify()
|
|
111
95
|
|
|
112
96
|
fastify.post('/', (req, reply) => {
|
|
@@ -125,28 +109,23 @@ test('Should get the body as string /2', (t, testDone) => {
|
|
|
125
109
|
}
|
|
126
110
|
})
|
|
127
111
|
|
|
128
|
-
fastify.listen({ port: 0 }
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
}, (err, response, body) => {
|
|
139
|
-
t.assert.ifError(err)
|
|
140
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
141
|
-
t.assert.strictEqual(body.toString(), 'hello world')
|
|
142
|
-
fastify.close()
|
|
143
|
-
testDone()
|
|
144
|
-
})
|
|
112
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
113
|
+
t.after(() => fastify.close())
|
|
114
|
+
|
|
115
|
+
const result = await fetch(fastifyServer, {
|
|
116
|
+
method: 'POST',
|
|
117
|
+
body: 'hello world',
|
|
118
|
+
headers: {
|
|
119
|
+
'Content-Type': ' text/plain/test '
|
|
120
|
+
}
|
|
145
121
|
})
|
|
122
|
+
|
|
123
|
+
t.assert.strictEqual(result.status, 200)
|
|
124
|
+
t.assert.strictEqual(await result.text(), 'hello world')
|
|
146
125
|
})
|
|
147
126
|
|
|
148
|
-
test('Should get the body as buffer', (t
|
|
149
|
-
t.plan(
|
|
127
|
+
test('Should get the body as buffer', async (t) => {
|
|
128
|
+
t.plan(4)
|
|
150
129
|
const fastify = Fastify()
|
|
151
130
|
|
|
152
131
|
fastify.post('/', (req, reply) => {
|
|
@@ -165,28 +144,23 @@ test('Should get the body as buffer', (t, testDone) => {
|
|
|
165
144
|
}
|
|
166
145
|
})
|
|
167
146
|
|
|
168
|
-
fastify.listen({ port: 0 }
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
}, (err, response, body) => {
|
|
179
|
-
t.assert.ifError(err)
|
|
180
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
181
|
-
t.assert.strictEqual(body.toString(), '{"hello":"world"}')
|
|
182
|
-
fastify.close()
|
|
183
|
-
testDone()
|
|
184
|
-
})
|
|
147
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
148
|
+
t.after(() => fastify.close())
|
|
149
|
+
|
|
150
|
+
const result = await fetch(fastifyServer, {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
body: '{"hello":"world"}',
|
|
153
|
+
headers: {
|
|
154
|
+
'Content-Type': 'application/json'
|
|
155
|
+
}
|
|
185
156
|
})
|
|
157
|
+
|
|
158
|
+
t.assert.strictEqual(result.status, 200)
|
|
159
|
+
t.assert.strictEqual(await result.text(), '{"hello":"world"}')
|
|
186
160
|
})
|
|
187
161
|
|
|
188
|
-
test('Should get the body as buffer', (t
|
|
189
|
-
t.plan(
|
|
162
|
+
test('Should get the body as buffer', async (t) => {
|
|
163
|
+
t.plan(4)
|
|
190
164
|
const fastify = Fastify()
|
|
191
165
|
|
|
192
166
|
fastify.post('/', (req, reply) => {
|
|
@@ -205,28 +179,23 @@ test('Should get the body as buffer', (t, testDone) => {
|
|
|
205
179
|
}
|
|
206
180
|
})
|
|
207
181
|
|
|
208
|
-
fastify.listen({ port: 0 }
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
}, (err, response, body) => {
|
|
219
|
-
t.assert.ifError(err)
|
|
220
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
221
|
-
t.assert.strictEqual(body.toString(), 'hello world')
|
|
222
|
-
fastify.close()
|
|
223
|
-
testDone()
|
|
224
|
-
})
|
|
182
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
183
|
+
t.after(() => fastify.close())
|
|
184
|
+
|
|
185
|
+
const result = await fetch(fastifyServer, {
|
|
186
|
+
method: 'POST',
|
|
187
|
+
body: 'hello world',
|
|
188
|
+
headers: {
|
|
189
|
+
'Content-Type': 'text/plain'
|
|
190
|
+
}
|
|
225
191
|
})
|
|
192
|
+
|
|
193
|
+
t.assert.strictEqual(result.status, 200)
|
|
194
|
+
t.assert.strictEqual(await result.text(), 'hello world')
|
|
226
195
|
})
|
|
227
196
|
|
|
228
|
-
test('Should parse empty bodies as a string', (t) => {
|
|
229
|
-
t.plan(
|
|
197
|
+
test('Should parse empty bodies as a string', async (t) => {
|
|
198
|
+
t.plan(8)
|
|
230
199
|
const fastify = Fastify()
|
|
231
200
|
|
|
232
201
|
fastify.addContentTypeParser('text/plain', { parseAs: 'string' }, (req, body, done) => {
|
|
@@ -242,47 +211,37 @@ test('Should parse empty bodies as a string', (t) => {
|
|
|
242
211
|
}
|
|
243
212
|
})
|
|
244
213
|
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
fastify.listen({ port: 0 }, err => {
|
|
248
|
-
t.assert.ifError(err)
|
|
249
|
-
t.after(() => { fastify.close() })
|
|
250
|
-
|
|
251
|
-
sget({
|
|
252
|
-
method: 'POST',
|
|
253
|
-
url: getServerUrl(fastify),
|
|
254
|
-
body: '',
|
|
255
|
-
headers: {
|
|
256
|
-
'Content-Type': 'text/plain'
|
|
257
|
-
}
|
|
258
|
-
}, (err, response, body) => {
|
|
259
|
-
t.assert.ifError(err)
|
|
260
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
261
|
-
t.assert.strictEqual(body.toString(), '')
|
|
262
|
-
completion.stepIn()
|
|
263
|
-
})
|
|
214
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
215
|
+
t.after(() => fastify.close())
|
|
264
216
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
'Content-Length': '0'
|
|
272
|
-
}
|
|
273
|
-
}, (err, response, body) => {
|
|
274
|
-
t.assert.ifError(err)
|
|
275
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
276
|
-
t.assert.strictEqual(body.toString(), '')
|
|
277
|
-
completion.stepIn()
|
|
278
|
-
})
|
|
217
|
+
const postResult = await fetch(fastifyServer, {
|
|
218
|
+
method: 'POST',
|
|
219
|
+
body: '',
|
|
220
|
+
headers: {
|
|
221
|
+
'Content-Type': 'text/plain'
|
|
222
|
+
}
|
|
279
223
|
})
|
|
280
224
|
|
|
281
|
-
|
|
225
|
+
t.assert.ok(postResult.ok)
|
|
226
|
+
t.assert.strictEqual(postResult.status, 200)
|
|
227
|
+
t.assert.strictEqual(await postResult.text(), '')
|
|
228
|
+
|
|
229
|
+
const deleteResult = await fetch(fastifyServer, {
|
|
230
|
+
method: 'DELETE',
|
|
231
|
+
body: '',
|
|
232
|
+
headers: {
|
|
233
|
+
'Content-Type': 'text/plain',
|
|
234
|
+
'Content-Length': '0'
|
|
235
|
+
}
|
|
236
|
+
})
|
|
237
|
+
|
|
238
|
+
t.assert.ok(deleteResult.ok)
|
|
239
|
+
t.assert.strictEqual(deleteResult.status, 200)
|
|
240
|
+
t.assert.strictEqual(await deleteResult.text(), '')
|
|
282
241
|
})
|
|
283
242
|
|
|
284
|
-
test('Should parse empty bodies as a buffer', (t
|
|
285
|
-
t.plan(
|
|
243
|
+
test('Should parse empty bodies as a buffer', async (t) => {
|
|
244
|
+
t.plan(4)
|
|
286
245
|
const fastify = Fastify()
|
|
287
246
|
|
|
288
247
|
fastify.post('/', (req, reply) => {
|
|
@@ -295,28 +254,23 @@ test('Should parse empty bodies as a buffer', (t, testDone) => {
|
|
|
295
254
|
done(null, body)
|
|
296
255
|
})
|
|
297
256
|
|
|
298
|
-
fastify.listen({ port: 0 }
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
}
|
|
308
|
-
}, (err, response, body) => {
|
|
309
|
-
t.assert.ifError(err)
|
|
310
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
311
|
-
t.assert.strictEqual(body.length, 0)
|
|
312
|
-
fastify.close()
|
|
313
|
-
testDone()
|
|
314
|
-
})
|
|
257
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
258
|
+
t.after(() => fastify.close())
|
|
259
|
+
|
|
260
|
+
const result = await fetch(fastifyServer, {
|
|
261
|
+
method: 'POST',
|
|
262
|
+
body: '',
|
|
263
|
+
headers: {
|
|
264
|
+
'Content-Type': 'text/plain'
|
|
265
|
+
}
|
|
315
266
|
})
|
|
267
|
+
|
|
268
|
+
t.assert.strictEqual(result.status, 200)
|
|
269
|
+
t.assert.strictEqual((await result.arrayBuffer()).byteLength, 0)
|
|
316
270
|
})
|
|
317
271
|
|
|
318
|
-
test('The charset should not interfere with the content type handling', (t
|
|
319
|
-
t.plan(
|
|
272
|
+
test('The charset should not interfere with the content type handling', async (t) => {
|
|
273
|
+
t.plan(4)
|
|
320
274
|
const fastify = Fastify()
|
|
321
275
|
|
|
322
276
|
fastify.post('/', (req, reply) => {
|
|
@@ -330,22 +284,18 @@ test('The charset should not interfere with the content type handling', (t, test
|
|
|
330
284
|
})
|
|
331
285
|
})
|
|
332
286
|
|
|
333
|
-
fastify.listen({ port: 0 }
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
}, (err, response, body) => {
|
|
344
|
-
t.assert.ifError(err)
|
|
345
|
-
t.assert.strictEqual(response.statusCode, 200)
|
|
346
|
-
t.assert.strictEqual(body.toString(), '{"hello":"world"}')
|
|
347
|
-
fastify.close()
|
|
348
|
-
testDone()
|
|
349
|
-
})
|
|
287
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
288
|
+
t.after(() => fastify.close())
|
|
289
|
+
|
|
290
|
+
const result = await fetch(fastifyServer, {
|
|
291
|
+
method: 'POST',
|
|
292
|
+
body: '{"hello":"world"}',
|
|
293
|
+
headers: {
|
|
294
|
+
'Content-Type': 'application/json; charset=utf-8'
|
|
295
|
+
}
|
|
350
296
|
})
|
|
297
|
+
|
|
298
|
+
t.assert.ok(result.ok)
|
|
299
|
+
t.assert.strictEqual(result.status, 200)
|
|
300
|
+
t.assert.strictEqual(await result.text(), '{"hello":"world"}')
|
|
351
301
|
})
|
|
@@ -1,9 +1,7 @@
|
|
|
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
|
-
const { getServerUrl } = require('./helper')
|
|
7
5
|
|
|
8
6
|
process.removeAllListeners('warning')
|
|
9
7
|
|
|
@@ -20,8 +18,8 @@ test('Wrong parseAs parameter', t => {
|
|
|
20
18
|
}
|
|
21
19
|
})
|
|
22
20
|
|
|
23
|
-
test('Should allow defining the bodyLimit per parser', (t
|
|
24
|
-
t.plan(
|
|
21
|
+
test('Should allow defining the bodyLimit per parser', async (t) => {
|
|
22
|
+
t.plan(2)
|
|
25
23
|
const fastify = Fastify()
|
|
26
24
|
t.after(() => fastify.close())
|
|
27
25
|
|
|
@@ -38,31 +36,27 @@ test('Should allow defining the bodyLimit per parser', (t, done) => {
|
|
|
38
36
|
}
|
|
39
37
|
)
|
|
40
38
|
|
|
41
|
-
fastify.listen({ port: 0 }
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
message: 'Request body is too large'
|
|
58
|
-
})
|
|
59
|
-
done()
|
|
60
|
-
})
|
|
39
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
40
|
+
|
|
41
|
+
const result = await fetch(fastifyServer, {
|
|
42
|
+
method: 'POST',
|
|
43
|
+
body: '1234567890',
|
|
44
|
+
headers: {
|
|
45
|
+
'Content-Type': 'x/foo'
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
t.assert.ok(!result.ok)
|
|
50
|
+
t.assert.deepStrictEqual(await result.json(), {
|
|
51
|
+
statusCode: 413,
|
|
52
|
+
code: 'FST_ERR_CTP_BODY_TOO_LARGE',
|
|
53
|
+
error: 'Payload Too Large',
|
|
54
|
+
message: 'Request body is too large'
|
|
61
55
|
})
|
|
62
56
|
})
|
|
63
57
|
|
|
64
|
-
test('route bodyLimit should take precedence over a custom parser bodyLimit', (t
|
|
65
|
-
t.plan(
|
|
58
|
+
test('route bodyLimit should take precedence over a custom parser bodyLimit', async (t) => {
|
|
59
|
+
t.plan(2)
|
|
66
60
|
const fastify = Fastify()
|
|
67
61
|
t.after(() => fastify.close())
|
|
68
62
|
|
|
@@ -79,23 +73,19 @@ test('route bodyLimit should take precedence over a custom parser bodyLimit', (t
|
|
|
79
73
|
}
|
|
80
74
|
)
|
|
81
75
|
|
|
82
|
-
fastify.listen({ port: 0 }
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
message: 'Request body is too large'
|
|
97
|
-
})
|
|
98
|
-
done()
|
|
99
|
-
})
|
|
76
|
+
const fastifyServer = await fastify.listen({ port: 0 })
|
|
77
|
+
|
|
78
|
+
const result = await fetch(fastifyServer, {
|
|
79
|
+
method: 'POST',
|
|
80
|
+
body: '1234567890',
|
|
81
|
+
headers: { 'Content-Type': 'x/foo' }
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
t.assert.ok(!result.ok)
|
|
85
|
+
t.assert.deepStrictEqual(await result.json(), {
|
|
86
|
+
statusCode: 413,
|
|
87
|
+
code: 'FST_ERR_CTP_BODY_TOO_LARGE',
|
|
88
|
+
error: 'Payload Too Large',
|
|
89
|
+
message: 'Request body is too large'
|
|
100
90
|
})
|
|
101
91
|
})
|