Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Reply.prototype.then = function (fullfilled, rejected) {
if (this.sent) {
fullfilled()
return
}
eos(this.res, function (err) {
// We must not treat ERR_STREAM_PREMATURE_CLOSE as
// an error because it is created by eos, not by the stream.
if (err && err.code !== 'ERR_STREAM_PREMATURE_CLOSE') {
if (rejected) {
rejected(err)
}
} else {
fullfilled()
}
})
}
var sourceOpen = true
eos(payload, { readable: true, writable: false }, function (err) {
sourceOpen = false
if (err != null) {
if (res.headersSent) {
reply.log.warn({ err }, 'response terminated with an error with headers already sent')
res.destroy()
} else {
onErrorHook(reply, err)
}
}
// there is nothing to do if there is not an error
})
eos(res, function (err) {
if (err != null) {
if (res.headersSent) {
reply.log.warn({ err }, 'response terminated with an error with headers already sent')
}
if (sourceOpen) {
if (payload.destroy) {
payload.destroy()
} else if (typeof payload.close === 'function') {
payload.close(noop)
} else if (typeof payload.abort === 'function') {
payload.abort()
}
}
}
})
function sendStream (payload, res, reply) {
var sourceOpen = true
eos(payload, { readable: true, writable: false }, function (err) {
sourceOpen = false
if (err != null) {
if (res.headersSent) {
reply.log.warn({ err }, 'response terminated with an error with headers already sent')
res.destroy()
} else {
onErrorHook(reply, err)
}
}
// there is nothing to do if there is not an error
})
eos(res, function (err) {
if (err != null) {
if (res.headersSent) {
reply.log.warn({ err }, 'response terminated with an error with headers already sent')
await new Promise((resolve, reject) => {
stream.finished(userStream, err => {
err ? reject(err) : resolve();
});
});
});
return new Promise((resolve, reject) => {
finished(stream, (err: Error) => err ? reject(err) : resolve())
})
}
return new Promise((resolve, reject) => {
finished(stream, (err: Error) => err ? reject(err) : resolve())
})
}