[fix] properly include port in host header with changeOrigin in all cases fixes #750

This commit is contained in:
Jarrett Cruger 2014-12-08 16:14:16 -05:00
parent 81874f795b
commit 501e8c2a9b

View File

@ -1,6 +1,7 @@
var common = exports,
url = require('url'),
extend = require('util')._extend;
var common = exports,
url = require('url'),
extend = require('util')._extend,
required = require('requires-port');
var upgradeHeader = /(^|,)\s*upgrade\s*($|,)/i;
/**
@ -74,9 +75,11 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
outgoing.path = common.urlJoin(targetPath, outgoingPath);
if (options.changeOrigin) {
outgoing.headers.host = outgoing.host;
outgoing.headers.host =
required(outgoing.port, options[forward || 'target'].protocol) && !hasPort(outgoing.host)
? outgoing.host + ':' + outgoing.port
: outgoing.host;
}
return outgoing;
};
@ -161,3 +164,14 @@ common.urlJoin = function() {
return retSegs.join('?')
};
/**
* Check the host and see if it potentially has a port in it (keep it simple)
*
* @returns {Boolean} Whether we have one or not
*
* @api private
*/
function hasPort(host) {
return !!~host.indexOf(':');
};