Skip to content

Commit

Permalink
Attempting to make proxy work with Proxy starting SSL connection (not…
Browse files Browse the repository at this point in the history
… HTTP CONNECT)
  • Loading branch information
ozten committed Apr 23, 2013
1 parent 18f86e3 commit 4d84cae
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions openid.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,12 @@ var _proxyRequest = function(protocol, options)
export HTTP_PROXY_PORT=8080
export HTTPS_PROXY_HOST=localhost
export HTTPS_PROXY_PORT=8442
Function returns protocol which should be used for network request, one of
http: or https:
*/
var targetHost = options.host;
var newProtocol = protocol;
if (!targetHost) return;
var updateOptions = function (envPrefix) {
var proxyHostname = process.env[envPrefix + '_PROXY_HOST'].trim();
Expand All @@ -195,10 +199,14 @@ var _proxyRequest = function(protocol, options)
!! process.env['HTTPS_PROXY_HOST'] &&
!! process.env['HTTPS_PROXY_PORT']) {
updateOptions('HTTPS');
// Proxy server request must be done via http... it is responsible for
// Making the https request...
newProtocol = 'http:';
} else if (!! process.env['HTTP_PROXY_HOST'] &&
!! process.env['HTTP_PROXY_PORT']) {
updateOptions('HTTP');
}
return newProtocol;
}

var _get = function(getUrl, params, callback, redirects)
Expand All @@ -220,9 +228,9 @@ var _get = function(getUrl, params, callback, redirects)
path: path
};

_proxyRequest(getUrl.protocol, options);
var protocol = _proxyRequest(getUrl.protocol, options);

(getUrl.protocol == 'https:' ? https : http).get(options, function(res)
(protocol == 'https:' ? https : http).get(options, function(res)
{
var data = '';
res.on('data', function(chunk)
Expand Down Expand Up @@ -281,9 +289,9 @@ var _post = function(postUrl, data, callback, redirects)
method: 'POST'
};

_proxyRequest(postUrl.protocol, options);
var protocol = _proxyRequest(postUrl.protocol, options);

(postUrl.protocol == 'https:' ? https : http).request(options, function(res)
(protocol == 'https:' ? https : http).request(options, function(res)
{
var data = '';
res.on('data', function(chunk)
Expand Down

0 comments on commit 4d84cae

Please sign in to comment.