Skip to content

Commit

Permalink
avoid body reordering on really fast lines (#1615)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina authored Aug 23, 2022
1 parent 21fdda5 commit 5cb0bac
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/api/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ module.exports = class BodyReadable extends Readable {
}

push (chunk) {
if (this[kConsume] && chunk !== null) {
if (this[kConsume] && chunk !== null && this.readableLength === 0) {
consumePush(this[kConsume], chunk)
return this[kReading] ? super.push(chunk) : true
}
Expand Down
23 changes: 23 additions & 0 deletions test/readable.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

const { test } = require('tap')
const Readable = require('../lib/api/readable')

test('avoid body reordering', async function (t) {
function resume () {
}
function abort () {
}
const r = new Readable(resume, abort)

r.push(Buffer.from('hello'))

process.nextTick(() => {
r.push(Buffer.from('world'))
r.push(null)
})

const text = await r.text()

t.equal(text, 'helloworld')
})

0 comments on commit 5cb0bac

Please sign in to comment.