1
1
import * as http from 'http' ;
2
2
import * 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' ;
5
4
// No types for the event source.
6
5
// @ts -ignore
7
6
import { EventSource as LDEventSource } from 'launchdarkly-eventsource' ;
7
+ import { format as formatUrl } from 'url' ;
8
8
import { promisify } from 'util' ;
9
9
import * as zlib from 'zlib' ;
10
10
@@ -52,11 +52,13 @@ function processProxyOptions(
52
52
proxyOptions : LDProxyOptions ,
53
53
additional : https . AgentOptions = { } ,
54
54
) : 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 ,
57
59
port : proxyOptions . port ,
58
- host : proxyOptions . host ,
59
- protocol ,
60
+ } ) ;
61
+ const parsedOptions : HttpsProxyAgentOptions < string > = {
60
62
...additional ,
61
63
} ;
62
64
if ( proxyOptions . auth ) {
@@ -67,12 +69,12 @@ function processProxyOptions(
67
69
68
70
// Node does not take kindly to undefined keys.
69
71
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 > ] ;
72
74
}
73
75
} ) ;
74
76
75
- return createHttpsProxyAgent ( parsedOptions ) ;
77
+ return new HttpsProxyAgent ( proxyUrl , parsedOptions ) ;
76
78
}
77
79
78
80
function createAgent (
0 commit comments