@@ -8,23 +8,13 @@ import { URL } from 'url';
88import { Agent , ClientRequest , RequestOptions , AgentCallbackReturn } from 'agent-base' ;
99import Electron from 'electron' ;
1010import HttpProxyAgent from 'http-proxy-agent' ;
11- import { HttpsProxyAgent , HttpsProxyAgentOptions } from 'https-proxy-agent' ;
11+ import { HttpsProxyAgent } from 'https-proxy-agent' ;
1212import { SocksProxyAgent } from 'socks-proxy-agent' ;
1313
1414import Logging from '@pkg/utils/logging' ;
1515
1616const console = Logging . background ;
1717
18- interface HttpConnectOpts extends net . TcpNetConnectOpts {
19- secureEndpoint : false ;
20- }
21- interface HttpsConnectOpts extends tls . ConnectionOptions {
22- port : number ;
23- secureEndpoint : true ;
24- }
25-
26- type CustomAgentConnectOpts = HttpConnectOpts | HttpsConnectOpts ;
27-
2818export default class ElectronProxyAgent extends Agent {
2919 protected session : Electron . Session ;
3020
@@ -85,25 +75,22 @@ export default class ElectronProxyAgent extends Agent {
8575 }
8676}
8777
88- class CustomHttpsProxyAgent < Uri extends string > extends HttpsProxyAgent < Uri > {
89- constructor ( proxy : Uri | URL , opts ?: HttpsProxyAgentOptions < Uri > ) {
78+ class CustomHttpsProxyAgent extends HttpsProxyAgent {
79+ constructor ( proxyURL : string , opts : HttpsAgentOptions ) {
9080 // Use object destructing here to ensure we only get wanted properties.
91- const { hostname, port, protocol } = new URL ( proxy . toString ( ) ) ;
81+ const { hostname, port, protocol } = new URL ( proxyURL ) ;
9282 const mergedOpts = Object . assign ( { } , opts , {
9383 hostname, port, protocol,
9484 } ) ;
9585
96- super ( proxy , mergedOpts ) ;
97- if ( opts ) {
98- this . options = opts ;
99- }
86+ super ( mergedOpts ) ;
87+ this . options = opts ;
10088 }
10189
102- async connect ( req : http . ClientRequest , opts : CustomAgentConnectOpts ) : Promise < net . Socket > {
90+ callback ( req : ClientRequest , opts : RequestOptions ) : Promise < net . Socket > {
10391 const mergedOptions = Object . assign ( { } , this . options , opts ) ;
104- const socket = await super . connect ( req , mergedOptions ) ;
10592
106- return socket ;
93+ return super . callback ( req , mergedOptions ) ;
10794 }
10895}
10996
0 commit comments