diff --git a/lib/cors-anywhere.js b/lib/cors-anywhere.js index 5890a71..2752231 100644 --- a/lib/cors-anywhere.js +++ b/lib/cors-anywhere.js @@ -130,7 +130,7 @@ var getHandler = exports.getHandler = function(options) { return; } else { // Actual request. First, extract the desired URL from the request: - var full_url, host, hostname, port, path, match; + var full_url, host, hostname, port, path, match, isHttps; match = req.url.match(/^\/?(?:(https?:)?\/\/)?(([^\/?]+?)(?::(\d{0,5})(?=[\/?]|$))?)([\/?][\S\s]*|$)/i); // ^^^^^^^ ^^^^^^^^ ^^^^^^^ ^^^^^^^^^^^^ // 1:protocol 3:hostname 4:port 5:path + query string @@ -164,10 +164,11 @@ var getHandler = exports.getHandler = function(options) { return; } else { full_url = match[0].substr(1); + isHttps = (match[1] && match[1].toLowerCase()) === 'https:'; host = match[2]; hostname = match[3]; // Read port from input: : / 443 if https / 80 by default - port = match[4] ? +match[4] : (match[1] && match[1].toLowerCase() === 'https:' ? 443 : 80); + port = match[4] ? +match[4] : (isHttps ? 443 : 80); path = match[5]; if (!match[1]) { @@ -187,7 +188,8 @@ var getHandler = exports.getHandler = function(options) { proxyRequest(req, res, proxy, full_url, { host: hostname, - port: port + port: port, + https: isHttps }); } };