fastify 3.28.0 → 3.29.2

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.
@@ -8,105 +8,105 @@ section.
8
8
 
9
9
  #### [Core](#core)
10
10
 
11
- - [`fastify-accepts`](https://github.com/fastify/fastify-accepts) to have
11
+ - [`@fastify/accepts`](https://github.com/fastify/fastify-accepts) to have
12
12
  [accepts](https://www.npmjs.com/package/accepts) in your request object.
13
- - [`fastify-accepts-serializer`](https://github.com/fastify/fastify-accepts-serializer)
13
+ - [`@fastify/accepts-serializer`](https://github.com/fastify/fastify-accepts-serializer)
14
14
  to serialize to output according to `Accept` header.
15
- - [`fastify-auth`](https://github.com/fastify/fastify-auth) Run multiple auth
15
+ - [`@fastify/auth`](https://github.com/fastify/fastify-auth) Run multiple auth
16
16
  functions in Fastify.
17
- - [`fastify-autoload`](https://github.com/fastify/fastify-autoload) Require all
17
+ - [`@fastify/autoload`](https://github.com/fastify/fastify-autoload) Require all
18
18
  plugins in a directory.
19
19
  - [`fastify-awilix`](https://github.com/fastify/fastify-awilix) Dependency
20
20
  injection support for Fastify, based on
21
21
  [awilix](https://github.com/jeffijoe/awilix).
22
- - [`fastify-bankai`](https://github.com/fastify/fastify-bankai)
22
+ - [`@fastify/bankai`](https://github.com/fastify/fastify-bankai)
23
23
  [Bankai](https://github.com/yoshuawuyts/bankai) assets compiler for Fastify.
24
- - [`fastify-basic-auth`](https://github.com/fastify/fastify-basic-auth) Basic
24
+ - [`@fastify/basic-auth`](https://github.com/fastify/fastify-basic-auth) Basic
25
25
  auth plugin for Fastify.
26
- - [`fastify-bearer-auth`](https://github.com/fastify/fastify-bearer-auth) Bearer
26
+ - [`@fastify/bearer-auth`](https://github.com/fastify/fastify-bearer-auth) Bearer
27
27
  auth plugin for Fastify.
28
- - [`fastify-caching`](https://github.com/fastify/fastify-caching) General
28
+ - [`@fastify/caching`](https://github.com/fastify/fastify-caching) General
29
29
  server-side cache and ETag support.
30
- - [`fastify-circuit-breaker`](https://github.com/fastify/fastify-circuit-breaker)
30
+ - [`@fastify/circuit-breaker`](https://github.com/fastify/fastify-circuit-breaker)
31
31
  A low overhead circuit breaker for your routes.
32
- - [`fastify-compress`](https://github.com/fastify/fastify-compress) Fastify
32
+ - [`@fastify/compress`](https://github.com/fastify/fastify-compress) Fastify
33
33
  compression utils.
34
- - [`fastify-cookie`](https://github.com/fastify/fastify-cookie) Parse and set
34
+ - [`@fastify/cookie`](https://github.com/fastify/fastify-cookie) Parse and set
35
35
  cookie headers.
36
- - [`fastify-cors`](https://github.com/fastify/fastify-cors) Enables the use of
36
+ - [`@fastify/cors`](https://github.com/fastify/fastify-cors) Enables the use of
37
37
  CORS in a Fastify application.
38
38
  - [`fastify-csrf`](https://github.com/fastify/fastify-csrf) A plugin for adding
39
39
  [CSRF](https://en.wikipedia.org/wiki/Cross-site_request_forgery) protection to
40
40
  Fastify.
41
- - [`fastify-diagnostics-channel`](https://github.com/fastify/fastify-diagnostics-channel)
41
+ - [`@fastify/diagnostics-channel`](https://github.com/fastify/fastify-diagnostics-channel)
42
42
  Plugin to deal with `diagnostics_channel` on Fastify
43
- - [`fastify-elasticsearch`](https://github.com/fastify/fastify-elasticsearch)
43
+ - [`@fastify/elasticsearch`](https://github.com/fastify/fastify-elasticsearch)
44
44
  Plugin to share the same ES client.
45
- - [`fastify-env`](https://github.com/fastify/fastify-env) Load and check
45
+ - [`@fastify/env`](https://github.com/fastify/fastify-env) Load and check
46
46
  configuration.
47
- - [`fastify-etag`](https://github.com/fastify/fastify-etag) Automatically
47
+ - [`@fastify/etag`](https://github.com/fastify/fastify-etag) Automatically
48
48
  generate ETags for HTTP responses.
49
- - [`fastify-flash`](https://github.com/fastify/fastify-flash) Set and get flash
49
+ - [`@fastify/flash`](https://github.com/fastify/fastify-flash) Set and get flash
50
50
  messages using the session.
51
- - [`fastify-formbody`](https://github.com/fastify/fastify-formbody) Plugin to
51
+ - [`@fastify/formbody`](https://github.com/fastify/fastify-formbody) Plugin to
52
52
  parse x-www-form-urlencoded bodies.
53
- - [`fastify-funky`](https://github.com/fastify/fastify-funky) Makes functional
53
+ - [`@fastify/funky`](https://github.com/fastify/fastify-funky) Makes functional
54
54
  programming in Fastify more convenient. Adds support for Fastify routes
55
55
  returning functional structures, such as Either, Task or plain parameterless
56
56
  function.
57
- - [`fastify-helmet`](https://github.com/fastify/fastify-helmet) Important
57
+ - [`@fastify/helmet`](https://github.com/fastify/fastify-helmet) Important
58
58
  security headers for Fastify.
59
- - [`fastify-http-proxy`](https://github.com/fastify/fastify-http-proxy) Proxy
59
+ - [`@fastify/http-proxy`](https://github.com/fastify/fastify-http-proxy) Proxy
60
60
  your HTTP requests to another server, with hooks.
61
- - [`fastify-jwt`](https://github.com/fastify/fastify-jwt) JWT utils for Fastify,
61
+ - [`@fastify/jwt`](https://github.com/fastify/fastify-jwt) JWT utils for Fastify,
62
62
  internally uses [fast-jwt](https://github.com/nearform/fast-jwt).
63
- - [`fastify-leveldb`](https://github.com/fastify/fastify-leveldb) Plugin to
63
+ - [`@fastify/leveldb`](https://github.com/fastify/fastify-leveldb) Plugin to
64
64
  share a common LevelDB connection across Fastify.
65
- - [`fastify-mongodb`](https://github.com/fastify/fastify-mongodb) Fastify
65
+ - [`@fastify/mongodb`](https://github.com/fastify/fastify-mongodb) Fastify
66
66
  MongoDB connection plugin, with which you can share the same MongoDB
67
67
  connection pool across every part of your server.
68
- - [`fastify-multipart`](https://github.com/fastify/fastify-multipart) Multipart
68
+ - [`@fastify/multipart`](https://github.com/fastify/fastify-multipart) Multipart
69
69
  support for Fastify.
70
- - [`fastify-oauth2`](https://github.com/fastify/fastify-oauth2) Wrap around
70
+ - [`@fastify/oauth2`](https://github.com/fastify/fastify-oauth2) Wrap around
71
71
  [`simple-oauth2`](https://github.com/lelylan/simple-oauth2).
72
- - [`fastify-postgres`](https://github.com/fastify/fastify-postgres) Fastify
72
+ - [`@fastify/postgres`](https://github.com/fastify/fastify-postgres) Fastify
73
73
  PostgreSQL connection plugin, with this you can share the same PostgreSQL
74
74
  connection pool in every part of your server.
75
- - [`fastify-rate-limit`](https://github.com/fastify/fastify-rate-limit) A low
75
+ - [`@fastify/rate-limit`](https://github.com/fastify/fastify-rate-limit) A low
76
76
  overhead rate limiter for your routes.
77
- - [`fastify-request-context`](https://github.com/fastify/fastify-request-context)
77
+ - [`@fastify/request-context`](https://github.com/fastify/fastify-request-context)
78
78
  Request-scoped storage, based on
79
79
  [AsyncLocalStorage](https://nodejs.org/api/async_hooks.html#async_hooks_class_asynclocalstorage)
80
80
  (with fallback to [cls-hooked](https://github.com/Jeff-Lewis/cls-hooked)),
81
81
  providing functionality similar to thread-local storages.
82
- - [`fastify-response-validation`](https://github.com/fastify/fastify-response-validation)
82
+ - [`@fastify/response-validation`](https://github.com/fastify/fastify-response-validation)
83
83
  A simple plugin that enables response validation for Fastify.
84
- - [`fastify-nextjs`](https://github.com/fastify/fastify-nextjs) React
84
+ - [`@fastify/nextjs`](https://github.com/fastify/fastify-nextjs) React
85
85
  server-side rendering support for Fastify with
86
86
  [Next](https://github.com/zeit/next.js/).
87
- - [`fastify-redis`](https://github.com/fastify/fastify-redis) Fastify Redis
87
+ - [`@fastify/redis`](https://github.com/fastify/fastify-redis) Fastify Redis
88
88
  connection plugin, with which you can share the same Redis connection across
89
89
  every part of your server.
90
- - [`fastify-reply-from`](https://github.com/fastify/fastify-reply-from) Plugin
90
+ - [`@fastify/reply-from`](https://github.com/fastify/fastify-reply-from) Plugin
91
91
  to forward the current HTTP request to another server.
92
- - [`fastify-routes`](https://github.com/fastify/fastify-routes) Plugin that
92
+ - [`@fastify/routes`](https://github.com/fastify/fastify-routes) Plugin that
93
93
  provides a `Map` of routes.
94
94
  - [`fastify-schedule`](https://github.com/fastify/fastify-schedule) Plugin for
95
95
  scheduling periodic jobs, based on
96
96
  [toad-scheduler](https://github.com/kibertoad/toad-scheduler).
97
- - [`fastify-sensible`](https://github.com/fastify/fastify-sensible) Defaults for
97
+ - [`@fastify/sensible`](https://github.com/fastify/fastify-sensible) Defaults for
98
98
  Fastify that everyone can agree on. It adds some useful decorators such as
99
99
  HTTP errors and assertions, but also more request and reply methods.
100
100
  - [`@fastify/session`](https://github.com/fastify/session) a session plugin for
101
101
  Fastify.
102
- - [`fastify-static`](https://github.com/fastify/fastify-static) Plugin for
102
+ - [`@fastify/static`](https://github.com/fastify/fastify-static) Plugin for
103
103
  serving static files as fast as possible.
104
- - [`fastify-swagger`](https://github.com/fastify/fastify-swagger) Plugin for
104
+ - [`@fastify/swagger`](https://github.com/fastify/fastify-swagger) Plugin for
105
105
  serving Swagger/OpenAPI documentation for Fastify, supporting dynamic
106
106
  generation.
107
- - [`fastify-websocket`](https://github.com/fastify/fastify-websocket) WebSocket
107
+ - [`@fastify/websocket`](https://github.com/fastify/fastify-websocket) WebSocket
108
108
  support for Fastify. Built upon [ws](https://github.com/websockets/ws).
109
- - [`fastify-url-data`](https://github.com/fastify/fastify-url-data) Decorate the
109
+ - [`@fastify/url-data`](https://github.com/fastify/fastify-url-data) Decorate the
110
110
  `Request` object with a method to access raw URL components.
111
111
  - [`middie`](https://github.com/fastify/middie) Middleware engine for Fastify.
112
112
  - [`point-of-view`](https://github.com/fastify/point-of-view) Templates
@@ -195,10 +195,10 @@ Fastify handles this internally, with minimum effort!
195
195
  Let's rewrite the above example with a database connection.
196
196
 
197
197
 
198
- First, install `fastify-plugin` and `fastify-mongodb`:
198
+ First, install `fastify-plugin` and `@fastify/mongodb`:
199
199
 
200
200
  ```
201
- npm i --save fastify-plugin fastify-mongodb
201
+ npm i --save fastify-plugin @fastify/mongodb
202
202
  ```
203
203
 
204
204
  **server.js**
@@ -246,7 +246,7 @@ fastify.listen(3000, function (err, address) {
246
246
  ```js
247
247
  // ESM
248
248
  import fastifyPlugin from 'fastify-plugin'
249
- import fastifyMongo from 'fastify-mongodb'
249
+ import fastifyMongo from '@fastify/mongodb'
250
250
 
251
251
  async function dbConnector (fastify, options) {
252
252
  fastify.register(fastifyMongo, {
@@ -265,7 +265,7 @@ module.exports = fastifyPlugin(dbConnector)
265
265
  const fastifyPlugin = require('fastify-plugin')
266
266
 
267
267
  async function dbConnector (fastify, options) {
268
- fastify.register(require('fastify-mongodb'), {
268
+ fastify.register(require('@fastify/mongodb'), {
269
269
  url: 'mongodb://localhost:27017/test_database'
270
270
  })
271
271
  }
@@ -14,7 +14,7 @@ From Fastify v3, middleware support does not come out-of-the-box with the
14
14
  framework itself.
15
15
 
16
16
  If you use Express middleware in your application, please install and register
17
- the [`fastify-express`](https://github.com/fastify/fastify-express) or
17
+ the [`@fastify/express`](https://github.com/fastify/fastify-express) or
18
18
  [`middie`](https://github.com/fastify/middie) plugin before doing so.
19
19
 
20
20
  **v2:**
@@ -28,7 +28,7 @@ fastify.use(require('cors')());
28
28
 
29
29
  ```js
30
30
  // Using the Express `cors` middleware in Fastify v3.
31
- await fastify.register(require('fastify-express'));
31
+ await fastify.register(require('@fastify/express'));
32
32
  fastify.use(require('cors')());
33
33
  ```
34
34
 
@@ -445,10 +445,10 @@ fastify
445
445
 
446
446
  If your plugin needs to expose custom errors, you can easily generate consistent
447
447
  error objects across your codebase and plugins with the
448
- [`fastify-error`](https://github.com/fastify/fastify-error) module.
448
+ [`@fastify/error`](https://github.com/fastify/fastify-error) module.
449
449
 
450
450
  ```js
451
- const createError = require('fastify-error')
451
+ const createError = require('@fastify/error')
452
452
  const CustomError = createError('ERROR_CODE', 'message')
453
453
  console.log(new CustomError())
454
454
  ```
@@ -477,12 +477,12 @@ section of our documentation!
477
477
  If you want to see some real-world examples, check out:
478
478
  - [`point-of-view`](https://github.com/fastify/point-of-view) Templates
479
479
  rendering (*ejs, pug, handlebars, marko*) plugin support for Fastify.
480
- - [`fastify-mongodb`](https://github.com/fastify/fastify-mongodb) Fastify
480
+ - [`@fastify/mongodb`](https://github.com/fastify/fastify-mongodb) Fastify
481
481
  MongoDB connection plugin, with this you can share the same MongoDB connection
482
482
  pool in every part of your server.
483
- - [`fastify-multipart`](https://github.com/fastify/fastify-multipart) Multipart
483
+ - [`@fastify/multipart`](https://github.com/fastify/fastify-multipart) Multipart
484
484
  support for Fastify
485
- - [`fastify-helmet`](https://github.com/fastify/fastify-helmet) Important
485
+ - [`@fastify/helmet`](https://github.com/fastify/fastify-helmet) Important
486
486
  security headers for Fastify
487
487
 
488
488
 
@@ -33,9 +33,9 @@ unused.
33
33
 
34
34
  If you want to see some good examples on how to document a plugin take a look
35
35
  at:
36
- - [`fastify-caching`](https://github.com/fastify/fastify-caching)
37
- - [`fastify-compress`](https://github.com/fastify/fastify-compress)
38
- - [`fastify-cookie`](https://github.com/fastify/fastify-cookie)
36
+ - [`@fastify/caching`](https://github.com/fastify/fastify-caching)
37
+ - [`@fastify/compress`](https://github.com/fastify/fastify-compress)
38
+ - [`@fastify/cookie`](https://github.com/fastify/fastify-cookie)
39
39
  - [`point-of-view`](https://github.com/fastify/point-of-view)
40
40
  - [`under-pressure`](https://github.com/fastify/under-pressure)
41
41
 
@@ -93,10 +93,10 @@ our documentation!
93
93
  If you want to see some real world examples, check out:
94
94
  - [`point-of-view`](https://github.com/fastify/point-of-view) Templates
95
95
  rendering (*ejs, pug, handlebars, marko*) plugin support for Fastify.
96
- - [`fastify-mongodb`](https://github.com/fastify/fastify-mongodb) Fastify
96
+ - [`@fastify/mongodb`](https://github.com/fastify/fastify-mongodb) Fastify
97
97
  MongoDB connection plugin, with this you can share the same MongoDB connection
98
98
  pool in every part of your server.
99
- - [`fastify-multipart`](https://github.com/fastify/fastify-multipart) Multipart
99
+ - [`@fastify/multipart`](https://github.com/fastify/fastify-multipart) Multipart
100
100
  support for Fastify.
101
- - [`fastify-helmet`](https://github.com/fastify/fastify-helmet) Important
101
+ - [`@fastify/helmet`](https://github.com/fastify/fastify-helmet) Important
102
102
  security headers for Fastify.
@@ -33,7 +33,7 @@ this example into concrete terms, consider a basic scenario of a REST API
33
33
  server that has three routes: the first route (`/one`) requires authentication,
34
34
  the second route (`/two`) does not, and the third route (`/three`) has
35
35
  access to the same context as the second route. Using
36
- [fastify-bearer-auth][bearer] to provide the authentication, the code for this
36
+ [@fastify/bearer-auth][bearer] to provide the authentication, the code for this
37
37
  example is as follows:
38
38
 
39
39
  ```js
@@ -44,7 +44,7 @@ const fastify = require('fastify')()
44
44
  fastify.decorateRequest('answer', 42)
45
45
 
46
46
  fastify.register(async function authenticatedContext (childServer) {
47
- childServer.register(require('fastify-bearer-auth'), { keys: ['abc123'] })
47
+ childServer.register(require('@fastify/bearer-auth'), { keys: ['abc123'] })
48
48
 
49
49
  childServer.route({
50
50
  path: '/one',
@@ -103,7 +103,7 @@ original diagram:
103
103
  1. Each _child context_ (`authenticatedContext`, `publicContext`, and
104
104
  `grandchildContext`) has access to the `answer` request decorator defined in
105
105
  the _root context_.
106
- 2. Only the `authenticatedContext` has access to the `fastify-bearer-auth`
106
+ 2. Only the `authenticatedContext` has access to the `@fastify/bearer-auth`
107
107
  plugin.
108
108
  3. Both the `publicContext` and `grandchildContext` have access to the `foo`
109
109
  request decorator.
@@ -351,7 +351,7 @@ fastify.addHook('preHandler', async (request, reply) => {
351
351
  })
352
352
 
353
353
  fastify.addHook('preHandler', async (request, reply) => {
354
- // the fastify-static plugin will send a file asynchronously,
354
+ // the @fastify/static plugin will send a file asynchronously,
355
355
  // so we should return reply
356
356
  reply.sendFile('myfile')
357
357
  return reply
@@ -4,16 +4,16 @@
4
4
 
5
5
  Starting with Fastify v3.0.0, middleware is not supported out of the box and
6
6
  requires an external plugin such as
7
- [`fastify-express`](https://github.com/fastify/fastify-express) or
7
+ [`@fastify/express`](https://github.com/fastify/fastify-express) or
8
8
  [`middie`](https://github.com/fastify/middie).
9
9
 
10
10
 
11
11
  An example of registering the
12
- [`fastify-express`](https://github.com/fastify/fastify-express) plugin to `use`
12
+ [`@fastify/express`](https://github.com/fastify/fastify-express) plugin to `use`
13
13
  Express middleware:
14
14
 
15
15
  ```js
16
- await fastify.register(require('fastify-express'))
16
+ await fastify.register(require('@fastify/express'))
17
17
  fastify.use(require('cors')())
18
18
  fastify.use(require('dns-prefetch-control')())
19
19
  fastify.use(require('frameguard')())
@@ -70,9 +70,9 @@ fastify.use(['/css', '/js'], serveStatic(path.join(__dirname, '/assets')))
70
70
  ### Alternatives
71
71
 
72
72
  Fastify offers some alternatives to the most commonly used middleware, such as
73
- [`fastify-helmet`](https://github.com/fastify/fastify-helmet) in case of
73
+ [`@fastify/helmet`](https://github.com/fastify/fastify-helmet) in case of
74
74
  [`helmet`](https://github.com/helmetjs/helmet),
75
- [`fastify-cors`](https://github.com/fastify/fastify-cors) for
75
+ [`@fastify/cors`](https://github.com/fastify/fastify-cors) for
76
76
  [`cors`](https://github.com/expressjs/cors), and
77
- [`fastify-static`](https://github.com/fastify/fastify-static) for
77
+ [`@fastify/static`](https://github.com/fastify/fastify-static) for
78
78
  [`serve-static`](https://github.com/expressjs/serve-static).
@@ -483,7 +483,7 @@ be used to enhance the HTTP response.
483
483
 
484
484
  Tip: you can simplify errors by using the
485
485
  [`http-errors`](https://npm.im/http-errors) module or
486
- [`fastify-sensible`](https://github.com/fastify/fastify-sensible) plugin to
486
+ [`@fastify/sensible`](https://github.com/fastify/fastify-sensible) plugin to
487
487
  generate errors:
488
488
 
489
489
  ```js
@@ -604,7 +604,7 @@ newer, automatically adds `.default` property and a named export to the exported
604
604
  plugin. Be sure to `export default` and `export const myPlugin` in your typings
605
605
  to provide the best developer experience. For a complete example you can check
606
606
  out
607
- [fastify-swagger](https://github.com/fastify/fastify-swagger/blob/master/index.d.ts).
607
+ [@fastify/swagger](https://github.com/fastify/fastify-swagger/blob/master/index.d.ts).
608
608
 
609
609
  With those files completed, the plugin is now ready to be consumed by any
610
610
  TypeScript project!
package/fastify.d.ts CHANGED
@@ -9,7 +9,7 @@ import { FastifyLoggerInstance, FastifyLoggerOptions } from './types/logger'
9
9
  import { FastifyInstance } from './types/instance'
10
10
  import { FastifyServerFactory } from './types/serverFactory'
11
11
  import { Options as AjvOptions } from '@fastify/ajv-compiler'
12
- import { FastifyError } from 'fastify-error'
12
+ import { FastifyError } from '@fastify/error'
13
13
  import { FastifyReply } from './types/reply'
14
14
  import { FastifySchemaValidationError } from './types/schema'
15
15
  import { ConstructorAction, ProtoAction } from "./types/content-type-parser";
@@ -163,7 +163,7 @@ export type FastifyServerOptions<
163
163
 
164
164
  type TrustProxyFunction = (address: string, hop: number) => boolean
165
165
 
166
- declare module 'fastify-error' {
166
+ declare module '@fastify/error' {
167
167
  interface FastifyError {
168
168
  validation?: ValidationResult[];
169
169
  }
@@ -188,7 +188,7 @@ export { FastifyContext, FastifyContextConfig } from './types/context'
188
188
  export { RouteHandler, RouteHandlerMethod, RouteOptions, RouteShorthandMethod, RouteShorthandOptions, RouteShorthandOptionsWithHandler } from './types/route'
189
189
  export * from './types/register'
190
190
  export { FastifyBodyParser, FastifyContentTypeParser, AddContentTypeParser, hasContentTypeParser, getDefaultJsonParser, ProtoAction, ConstructorAction } from './types/content-type-parser'
191
- export { FastifyError } from 'fastify-error'
191
+ export { FastifyError } from '@fastify/error'
192
192
  export { FastifySchema, FastifySchemaCompiler } from './types/schema'
193
193
  export { HTTPMethods, RawServerBase, RawRequestDefaultExpression, RawReplyDefaultExpression, RawServerDefault, ContextConfigDefault, RequestBodyDefault, RequestQuerystringDefault, RequestParamsDefault, RequestHeadersDefault } from './types/utils'
194
194
  export * from './types/hooks'
package/fastify.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const VERSION = '3.28.0'
3
+ const VERSION = '3.29.2'
4
4
 
5
5
  const Avvio = require('avvio')
6
6
  const http = require('http')
@@ -584,7 +584,7 @@ function fastify (options) {
584
584
  // https://github.com/nodejs/node/blob/6ca23d7846cb47e84fd344543e394e50938540be/lib/_http_server.js#L666
585
585
 
586
586
  // If the socket is not writable, there is no reason to try to send data.
587
- if (socket.writable && socket.bytesWritten === 0) {
587
+ if (socket.writable) {
588
588
  socket.write(`HTTP/1.1 400 Bad Request\r\nContent-Length: ${body.length}\r\nContent-Type: application/json\r\n\r\n${body}`)
589
589
  }
590
590
  socket.destroy(err)
package/lib/errors.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict'
2
2
 
3
- const createError = require('fastify-error')
3
+ const createError = require('@fastify/error')
4
4
  const codes = {
5
5
  /**
6
6
  * Basic
package/lib/reply.js CHANGED
@@ -545,7 +545,7 @@ function sendStream (payload, res, reply) {
545
545
  eos(payload, { readable: true, writable: false }, function (err) {
546
546
  sourceOpen = false
547
547
  if (err != null) {
548
- if (res.headersSent) {
548
+ if (res.headersSent || reply.request.raw.aborted === true) {
549
549
  if (!errorLogged) {
550
550
  errorLogged = true
551
551
  logStreamError(reply.log, err, res)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fastify",
3
- "version": "3.28.0",
3
+ "version": "3.29.2",
4
4
  "description": "Fast and low overhead web framework, for Node.js",
5
5
  "main": "fastify.js",
6
6
  "type": "commonjs",
@@ -127,9 +127,8 @@
127
127
  "@sinonjs/fake-timers": "^9.1.0",
128
128
  "@types/node": "^16.0.0",
129
129
  "@types/pino": "^6.0.1",
130
- "@typescript-eslint/eslint-plugin": "^5.0.0",
131
- "@typescript-eslint/parser": "^5.0.0",
132
- "JSONStream": "^1.3.5",
130
+ "@typescript-eslint/eslint-plugin": "^5.21.0",
131
+ "@typescript-eslint/parser": "^5.21.0",
133
132
  "ajv": "^6.0.0",
134
133
  "ajv-errors": "^1.0.1",
135
134
  "ajv-formats": "^2.1.1",
@@ -140,11 +139,11 @@
140
139
  "cors": "^2.8.5",
141
140
  "coveralls": "^3.1.0",
142
141
  "dns-prefetch-control": "^0.3.0",
143
- "eslint": "^8.0.1",
142
+ "eslint": "^8.14.0",
144
143
  "eslint-config-standard": "^17.0.0-1",
145
- "eslint-import-resolver-node": "^0.3.2",
146
- "eslint-plugin-import": "^2.25.4",
147
- "eslint-plugin-n": "^14.0.0",
144
+ "eslint-import-resolver-node": "^0.3.6",
145
+ "eslint-plugin-import": "^2.26.0",
146
+ "eslint-plugin-n": "^15.2.0",
148
147
  "eslint-plugin-promise": "^6.0.0",
149
148
  "fast-json-body": "^1.1.0",
150
149
  "fastify-plugin": "^3.0.0",
@@ -157,6 +156,7 @@
157
156
  "hsts": "^2.2.0",
158
157
  "http-errors": "^2.0.0",
159
158
  "ienoopen": "^1.1.0",
159
+ "JSONStream": "^1.3.5",
160
160
  "license-checker": "^25.0.1",
161
161
  "pem": "^1.14.4",
162
162
  "proxyquire": "^2.1.3",
@@ -166,7 +166,7 @@
166
166
  "simple-get": "^4.0.0",
167
167
  "snazzy": "^9.0.0",
168
168
  "split2": "^4.1.0",
169
- "standard": "^17.0.0-2",
169
+ "standard": "^17.0.0",
170
170
  "tap": "^15.1.1",
171
171
  "tap-mocha-reporter": "^5.0.1",
172
172
  "then-sleep": "^1.0.1",
@@ -178,15 +178,15 @@
178
178
  },
179
179
  "dependencies": {
180
180
  "@fastify/ajv-compiler": "^1.0.0",
181
+ "@fastify/error": "^2.0.0",
181
182
  "abstract-logging": "^2.0.0",
182
183
  "avvio": "^7.1.2",
183
184
  "fast-json-stringify": "^2.5.2",
184
- "fastify-error": "^0.3.0",
185
- "process-warning": "^1.0.0",
186
185
  "find-my-way": "^4.5.0",
187
186
  "flatstr": "^1.0.12",
188
187
  "light-my-request": "^4.2.0",
189
188
  "pino": "^6.13.0",
189
+ "process-warning": "^1.0.0",
190
190
  "proxy-addr": "^2.0.7",
191
191
  "rfdc": "^1.1.4",
192
192
  "secure-json-parse": "^2.0.0",
@@ -2,6 +2,7 @@
2
2
 
3
3
  const { connect } = require('net')
4
4
  const t = require('tap')
5
+ const semver = require('semver')
5
6
  const test = t.test
6
7
  const Fastify = require('..')
7
8
  const { kRequest } = require('../lib/symbols.js')
@@ -153,7 +154,7 @@ test('default clientError handler ignores sockets in destroyed state', t => {
153
154
  })
154
155
 
155
156
  test('default clientError handler destroys sockets in writable state', t => {
156
- t.plan(1)
157
+ t.plan(2)
157
158
 
158
159
  const fastify = Fastify({
159
160
  bodyLimit: 1,
@@ -169,6 +170,9 @@ test('default clientError handler destroys sockets in writable state', t => {
169
170
  },
170
171
  destroy () {
171
172
  t.pass('destroy should be called')
173
+ },
174
+ write (response) {
175
+ t.match(response, /^HTTP\/1.1 400 Bad Request/)
172
176
  }
173
177
  })
174
178
  })
@@ -189,6 +193,9 @@ test('default clientError handler destroys http sockets in non-writable state',
189
193
  },
190
194
  destroy () {
191
195
  t.pass('destroy should be called')
196
+ },
197
+ write (response) {
198
+ t.fail('write should not be called')
192
199
  }
193
200
  })
194
201
  })
@@ -273,3 +280,42 @@ test('encapsulated error handler binding', t => {
273
280
  t.equal(fastify.hello, undefined)
274
281
  })
275
282
  })
283
+
284
+ const skip = semver.lt(process.versions.node, '11.0.0')
285
+
286
+ test('default clientError replies with bad request on reused keep-alive connection', { skip }, t => {
287
+ t.plan(2)
288
+
289
+ let response = ''
290
+
291
+ const fastify = Fastify({
292
+ bodyLimit: 1,
293
+ keepAliveTimeout: 100
294
+ })
295
+
296
+ fastify.get('/', (request, reply) => {
297
+ reply.send('OK\n')
298
+ })
299
+
300
+ fastify.listen({ port: 0 }, function (err) {
301
+ t.error(err)
302
+ fastify.server.unref()
303
+
304
+ const client = connect(fastify.server.address().port)
305
+
306
+ client.on('data', chunk => {
307
+ response += chunk.toString('utf-8')
308
+ })
309
+
310
+ client.on('end', () => {
311
+ t.match(response, /^HTTP\/1.1 200 OK.*HTTP\/1.1 400 Bad Request/s)
312
+ })
313
+
314
+ client.resume()
315
+ client.write('GET / HTTP/1.1\r\n')
316
+ client.write('\r\n\r\n')
317
+ client.write('GET /?a b HTTP/1.1\r\n')
318
+ client.write('Connection: close\r\n')
319
+ client.write('\r\n\r\n')
320
+ })
321
+ })
@@ -683,3 +683,51 @@ test('should mark reply as sent before pumping the payload stream into response
683
683
  fastify.close()
684
684
  })
685
685
  })
686
+
687
+ test('reply.send handles aborted requests', t => {
688
+ t.plan(2)
689
+
690
+ const spyLogger = {
691
+ level: 'error',
692
+ fatal: () => { },
693
+ error: () => {
694
+ t.fail('should not log an error')
695
+ },
696
+ warn: () => { },
697
+ info: () => { },
698
+ debug: () => { },
699
+ trace: () => { },
700
+ child: () => { return spyLogger }
701
+ }
702
+ const fastify = Fastify({
703
+ logger: spyLogger
704
+ })
705
+
706
+ fastify.get('/', (req, reply) => {
707
+ setTimeout(() => {
708
+ const stream = new Readable({
709
+ read: function () {
710
+ this.push(null)
711
+ }
712
+ })
713
+ reply.send(stream)
714
+ }, 6)
715
+ })
716
+
717
+ fastify.listen({ port: 0 }, err => {
718
+ t.error(err)
719
+ fastify.server.unref()
720
+
721
+ const port = fastify.server.address().port
722
+ const http = require('http')
723
+ const req = http.get(`http://localhost:${port}`)
724
+ .on('error', (err) => {
725
+ t.equal(err.code, 'ECONNRESET')
726
+ fastify.close()
727
+ })
728
+
729
+ setTimeout(() => {
730
+ req.abort()
731
+ }, 1)
732
+ })
733
+ })
@@ -1,4 +1,4 @@
1
- import { FastifyError } from 'fastify-error'
1
+ import { FastifyError } from '@fastify/error'
2
2
  import { expectAssignable, expectError, expectType } from 'tsd'
3
3
  import fastify, {
4
4
  FastifyInstance,
@@ -1,4 +1,4 @@
1
- import { expectType } from 'tsd'
1
+ import { expectError, expectType } from 'tsd'
2
2
  import fastify, { FastifyLogFn, LogLevel, FastifyLoggerInstance, FastifyError, FastifyRequest, FastifyReply } from '../../fastify'
3
3
  import { Server, IncomingMessage, ServerResponse } from 'http'
4
4
  import pino from 'pino'
@@ -183,3 +183,15 @@ const passStreamAsOption = fastify({
183
183
  stream: fs.createWriteStream('/tmp/stream.out')
184
184
  }
185
185
  })
186
+
187
+ const childParent = fastify().log
188
+ // we test different option variant here
189
+ expectType<FastifyLoggerInstance>(childParent.child({}, { level: 'info' }))
190
+ expectType<FastifyLoggerInstance>(childParent.child({}, { redact: ['pass', 'pin'] }))
191
+ expectType<FastifyLoggerInstance>(childParent.child({}, { serializers: { key: () => {} } }))
192
+ expectType<FastifyLoggerInstance>(childParent.child({}, { level: 'info', redact: ['pass', 'pin'], serializers: { key: () => {} } }))
193
+
194
+ // no option pass
195
+ expectError(childParent.child())
196
+ // wrong option
197
+ expectError(childParent.child({}, { nonExist: true }))
@@ -3,7 +3,7 @@ import * as http from 'http'
3
3
  import * as https from 'https'
4
4
  import { expectType, expectError, expectAssignable } from 'tsd'
5
5
  import { FastifyPluginCallback, FastifyPluginAsync } from '../../types/plugin'
6
- import { FastifyError } from 'fastify-error'
6
+ import { FastifyError } from '@fastify/error'
7
7
 
8
8
  // FastifyPlugin & FastifyRegister
9
9
  interface TestOptions extends FastifyPluginOptions {
@@ -3,7 +3,7 @@ import { expectType, expectError, expectAssignable } from 'tsd'
3
3
  import { HTTPMethods } from '../../types/utils'
4
4
  import * as http from 'http'
5
5
  import { RequestPayload } from '../../types/hooks'
6
- import { FastifyError } from 'fastify-error'
6
+ import { FastifyError } from '@fastify/error'
7
7
 
8
8
  /*
9
9
  * Testing Fastify HTTP Routes and Route Shorthands.
package/types/hooks.d.ts CHANGED
@@ -4,7 +4,7 @@ import { RouteOptions, RouteGenericInterface } from './route'
4
4
  import { RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, ContextConfigDefault } from './utils'
5
5
  import { FastifyRequest } from './request'
6
6
  import { FastifyReply } from './reply'
7
- import { FastifyError } from 'fastify-error'
7
+ import { FastifyError } from '@fastify/error'
8
8
  import { FastifyLoggerInstance } from './logger'
9
9
  import { RegisterOptions } from './register'
10
10
  import { FastifyPluginOptions } from './plugin'
@@ -13,7 +13,7 @@ import { FastifyRegister } from './register'
13
13
  import { onRequestHookHandler, preParsingHookHandler, onSendHookHandler, preValidationHookHandler, preHandlerHookHandler, preSerializationHookHandler, onResponseHookHandler, onErrorHookHandler, onRouteHookHandler, onRegisterHookHandler, onCloseHookHandler, onCloseAsyncHookHandler, onReadyHookHandler, onTimeoutHookHandler, preParsingAsyncHookHandler, preValidationAsyncHookHandler, preHandlerAsyncHookHandler, preSerializationAsyncHookHandler, onSendAsyncHookHandler, onResponseAsyncHookHandler, onTimeoutAsyncHookHandler, onErrorAsyncHookHandler, onReadyAsyncHookHandler, onRequestAsyncHookHandler } from './hooks'
14
14
  import { FastifyRequest } from './request'
15
15
  import { FastifyReply } from './reply'
16
- import { FastifyError } from 'fastify-error'
16
+ import { FastifyError } from '@fastify/error'
17
17
  import { AddContentTypeParser, hasContentTypeParser, getDefaultJsonParser, ProtoAction, ConstructorAction, FastifyBodyParser, removeContentTypeParser, removeAllContentTypeParsers } from './content-type-parser'
18
18
 
19
19
  export interface PrintRoutesOptions {
package/types/logger.d.ts CHANGED
@@ -18,7 +18,7 @@
18
18
  * https://github.com/fastify/fastify/issues/649
19
19
  */
20
20
 
21
- import { FastifyError } from 'fastify-error'
21
+ import { FastifyError } from '@fastify/error'
22
22
  import { RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression } from './utils'
23
23
  import { RouteGenericInterface } from './route'
24
24
  import { FastifyRequest } from './request'
@@ -36,12 +36,23 @@ export type LogLevel = 'info' | 'error' | 'debug' | 'fatal' | 'warn' | 'trace'
36
36
 
37
37
  export type SerializerFn = (value: unknown) => unknown;
38
38
 
39
+ export interface redactOptions {
40
+ paths: string[];
41
+ censor?: string | ((v: any) => any) | undefined;
42
+ remove?: boolean | undefined;
43
+ }
39
44
  export interface Bindings {
40
45
  level?: LogLevel | string;
41
46
  serializers?: { [key: string]: SerializerFn };
42
47
  [key: string]: unknown;
43
48
  }
44
49
 
50
+ export interface ChildLoggerOptions {
51
+ level?: LogLevel | string;
52
+ redact?: string[] | redactOptions | undefined;
53
+ serializers?: { [key: string]: SerializerFn } | undefined;
54
+ }
55
+
45
56
  export interface FastifyLoggerInstance {
46
57
  info: FastifyLogFn;
47
58
  warn: FastifyLogFn;
@@ -49,7 +60,7 @@ export interface FastifyLoggerInstance {
49
60
  fatal: FastifyLogFn;
50
61
  trace: FastifyLogFn;
51
62
  debug: FastifyLogFn;
52
- child(bindings: Bindings): FastifyLoggerInstance;
63
+ child(bindings: Bindings, options?: ChildLoggerOptions): FastifyLoggerInstance;
53
64
  }
54
65
 
55
66
  // This interface is accurate for pino 6.3 and was copied from the following permalink:
package/types/route.d.ts CHANGED
@@ -5,7 +5,7 @@ import { FastifySchema, FastifySchemaCompiler, FastifySchemaValidationError, Fas
5
5
  import { HTTPMethods, RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, ContextConfigDefault } from './utils'
6
6
  import { FastifyLoggerInstance, LogLevel } from './logger'
7
7
  import { preValidationHookHandler, preHandlerHookHandler, preSerializationHookHandler, onRequestHookHandler, preParsingHookHandler, onResponseHookHandler, onSendHookHandler, onErrorHookHandler, onTimeoutHookHandler } from './hooks'
8
- import { FastifyError } from 'fastify-error'
8
+ import { FastifyError } from '@fastify/error'
9
9
  import { FastifyContext } from './context'
10
10
 
11
11
  export interface RouteGenericInterface extends RequestGenericInterface, ReplyGenericInterface {}