Skip to content

Commit 45c4b85

Browse files
committed
Switch to WHATWG URL
Fixes #4
1 parent 095d1c2 commit 45c4b85

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

index.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
var parseUrl = require('url').parse;
4-
53
var DEFAULT_PORTS = {
64
ftp: 21,
75
gopher: 70,
@@ -17,12 +15,18 @@ var stringEndsWith = String.prototype.endsWith || function(s) {
1715
};
1816

1917
/**
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.
2119
* @return {string} The URL of the proxy that should handle the request to the
2220
* given URL. If no proxy is set, this will be an empty string.
2321
*/
2422
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+
}
2630
var proto = parsedUrl.protocol;
2731
var hostname = parsedUrl.host;
2832
var port = parsedUrl.port;

0 commit comments

Comments
 (0)