fastify 4.25.1 → 4.25.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.
- package/docs/Reference/Server.md +5 -3
- package/fastify.js +1 -1
- package/lib/reply.js +4 -0
- package/package.json +2 -2
- package/test/reply-code.test.js +24 -1
package/docs/Reference/Server.md
CHANGED
|
@@ -1532,9 +1532,11 @@ handlers. *async-await* is supported as well.
|
|
|
1532
1532
|
If the error `statusCode` is less than 400, Fastify will automatically
|
|
1533
1533
|
set it to 500 before calling the error handler.
|
|
1534
1534
|
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1535
|
+
`setErrorHandler` will ***not*** catch:
|
|
1536
|
+
- errors thrown in an `onResponse` hook because the response has already been
|
|
1537
|
+
sent to the client. Use the `onSend` hook instead.
|
|
1538
|
+
- not found (404) errors. Use [`setNotFoundHandler`](#set-not-found-handler)
|
|
1539
|
+
instead.
|
|
1538
1540
|
|
|
1539
1541
|
```js
|
|
1540
1542
|
fastify.setErrorHandler(function (error, request, reply) {
|
package/fastify.js
CHANGED
package/lib/reply.js
CHANGED
|
@@ -605,6 +605,10 @@ function onSendEnd (reply, payload) {
|
|
|
605
605
|
reply.removeHeader('content-length')
|
|
606
606
|
safeWriteHead(reply, statusCode)
|
|
607
607
|
sendTrailer(undefined, res, reply)
|
|
608
|
+
if (typeof payload.resume === 'function') {
|
|
609
|
+
payload.on('error', noop)
|
|
610
|
+
payload.resume()
|
|
611
|
+
}
|
|
608
612
|
return
|
|
609
613
|
}
|
|
610
614
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fastify",
|
|
3
|
-
"version": "4.25.
|
|
3
|
+
"version": "4.25.2",
|
|
4
4
|
"description": "Fast and low overhead web framework, for Node.js",
|
|
5
5
|
"main": "fastify.js",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"test:report": "npm run lint && npm run unit:report && npm run test:typescript",
|
|
26
26
|
"test:validator:integrity": "npm run build:validation && git diff --quiet --ignore-all-space --ignore-blank-lines --ignore-cr-at-eol lib/error-serializer.js && git diff --quiet --ignore-all-space --ignore-blank-lines --ignore-cr-at-eol lib/configValidator.js",
|
|
27
27
|
"test:typescript": "tsc test/types/import.ts && tsd",
|
|
28
|
-
"test:watch": "npm run unit --
|
|
28
|
+
"test:watch": "npm run unit -- --watch --cov --no-coverage-report --reporter=terse",
|
|
29
29
|
"unit": "c8 tap",
|
|
30
30
|
"unit:junit": "tap-mocha-reporter xunit < out.tap > test/junit-testresults.xml",
|
|
31
31
|
"unit:report": "tap --cov --coverage-report=html --coverage-report=cobertura | tee out.tap",
|
package/test/reply-code.test.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const t = require('tap')
|
|
4
|
+
const { Readable } = require('stream')
|
|
4
5
|
const test = t.test
|
|
5
6
|
const Fastify = require('..')
|
|
6
7
|
|
|
@@ -59,7 +60,7 @@ test('code should handle null/undefined/float', t => {
|
|
|
59
60
|
})
|
|
60
61
|
|
|
61
62
|
test('code should handle 204', t => {
|
|
62
|
-
t.plan(
|
|
63
|
+
t.plan(13)
|
|
63
64
|
|
|
64
65
|
const fastify = Fastify()
|
|
65
66
|
|
|
@@ -72,6 +73,18 @@ test('code should handle 204', t => {
|
|
|
72
73
|
reply.status(204).send({ message: 'hello' })
|
|
73
74
|
})
|
|
74
75
|
|
|
76
|
+
fastify.get('/stream/204', function (request, reply) {
|
|
77
|
+
const stream = new Readable({
|
|
78
|
+
read () {
|
|
79
|
+
this.push(null)
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
stream.on('end', () => {
|
|
83
|
+
t.pass('stream ended')
|
|
84
|
+
})
|
|
85
|
+
reply.status(204).send(stream)
|
|
86
|
+
})
|
|
87
|
+
|
|
75
88
|
fastify.inject({
|
|
76
89
|
method: 'GET',
|
|
77
90
|
url: '/204'
|
|
@@ -91,6 +104,16 @@ test('code should handle 204', t => {
|
|
|
91
104
|
t.equal(res.payload, '')
|
|
92
105
|
t.equal(res.headers['content-length'], undefined)
|
|
93
106
|
})
|
|
107
|
+
|
|
108
|
+
fastify.inject({
|
|
109
|
+
method: 'GET',
|
|
110
|
+
url: '/stream/204'
|
|
111
|
+
}, (error, res) => {
|
|
112
|
+
t.error(error)
|
|
113
|
+
t.equal(res.statusCode, 204)
|
|
114
|
+
t.equal(res.payload, '')
|
|
115
|
+
t.equal(res.headers['content-length'], undefined)
|
|
116
|
+
})
|
|
94
117
|
})
|
|
95
118
|
|
|
96
119
|
test('code should handle onSend hook on 204', t => {
|