Skip to content

Commit

Permalink
fix protocol and default port detection on node 0.12.x, compatible wi…
Browse files Browse the repository at this point in the history
…th 0.10.x
  • Loading branch information
Jeremy Judeaux committed Apr 2, 2015
1 parent 0ee314c commit 5f14bca
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/http-proxy/common.js
Expand Up @@ -134,7 +134,20 @@ common.getPort = function(req) {

return res ?
res[1] :
req.connection.pair ? '443' : '80';
common.hasEncryptedConnection(req) ? '443' : '80';
};

/**
* Check if the request has an encrypted connection.
*
* @param {Request} req Incoming HTTP request.
*
* @return {Boolean} Whether the connection is encrypted or not.
*
* @api private
*/
common.hasEncryptedConnection = function(req) {
return Boolean(req.connection.encrypted || req.connection.pair);
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/http-proxy/passes/web-incoming.js
Expand Up @@ -64,7 +64,7 @@ web_o = Object.keys(web_o).map(function(pass) {
function XHeaders(req, res, options) {
if(!options.xfwd) return;

var encrypted = req.isSpdy || req.connection.encrypted || req.connection.pair;
var encrypted = req.isSpdy || common.hasEncryptedConnection(req);
var values = {
for : req.connection.remoteAddress || req.socket.remoteAddress,
port : common.getPort(req),
Expand Down
2 changes: 1 addition & 1 deletion lib/http-proxy/passes/ws-incoming.js
Expand Up @@ -57,7 +57,7 @@ var passes = exports;
var values = {
for : req.connection.remoteAddress || req.socket.remoteAddress,
port : common.getPort(req),
proto: req.connection.pair ? 'wss' : 'ws'
proto: common.hasEncryptedConnection(req) ? 'wss' : 'ws'
};

['for', 'port', 'proto'].forEach(function(header) {
Expand Down

0 comments on commit 5f14bca

Please sign in to comment.