11import * as http from 'http' ;
22import * as https from 'https' ;
3- import * as createHttpsProxyAgent from 'https-proxy-agent' ;
4- import { HttpsProxyAgentOptions } from 'https-proxy-agent' ;
3+ import { HttpsProxyAgent , HttpsProxyAgentOptions } from 'https-proxy-agent' ;
54// No types for the event source.
65// @ts -ignore
76import { EventSource as LDEventSource } from 'launchdarkly-eventsource' ;
7+ import { format as formatUrl } from 'url' ;
88import { promisify } from 'util' ;
99import * as zlib from 'zlib' ;
1010
@@ -52,11 +52,13 @@ function processProxyOptions(
5252 proxyOptions : LDProxyOptions ,
5353 additional : https . AgentOptions = { } ,
5454) : https . Agent | http . Agent {
55- const protocol = proxyOptions . scheme ?. startsWith ( 'https' ) ? 'https:' : 'http' ;
56- const parsedOptions : HttpsProxyAgentOptions & { [ index : string ] : any } = {
55+ const proxyUrl = formatUrl ( {
56+ protocol : proxyOptions . scheme ?. startsWith ( 'https' ) ? 'https:' : 'http:' ,
57+ slashes : true ,
58+ hostname : proxyOptions . host ,
5759 port : proxyOptions . port ,
58- host : proxyOptions . host ,
59- protocol ,
60+ } ) ;
61+ const parsedOptions : HttpsProxyAgentOptions < string > = {
6062 ...additional ,
6163 } ;
6264 if ( proxyOptions . auth ) {
@@ -67,12 +69,12 @@ function processProxyOptions(
6769
6870 // Node does not take kindly to undefined keys.
6971 Object . keys ( parsedOptions ) . forEach ( ( key ) => {
70- if ( parsedOptions [ key ] === undefined ) {
71- delete parsedOptions [ key ] ;
72+ if ( parsedOptions [ key as keyof HttpsProxyAgentOptions < string > ] === undefined ) {
73+ delete parsedOptions [ key as keyof HttpsProxyAgentOptions < string > ] ;
7274 }
7375 } ) ;
7476
75- return createHttpsProxyAgent ( parsedOptions ) ;
77+ return new HttpsProxyAgent ( proxyUrl , parsedOptions ) ;
7678}
7779
7880function createAgent (
0 commit comments