Skip to content

Commit

Permalink
Adjust existing PRs for the new reply.sent handing (#3444)
Browse files Browse the repository at this point in the history
* fixup! Encapsulated error handling (#3261)

* fixup! fixed unresponsive server  #3283 (#3285)

* fixup! fix: reply object not marked as sent for stream payloads (#3318)
  • Loading branch information
sergejostir committed Nov 23, 2021
1 parent f57a435 commit fd8503a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
4 changes: 1 addition & 3 deletions lib/error-handler.js
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 0 additions & 4 deletions lib/reply.js
Expand Up @@ -15,7 +15,6 @@ const {
kReplyHasStatusCode,
kReplyIsRunningOnErrorHook,
kReplyNextErrorHandler,
kReplySent,
kDisableRequestLogging
} = require('./symbols.js')
const { hookRunner, hookIterator, onSendHookRunner } = require('./hooks')
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -418,8 +416,6 @@ function onSendEnd (reply, payload) {
}

if (typeof payload.pipe === 'function') {
reply[kReplySent] = true

sendStream(payload, res, reply)
return
}
Expand Down
6 changes: 3 additions & 3 deletions test/stream.test.js
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
}
})
Expand All @@ -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({
Expand Down

0 comments on commit fd8503a

Please sign in to comment.