From 808e1761ef4430ee8c5df91e4eb179df12b0ee41 Mon Sep 17 00:00:00 2001 From: kybernetikos Date: Mon, 10 Jun 2013 16:41:13 +0100 Subject: [PATCH] Make the proxy request use the correct protocol (http/https). I discovered that the proxy request was using http even when it was proxying to an https port / url. This is because we didn't pass the https parameter through in the proxyRequest method. --- lib/cors-anywhere.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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 }); } };