@@ -5,7 +5,7 @@ import * as crypto from 'crypto';
5
5
import { once } from 'events' ;
6
6
import createDebug from 'debug' ;
7
7
import { Readable } from 'stream' ;
8
- import { format , URL } from 'url' ;
8
+ import { URL } from 'url' ;
9
9
import { Agent , AgentConnectOpts , toBuffer } from 'agent-base' ;
10
10
import { HttpProxyAgent , HttpProxyAgentOptions } from 'http-proxy-agent' ;
11
11
import { HttpsProxyAgent , HttpsProxyAgentOptions } from 'https-proxy-agent' ;
@@ -204,32 +204,16 @@ export class PacProxyAgent<Uri extends string> extends Agent {
204
204
const resolver = await this . getResolver ( ) ;
205
205
206
206
// Calculate the `url` parameter
207
+ const protocol = secureEndpoint ? 'https:' : 'http:' ;
208
+ const host =
209
+ opts . host && net . isIPv6 ( opts . host ) ? `[${ opts . host } ]` : opts . host ;
207
210
const defaultPort = secureEndpoint ? 443 : 80 ;
208
- let path = req . path ;
209
- let search : string | null = null ;
210
- const firstQuestion = path . indexOf ( '?' ) ;
211
- if ( firstQuestion !== - 1 ) {
212
- search = path . substring ( firstQuestion ) ;
213
- path = path . substring ( 0 , firstQuestion ) ;
214
- }
215
-
216
- const urlOpts = {
217
- ...opts ,
218
- protocol : secureEndpoint ? 'https:' : 'http:' ,
219
- pathname : path ,
220
- search,
221
-
222
- // need to use `hostname` instead of `host` otherwise `port` is ignored
223
- hostname : opts . host ,
224
- host : null ,
225
- href : null ,
226
-
227
- // set `port` to null when it is the protocol default port (80 / 443)
228
- port : defaultPort === opts . port ? null : opts . port ,
229
- } ;
230
- const url = format ( urlOpts ) ;
211
+ const url = Object . assign (
212
+ new URL ( req . path , `${ protocol } //${ host } ` ) ,
213
+ defaultPort ? undefined : { port : opts . port }
214
+ ) ;
231
215
232
- debug ( 'url: %o ' , url ) ;
216
+ debug ( 'url: %s ' , url ) ;
233
217
let result = await resolver ( url ) ;
234
218
235
219
// Default to "DIRECT" if a falsey value was returned (or nothing)
0 commit comments