fastify 5.3.3 â 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 +15 -15
- package/LICENSE +1 -1
- package/README.md +2 -0
- package/SECURITY.md +158 -2
- package/build/build-validation.js +20 -1
- package/docs/Guides/Delay-Accepting-Requests.md +8 -5
- package/docs/Guides/Ecosystem.md +20 -5
- package/docs/Guides/Migration-Guide-V5.md +6 -10
- package/docs/Guides/Recommendations.md +1 -1
- package/docs/Reference/ContentTypeParser.md +1 -1
- package/docs/Reference/Errors.md +5 -3
- package/docs/Reference/Hooks.md +16 -20
- package/docs/Reference/Lifecycle.md +2 -2
- 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 +2 -2
- package/docs/Reference/Routes.md +7 -6
- package/docs/Reference/Server.md +341 -200
- package/docs/Reference/TypeScript.md +1 -3
- package/docs/Reference/Validation-and-Serialization.md +56 -4
- package/docs/Reference/Warnings.md +2 -1
- package/fastify.d.ts +4 -3
- package/fastify.js +47 -34
- package/lib/configValidator.js +196 -28
- package/lib/contentTypeParser.js +41 -48
- package/lib/error-handler.js +3 -3
- package/lib/errors.js +11 -0
- package/lib/handleRequest.js +13 -17
- package/lib/pluginOverride.js +3 -1
- package/lib/promise.js +23 -0
- package/lib/reply.js +24 -30
- package/lib/request.js +3 -10
- package/lib/route.js +37 -3
- package/lib/server.js +36 -35
- package/lib/symbols.js +1 -0
- package/lib/warnings.js +19 -1
- package/package.json +14 -10
- 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 +84 -128
- package/test/async_hooks.test.js +18 -37
- package/test/body-limit.test.js +90 -63
- package/test/buffer.test.js +22 -0
- package/test/build-certificate.js +1 -1
- 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-async.test.js +17 -22
- 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-namespace.test._js_ +3 -4
- 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-delay-request.test.js +7 -16
- 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-delay-request.test.js +7 -16
- 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 +139 -135
- package/test/hooks-async.test.js +259 -235
- package/test/hooks.test.js +951 -996
- 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/lock.test.js +31 -31
- package/test/http-methods/mkcalendar.test.js +45 -72
- package/test/http-methods/mkcol.test.js +5 -9
- package/test/http-methods/move.test.js +6 -10
- package/test/http-methods/propfind.test.js +34 -44
- 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/http-methods/unlock.test.js +5 -9
- package/test/http2/closing.test.js +38 -20
- package/test/http2/secure-with-fallback.test.js +31 -28
- package/test/https/custom-https-server.test.js +9 -13
- package/test/https/https.test.js +56 -53
- package/test/input-validation.js +139 -150
- package/test/internals/errors.test.js +50 -1
- package/test/internals/handle-request.test.js +72 -65
- package/test/internals/promise.test.js +63 -0
- package/test/internals/reply.test.js +277 -496
- package/test/issue-4959.test.js +12 -3
- package/test/listen.4.test.js +31 -43
- package/test/nullable-validation.test.js +33 -46
- package/test/output-validation.test.js +24 -26
- package/test/plugin.1.test.js +40 -68
- package/test/plugin.2.test.js +108 -120
- package/test/plugin.3.test.js +50 -72
- package/test/plugin.4.test.js +124 -119
- package/test/promises.test.js +42 -63
- package/test/proto-poisoning.test.js +78 -97
- package/test/register.test.js +8 -18
- package/test/request-error.test.js +57 -146
- package/test/request-id.test.js +30 -49
- package/test/route-hooks.test.js +117 -101
- package/test/route-prefix.test.js +194 -133
- 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-serialization.test.js +177 -154
- package/test/schema-special-usage.test.js +165 -132
- package/test/schema-validation.test.js +254 -218
- package/test/server.test.js +143 -5
- package/test/set-error-handler.test.js +58 -1
- package/test/skip-reply-send.test.js +64 -69
- 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/trust-proxy.test.js +32 -58
- package/test/types/errors.test-d.ts +13 -1
- package/test/types/fastify.test-d.ts +3 -0
- package/test/types/request.test-d.ts +1 -0
- package/test/types/type-provider.test-d.ts +55 -0
- package/test/url-rewriting.test.js +45 -62
- 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
- package/types/request.d.ts +1 -0
- package/.taprc +0 -7
package/docs/Reference/Reply.md
CHANGED
|
@@ -151,7 +151,7 @@ fastify.get('/', async function (req, rep) {
|
|
|
151
151
|
Sets a response header. If the value is omitted or undefined, it is coerced to
|
|
152
152
|
`''`.
|
|
153
153
|
|
|
154
|
-
>
|
|
154
|
+
> âšī¸ Note: The header's value must be properly encoded using
|
|
155
155
|
> [`encodeURI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
|
|
156
156
|
> or similar modules such as
|
|
157
157
|
> [`encodeurl`](https://www.npmjs.com/package/encodeurl). Invalid characters
|
|
@@ -260,10 +260,10 @@ requires heavy resources to be sent after the `data`, for example,
|
|
|
260
260
|
`Server-Timing` and `Etag`. It can ensure the client receives the response data
|
|
261
261
|
as soon as possible.
|
|
262
262
|
|
|
263
|
-
>
|
|
263
|
+
> âšī¸ Note: The header `Transfer-Encoding: chunked` will be added once you use
|
|
264
264
|
> the trailer. It is a hard requirement for using trailer in Node.js.
|
|
265
265
|
|
|
266
|
-
>
|
|
266
|
+
> âšī¸ Note: Any error passed to `done` callback will be ignored. If you interested
|
|
267
267
|
> in the error, you can turn on `debug` level logging.*
|
|
268
268
|
|
|
269
269
|
```js
|
|
@@ -279,14 +279,14 @@ const { createHash } = require('node:crypto')
|
|
|
279
279
|
reply.trailer('content-md5', function(reply, payload, done) {
|
|
280
280
|
const hash = createHash('md5')
|
|
281
281
|
hash.update(payload)
|
|
282
|
-
done(null, hash.
|
|
282
|
+
done(null, hash.digest('hex'))
|
|
283
283
|
})
|
|
284
284
|
|
|
285
285
|
// when you prefer async-await
|
|
286
286
|
reply.trailer('content-md5', async function(reply, payload) {
|
|
287
287
|
const hash = createHash('md5')
|
|
288
288
|
hash.update(payload)
|
|
289
|
-
return hash.
|
|
289
|
+
return hash.digest('hex')
|
|
290
290
|
})
|
|
291
291
|
```
|
|
292
292
|
|
|
@@ -314,7 +314,7 @@ reply.getTrailer('server-timing') // undefined
|
|
|
314
314
|
Redirects a request to the specified URL, the status code is optional, default
|
|
315
315
|
to `302` (if status code is not already set by calling `code`).
|
|
316
316
|
|
|
317
|
-
>
|
|
317
|
+
> âšī¸ Note: The input URL must be properly encoded using
|
|
318
318
|
> [`encodeURI`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI)
|
|
319
319
|
> or similar modules such as
|
|
320
320
|
> [`encodeurl`](https://www.npmjs.com/package/encodeurl). Invalid URLs will
|
|
@@ -823,7 +823,7 @@ automatically create an error structured as the following:
|
|
|
823
823
|
You can add custom properties to the Error object, such as `headers`, that will
|
|
824
824
|
be used to enhance the HTTP response.
|
|
825
825
|
|
|
826
|
-
>
|
|
826
|
+
> âšī¸ Note: If you are passing an error to `send` and the statusCode is less than
|
|
827
827
|
> 400, Fastify will automatically set it at 500.
|
|
828
828
|
|
|
829
829
|
Tip: you can simplify errors by using the
|
|
@@ -871,7 +871,7 @@ fastify.get('/', {
|
|
|
871
871
|
If you want to customize error handling, check out
|
|
872
872
|
[`setErrorHandler`](./Server.md#seterrorhandler) API.
|
|
873
873
|
|
|
874
|
-
>
|
|
874
|
+
> âšī¸ Note: you are responsible for logging when customizing the error handler.
|
|
875
875
|
|
|
876
876
|
API:
|
|
877
877
|
|
|
@@ -84,7 +84,7 @@ This operation adds new values to the request headers, accessible via
|
|
|
84
84
|
For performance reasons, `Symbol('fastify.RequestAcceptVersion')` may be added
|
|
85
85
|
to headers on `not found` routes.
|
|
86
86
|
|
|
87
|
-
>
|
|
87
|
+
> âšī¸ Note: Schema validation may mutate the `request.headers` and
|
|
88
88
|
> `request.raw.headers` objects, causing the headers to become empty.
|
|
89
89
|
|
|
90
90
|
```js
|
|
@@ -237,7 +237,7 @@ const newValidate = request.compileValidationSchema(newSchema)
|
|
|
237
237
|
console.log(newValidate === validate) // false
|
|
238
238
|
```
|
|
239
239
|
|
|
240
|
-
### .validateInput(data, [schema |
|
|
240
|
+
### .validateInput(data, [schema | httpPart], [httpPart])
|
|
241
241
|
<a id="validate"></a>
|
|
242
242
|
|
|
243
243
|
This function validates the input based on the provided schema or HTTP part. If
|
package/docs/Reference/Routes.md
CHANGED
|
@@ -59,8 +59,9 @@ fastify.route(options)
|
|
|
59
59
|
one.
|
|
60
60
|
* `onRequest(request, reply, done)`: a [function](./Hooks.md#onrequest) called
|
|
61
61
|
as soon as a request is received, it could also be an array of functions.
|
|
62
|
-
* `preParsing(request, reply, done)`: a
|
|
63
|
-
before parsing the request, it could
|
|
62
|
+
* `preParsing(request, reply, payload, done)`: a
|
|
63
|
+
[function](./Hooks.md#preparsing) called before parsing the request, it could
|
|
64
|
+
also be an array of functions.
|
|
64
65
|
* `preValidation(request, reply, done)`: a [function](./Hooks.md#prevalidation)
|
|
65
66
|
called after the shared `preValidation` hooks, useful if you need to perform
|
|
66
67
|
authentication at route level for example, it could also be an array of
|
|
@@ -137,7 +138,7 @@ fastify.route(options)
|
|
|
137
138
|
|
|
138
139
|
* `reply` is defined in [Reply](./Reply.md).
|
|
139
140
|
|
|
140
|
-
>
|
|
141
|
+
> âšī¸ Note: The documentation for `onRequest`, `preParsing`, `preValidation`,
|
|
141
142
|
> `preHandler`, `preSerialization`, `onSend`, and `onResponse` is detailed in
|
|
142
143
|
> [Hooks](./Hooks.md). To send a response before the request is handled by the
|
|
143
144
|
> `handler`, see [Respond to a request from
|
|
@@ -233,7 +234,7 @@ const opts = {
|
|
|
233
234
|
fastify.get('/', opts)
|
|
234
235
|
```
|
|
235
236
|
|
|
236
|
-
>
|
|
237
|
+
> âšī¸ Note: Specifying the handler in both `options` and as the third parameter to
|
|
237
238
|
> the shortcut method throws a duplicate `handler` error.
|
|
238
239
|
|
|
239
240
|
### Url building
|
|
@@ -402,7 +403,7 @@ This approach supports both `callback-style` and `async-await` with minimal
|
|
|
402
403
|
trade-off. However, it is recommended to use only one style for consistent
|
|
403
404
|
error handling within your application.
|
|
404
405
|
|
|
405
|
-
>
|
|
406
|
+
> âšī¸ Note: Every async function returns a promise by itself.
|
|
406
407
|
|
|
407
408
|
### Route Prefixing
|
|
408
409
|
<a id="route-prefixing"></a>
|
|
@@ -781,7 +782,7 @@ const secret = {
|
|
|
781
782
|
> const Fastify = require('fastify')
|
|
782
783
|
>
|
|
783
784
|
> const fastify = Fastify({
|
|
784
|
-
> frameworkErrors: function (err,
|
|
785
|
+
> frameworkErrors: function (err, req, res) {
|
|
785
786
|
> if (err instanceof Fastify.errorCodes.FST_ERR_ASYNC_CONSTRAINT) {
|
|
786
787
|
> res.code(400)
|
|
787
788
|
> return res.send("Invalid header provided")
|