Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: stream protocols not completing #21758

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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