Skip to content

Commit 5f14bca

Browse files
author
Jeremy Judeaux
committed
fix protocol and default port detection on node 0.12.x, compatible with 0.10.x
1 parent 0ee314c commit 5f14bca

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

lib/http-proxy/common.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,20 @@ common.getPort = function(req) {
134134

135135
return res ?
136136
res[1] :
137-
req.connection.pair ? '443' : '80';
137+
common.hasEncryptedConnection(req) ? '443' : '80';
138+
};
139+
140+
/**
141+
* Check if the request has an encrypted connection.
142+
*
143+
* @param {Request} req Incoming HTTP request.
144+
*
145+
* @return {Boolean} Whether the connection is encrypted or not.
146+
*
147+
* @api private
148+
*/
149+
common.hasEncryptedConnection = function(req) {
150+
return Boolean(req.connection.encrypted || req.connection.pair);
138151
};
139152

140153
/**

lib/http-proxy/passes/web-incoming.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ web_o = Object.keys(web_o).map(function(pass) {
6464
function XHeaders(req, res, options) {
6565
if(!options.xfwd) return;
6666

67-
var encrypted = req.isSpdy || req.connection.encrypted || req.connection.pair;
67+
var encrypted = req.isSpdy || common.hasEncryptedConnection(req);
6868
var values = {
6969
for : req.connection.remoteAddress || req.socket.remoteAddress,
7070
port : common.getPort(req),

lib/http-proxy/passes/ws-incoming.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ var passes = exports;
5757
var values = {
5858
for : req.connection.remoteAddress || req.socket.remoteAddress,
5959
port : common.getPort(req),
60-
proto: req.connection.pair ? 'wss' : 'ws'
60+
proto: common.hasEncryptedConnection(req) ? 'wss' : 'ws'
6161
};
6262

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

0 commit comments

Comments
 (0)