8000 fix: Close protocol response streams when aborted by trop[bot] · Pull Request #24657 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: Close protocol response streams when aborted #24657

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

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions shell/browser/net/node_stream_loader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ NodeStreamLoader::~NodeStreamLoader() {
node::MakeCallback(isolate_, emitter_.Get(isolate_), "removeListener",
node::arraysize(args), args, {0, 0});
}

// Destroy the stream if not already ended
if (!ended_) {
node::MakeCallback(isolate_, emitter_.Get(isolate_), "destroy", 0, nullptr,
{0, 0});
}
}

void NodeStreamLoader::Start(network::mojom::URLResponseHeadPtr head) {
Expand Down
24 changes: 24 additions & 0 deletions spec-main/api-protocol-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,30 @@ describe('protocol module', () => {
ajax(protocolName + '://fake-host');
await hasEndedPromise;
});

it('destroys response streams when aborted before completion', async () => {
const events = new EventEmitter();
registerStreamProtocol(protocolName, (request, callback) => {
const responseStream = new stream.PassThrough();
responseStream.push('data\r\n');
responseStream.on('close', () => {
events.emit('close');
});
callback({
statusCode: 200,
headers: { 'Content-Type': 'text/plain' },
data: responseStream
});
events.emit('respond');
});

const hasRespondedPromise = emittedOnce(events, 'respond');
const hasClosedPromise = emittedOnce(events, 'close');
ajax(protocolName + '://fake-host');
await hasRespondedPromise;
await contents.loadFile(path.join(__dirname, 'fixtures', 'pages', 'jquery.html'));
await hasClosedPromise;
});
});

describe('protocol.isProtocolHandled', () => {
Expand Down
0