mirror of
https://github.com/d0zingcat/cors-anywhere.git
synced 2026-05-13 23:16:51 +00:00
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.
This commit is contained in:
@@ -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: :<port> / 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
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user