Skip to content

Commit c09f373

Browse files
authored
fix(devtools-proxy-support): add yet another proxy-agent workaround (#453)
1 parent 5c1e7de commit c09f373

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

packages/devtools-proxy-support/src/agent.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,4 +345,21 @@ q/I2+0j6dAkOGcK/68z7qQXByeGri3n28a1Kn6o=
345345
}
346346
});
347347
});
348+
349+
context('invalid arguments', function () {
350+
it('does not receive unhandled rejections when using invalid options', async function () {
351+
// This test may seem contrived, but it mimics FIPS mode without a valid system FIPS config
352+
// (i.e. OpenSSL cannot load ciphers) -- this should result in a handled rejection, rather than
353+
// an unhandled one.
354+
try {
355+
await get(
356+
'https://example.com/hello',
357+
createAgent({ ciphers: 'unknown' } as any)
358+
);
359+
expect.fail('missed exception');
360+
} catch (err: any) {
361+
expect(err.message).to.include('no cipher match');
362+
}
363+
});
364+
});
348365
});

packages/devtools-proxy-support/src/agent.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { ProxyAgent } from './proxy-agent';
2-
import type { Agent } from 'https';
2+
import type { Agent as HTTPSAgent } from 'https';
33
import type { DevtoolsProxyOptions } from './proxy-options';
44
import { proxyForUrl } from './proxy-options';
5-
import type { ClientRequest, Agent as HTTPAgent } from 'http';
5+
import type { ClientRequest } from 'http';
6+
import { Agent as HTTPAgent } from 'http';
67
import type { TcpNetConnectOpts } from 'net';
78
import type { ConnectionOptions, SecureContextOptions } from 'tls';
89
import type { Duplex } from 'stream';
@@ -16,7 +17,7 @@ import { mergeCA, systemCA } from './system-ca';
1617
// Helper type that represents an https.Agent (= connection factory)
1718
// with some custom properties that TS does not know about and/or
1819
// that we add for our own purposes.
19-
export type AgentWithInitialize = Agent & {
20+
export type AgentWithInitialize = HTTPSAgent & {
2021
// This is genuinely custom for our usage (to allow establishing an SSH tunnel
2122
// first before starting to push connections through it)
2223
initialize?(): Promise<void>;
@@ -96,7 +97,18 @@ class DevtoolsProxyAgent extends ProxyAgent implements AgentWithInitialize {
9697
}
9798
this._req = req;
9899
this._reqLock = new Promise((resolve) => (this._reqLockResolve = resolve));
99-
return await super.connect(req, opts);
100+
const agent = await super.connect(req, opts);
101+
// Work around https://github.com/TooTallNate/proxy-agents/pull/330
102+
if ('addRequest' in agent && typeof agent.addRequest === 'function') {
103+
const dummyHttpAgent = Object.assign(new HTTPAgent(), {
104+
addRequest() {
105+
//ignore
106+
},
107+
});
108+
agent.addRequest(req, opts);
109+
return dummyHttpAgent;
110+
}
111+
return agent;
100112
}
101113

102114
destroy(): void {

0 commit comments

Comments
 (0)