Skip to content

Commit

Permalink
Switch to WHATWG URL
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
orgads committed Nov 17, 2021
1 parent 96d01f8 commit a9f91e5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict';

var parseUrl = require('url').parse;

var DEFAULT_PORTS = {
ftp: 21,
gopher: 70,
Expand All @@ -17,12 +15,18 @@ var stringEndsWith = String.prototype.endsWith || function(s) {
};

/**
* @param {string|object} url - The URL, or the result from url.parse.
* @param {string|URL} url - The URL, as a string or as URL object.
* @return {string} The URL of the proxy that should handle the request to the
* given URL. If no proxy is set, this will be an empty string.
*/
function getProxyForUrl(url) {
var parsedUrl = typeof url === 'string' ? parseUrl(url) : url || {};
var parsedUrl = url || {};
try {
if (typeof url === 'string')
parsedUrl = new URL(url);
} catch (err) {
return '';
}
var proto = parsedUrl.protocol;
var hostname = parsedUrl.host;
var port = parsedUrl.port;
Expand Down

0 comments on commit a9f91e5

Please sign in to comment.