File tree 1 file changed +8
-4
lines changed
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
- var parseUrl = require ( 'url' ) . parse ;
4
-
5
3
var DEFAULT_PORTS = {
6
4
ftp : 21 ,
7
5
gopher : 70 ,
@@ -17,12 +15,18 @@ var stringEndsWith = String.prototype.endsWith || function(s) {
17
15
} ;
18
16
19
17
/**
20
- * @param {string|object } url - The URL, or the result from url.parse .
18
+ * @param {string|URL } url - The URL, as a string or as URL object .
21
19
* @return {string } The URL of the proxy that should handle the request to the
22
20
* given URL. If no proxy is set, this will be an empty string.
23
21
*/
24
22
function getProxyForUrl ( url ) {
25
- var parsedUrl = typeof url === 'string' ? parseUrl ( url ) : url || { } ;
23
+ var parsedUrl = url || { } ;
24
+ try {
25
+ if ( typeof url === 'string' )
26
+ parsedUrl = new URL ( url ) ;
27
+ } catch ( err ) {
28
+ return '' ;
29
+ }
26
30
var proto = parsedUrl . protocol ;
27
31
var hostname = parsedUrl . host ;
28
32
var port = parsedUrl . port ;
You can’t perform that action at this time.
0 commit comments