diff --git a/lib/error-handler.js b/lib/error-handler.js index cd6ab2ca05..e7f01f6a00 100644 --- a/lib/error-handler.js +++ b/lib/error-handler.js @@ -4,7 +4,7 @@ const FJS = require('fast-json-stringify') const statusCodes = require('http').STATUS_CODES const wrapThenable = require('./wrapThenable') const { - kReplyHeaders, kReplyNextErrorHandler, kReplyIsRunningOnErrorHook, kReplySent, kReplyHasStatusCode + kReplyHeaders, kReplyNextErrorHandler, kReplyIsRunningOnErrorHook, kReplyHasStatusCode } = require('./symbols.js') const { @@ -122,8 +122,6 @@ function fallbackErrorHandler (error, reply, cb) { reply[kReplyHeaders]['content-type'] = 'application/json; charset=utf-8' reply[kReplyHeaders]['content-length'] = '' + Buffer.byteLength(payload) - reply[kReplySent] = true - cb(reply, payload) } diff --git a/lib/reply.js b/lib/reply.js index 0eec1f3f6a..c7a15fc64b 100644 --- a/lib/reply.js +++ b/lib/reply.js @@ -15,7 +15,6 @@ const { kReplyHasStatusCode, kReplyIsRunningOnErrorHook, kReplyNextErrorHandler, - kReplySent, kDisableRequestLogging } = require('./symbols.js') const { hookRunner, hookIterator, onSendHookRunner } = require('./hooks') @@ -376,7 +375,6 @@ function preserializeHookEnd (err, request, reply, payload) { function onSendHook (reply, payload) { if (reply.context.onSend !== null) { - reply[kReplySent] = true onSendHookRunner( reply.context.onSend, reply.request, @@ -418,8 +416,6 @@ function onSendEnd (reply, payload) { } if (typeof payload.pipe === 'function') { - reply[kReplySent] = true - sendStream(payload, res, reply) return } diff --git a/test/stream.test.js b/test/stream.test.js index 8cd02bbddc..7e38d45f67 100644 --- a/test/stream.test.js +++ b/test/stream.test.js @@ -14,7 +14,7 @@ const JSONStream = require('JSONStream') const send = require('send') const Readable = require('stream').Readable const split = require('split2') -const { kDisableRequestLogging, kReplySent } = require('../lib/symbols.js') +const { kDisableRequestLogging } = require('../lib/symbols.js') test('should respond with a stream (success)', t => { t.plan(6) @@ -653,7 +653,7 @@ test('should mark reply as sent before pumping the payload stream into response const handleRequest = proxyquire('../lib/handleRequest', { './wrapThenable': (thenable, reply) => { thenable.then(function (payload) { - t.equal(reply[kReplySent], true) + t.equal(reply.sent, true) }) } }) @@ -670,7 +670,7 @@ test('should mark reply as sent before pumping the payload stream into response fastify.get('/', async function (req, reply) { const stream = fs.createReadStream(__filename, 'utf8') - reply.code(200).send(stream) + return reply.code(200).send(stream) }) fastify.inject({