Skip to content

Commit

Permalink
[fix] properly include port in host header with changeOrigin in all c…
Browse files Browse the repository at this point in the history
…ases fixes #750
  • Loading branch information
jcrugzz committed Dec 8, 2014
1 parent 81874f7 commit 501e8c2
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions lib/http-proxy/common.js
Original file line number Diff line number Diff line change
@@ -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;
/**
Expand Down Expand Up @@ -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;
};

Expand Down Expand Up @@ -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(':');
};

0 comments on commit 501e8c2

Please sign in to comment.