fix: stream protocols not completing (#21733)
This commit is contained in:
parent
7723c2c16d
commit
d68f17b32c
2 changed files with 22 additions and 0 deletions
|
@ -102,6 +102,9 @@ void NodeStreamLoader::ReadMore() {
|
||||||
if (!ret.ToLocal(&buffer) || !node::Buffer::HasInstance(buffer)) {
|
if (!ret.ToLocal(&buffer) || !node::Buffer::HasInstance(buffer)) {
|
||||||
readable_ = false;
|
readable_ = false;
|
||||||
is_reading_ = false;
|
is_reading_ = false;
|
||||||
|
if (ended_) {
|
||||||
|
NotifyComplete(result_);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -392,6 +392,25 @@ describe('protocol module', () => {
|
||||||
const r = await ajax(protocolName + '://fake-host')
|
const r = await ajax(protocolName + '://fake-host')
|
||||||
expect(r.data).to.have.lengthOf(data.length)
|
expect(r.data).to.have.lengthOf(data.length)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('can handle a stream completing while writing', async () => {
|
||||||
|
function dumbPassthrough () {
|
||||||
|
return new stream.Transform({
|
||||||
|
async transform (chunk, encoding, cb) {
|
||||||
|
cb(null, chunk)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
await registerStreamProtocol(protocolName, (request, callback) => {
|
||||||
|
callback({
|
||||||
|
statusCode: 200,
|
||||||
|
headers: { 'Content-Type': 'text/plain' },
|
||||||
|
data: getStream(1024 * 1024, Buffer.alloc(1024 * 1024 * 2)).pipe(dumbPassthrough())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
const r = await ajax(protocolName + '://fake-host')
|
||||||
|
expect(r.data).to.have.lengthOf(1024 * 1024 * 2)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('protocol.isProtocolHandled', () => {
|
describe('protocol.isProtocolHandled', () => {
|
||||||
|
|
Loading…
Reference in a new issue