1
1
import { ProxyAgent } from './proxy-agent' ;
2
- import type { Agent } from 'https' ;
2
+ import type { Agent as HTTPSAgent } from 'https' ;
3
3
import type { DevtoolsProxyOptions } from './proxy-options' ;
4
4
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' ;
6
7
import type { TcpNetConnectOpts } from 'net' ;
7
8
import type { ConnectionOptions , SecureContextOptions } from 'tls' ;
8
9
import type { Duplex } from 'stream' ;
@@ -16,7 +17,7 @@ import { mergeCA, systemCA } from './system-ca';
16
17
// Helper type that represents an https.Agent (= connection factory)
17
18
// with some custom properties that TS does not know about and/or
18
19
// that we add for our own purposes.
19
- export type AgentWithInitialize = Agent & {
20
+ export type AgentWithInitialize = HTTPSAgent & {
20
21
// This is genuinely custom for our usage (to allow establishing an SSH tunnel
21
22
// first before starting to push connections through it)
22
23
initialize ?( ) : Promise < void > ;
@@ -96,7 +97,18 @@ class DevtoolsProxyAgent extends ProxyAgent implements AgentWithInitialize {
96
97
}
97
98
this . _req = req ;
98
99
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 ;
100
112
}
101
113
102
114
destroy ( ) : void {
0 commit comments