Skip to content

Commit

Permalink
fix: stream protocols not completing (#21758)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeremy Apthorp <nornagon@nornagon.net>
  • Loading branch information
2 people authored and zcbenz committed Jan 14, 2020
1 parent 85c07d0 commit dd27520
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shell/browser/net/node_stream_loader.cc
Expand Up @@ -97,6 +97,9 @@ void NodeStreamLoader::ReadMore() {
if (!ret.ToLocal(&buffer) || !node::Buffer::HasInstance(buffer)) {
readable_ = false;
is_reading_ = false;
if (ended_) {
NotifyComplete(result_);
}
return;
}

Expand Down
19 changes: 19 additions & 0 deletions spec-main/api-protocol-spec.ts
Expand Up @@ -392,6 +392,25 @@ describe('protocol module', () => {
const r = await ajax(protocolName + '://fake-host')
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', () => {
Expand Down

0 comments on commit dd27520

Please sign in to comment.