Compare commits

...

2 Commits

Author SHA1 Message Date
Jeremy Rose
325faae33c fix test 2021-02-03 13:28:25 -08:00
Jeremy Rose
94f8b4b39a fix: [net] no errors on response stream 2021-02-02 16:39:43 -08:00
2 changed files with 31 additions and 5 deletions

View File

@@ -432,9 +432,7 @@ export class ClientRequest extends Writable implements Electron.ClientRequest {
if (this._response) { this._response._storeInternalData(null, null); }
});
this._urlLoader.on('error', (event, netErrorString) => {
const error = new Error(netErrorString);
if (this._response) this._response.destroy(error);
this._die(error);
this._die(new Error(netErrorString));
});
this._urlLoader.on('login', (event, authInfo, callback) => {
@@ -515,7 +513,7 @@ export class ClientRequest extends Writable implements Electron.ClientRequest {
this.destroy(err);
if (this._urlLoader) {
this._urlLoader.cancel();
if (this._response) this._response.destroy(err);
if (this._response) this._response.destroy();
}
}

View File

@@ -2,7 +2,7 @@ import { expect } from 'chai';
import { net, session, ClientRequest, BrowserWindow, ClientRequestConstructorOptions } from 'electron/main';
import * as http from 'http';
import * as url from 'url';
import { AddressInfo, Socket } from 'net';
import { AddressInfo, Socket, createServer } from 'net';
import { emittedOnce } from './events-helpers';
import { defer, delay } from './spec-helpers';
@@ -1536,6 +1536,34 @@ describe('net module', () => {
expect(response.statusCode).to.equal(200);
await collectStreamBody(response);
});
it('should not trigger errors on the response stream', async () => {
const ses = session.fromPartition(`${Math.random()}`);
const serverPort = await new Promise(resolve => {
const server = createServer((c) => {
c.end('HTTP/1.1 407 Authentication Required\nProxy-Authenticate: Basic realm="Foo"\n\n');
}).listen(0, '127.0.0.1', async () => {
resolve((server.address() as AddressInfo).port);
});
});
await ses.setProxy({ proxyRules: `127.0.0.1:${serverPort}` });
const error = await new Promise<Error>((resolve, reject) => {
net
.request({ method: 'GET', url: 'https://example.com', session: ses })
.once('response', (res) => {
res.on('error', () => {
reject(new Error('response stream should not emit error'));
});
})
.once('abort', () => reject(new Error('should not abort')))
.once('error', (err) => {
resolve(err);
})
.once('login', (_, callback) => { callback('username', 'password'); })
.end();
});
expect(error.message).to.equal('net::ERR_TUNNEL_CONNECTION_FAILED');
});
});
describe('IncomingMessage API', () => {