Skip to content

Commit

Permalink
fixup! fix: reply object not marked as sent for stream payloads (#3318)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergejostir committed Nov 14, 2021
1 parent 94e21aa commit 1dc6d13
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 40 deletions.
3 changes: 0 additions & 3 deletions lib/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const {
kReplyHasStatusCode,
kReplyIsRunningOnErrorHook,
kReplyNextErrorHandler,
kReplySent,
kDisableRequestLogging
} = require('./symbols.js')
const { hookRunner, hookIterator, onSendHookRunner } = require('./hooks')
Expand Down Expand Up @@ -415,8 +414,6 @@ function onSendEnd (reply, payload) {
}

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

sendStream(payload, res, reply)
return
}
Expand Down
38 changes: 1 addition & 37 deletions test/stream.test.js
Original file line number Diff line number Diff line change
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 @@ -646,39 +646,3 @@ test('should destroy stream when response is ended', t => {
})
})
})

test('should mark reply as sent before pumping the payload stream into response for async route handler', t => {
t.plan(3)

const handleRequest = proxyquire('../lib/handleRequest', {
'./wrapThenable': (thenable, reply) => {
thenable.then(function (payload) {
t.equal(reply[kReplySent], true)
})
}
})

const route = proxyquire('../lib/route', {
'./handleRequest': handleRequest
})

const Fastify = proxyquire('..', {
'./lib/route': route
})

const fastify = Fastify()

fastify.get('/', async function (req, reply) {
const stream = fs.createReadStream(__filename, 'utf8')
reply.code(200).send(stream)
})

fastify.inject({
url: '/',
method: 'GET'
}, (err, res) => {
t.error(err)
t.equal(res.payload, fs.readFileSync(__filename, 'utf8'))
fastify.close()
})
})

0 comments on commit 1dc6d13

Please sign in to comment.