Skip to content

Commit

Permalink
fix(reply.send): support Uint8Array payloads
Browse files Browse the repository at this point in the history
fixes #5118
  • Loading branch information
SgtPooki committed Oct 26, 2023
1 parent 642af3b commit 5845226
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Reply.prototype.send = function (payload) {
if (hasContentType === false) {
this[kReplyHeaders]['content-type'] = CONTENT_TYPE.OCTET
}
const payloadToSend = Buffer.isBuffer(payload) ? payload : Buffer.from(payload.buffer)
const payloadToSend = payload instanceof Uint8Array ? payload : Buffer.from(payload.buffer)
onSendHook(this, payloadToSend)
return this
}
Expand Down Expand Up @@ -613,7 +613,7 @@ function onSendEnd (reply, payload) {
return
}

if (typeof payload !== 'string' && !Buffer.isBuffer(payload)) {
if (typeof payload !== 'string' && !Buffer.isBuffer(payload) && !(payload instanceof Uint8Array)) {
throw new FST_ERR_REP_INVALID_PAYLOAD_TYPE(typeof payload)
}

Expand Down
4 changes: 2 additions & 2 deletions test/internals/reply.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2169,8 +2169,8 @@ test('Uint8Array view of ArrayBuffer returns correct byteLength', t => {
}, (err, response) => {
t.error(err)
t.equal(response.headers['content-type'], 'application/octet-stream')
t.equal(response.headers['content-length'], '100')
t.same(response.rawPayload.byteLength, arrBuf.byteLength)
t.equal(response.headers['content-length'], '10')
t.same(response.rawPayload.byteLength, arrView.byteLength)
})
})
})

0 comments on commit 5845226

Please sign in to comment.