11import { ProxyAgent } from './proxy-agent' ;
2- import type { Agent } from 'https' ;
2+ import type { Agent as HTTPSAgent } from 'https' ;
33import type { DevtoolsProxyOptions } from './proxy-options' ;
44import { 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' ;
67import type { TcpNetConnectOpts } from 'net' ;
78import type { ConnectionOptions , SecureContextOptions } from 'tls' ;
89import 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