Skip to content

Commit 5cb0bac

Browse files
authored
avoid body reordering on really fast lines (#1615)
1 parent 21fdda5 commit 5cb0bac

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/api/readable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module.exports = class BodyReadable extends Readable {
9393
}
9494

9595
push (chunk) {
96-
if (this[kConsume] && chunk !== null) {
96+
if (this[kConsume] && chunk !== null && this.readableLength === 0) {
9797
consumePush(this[kConsume], chunk)
9898
return this[kReading] ? super.push(chunk) : true
9999
}

test/readable.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict'
2+
3+
const { test } = require('tap')
4+
const Readable = require('../lib/api/readable')
5+
6+
test('avoid body reordering', async function (t) {
7+
function resume () {
8+
}
9+
function abort () {
10+
}
11+
const r = new Readable(resume, abort)
12+
13+
r.push(Buffer.from('hello'))
14+
15+
process.nextTick(() => {
16+
r.push(Buffer.from('world'))
17+
r.push(null)
18+
})
19+
20+
const text = await r.text()
21+
22+
t.equal(text, 'helloworld')
23+
})

0 commit comments

Comments
 (0)