mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[fix] properly include port in host header with changeOrigin in all cases fixes #750
This commit is contained in:
parent
81874f795b
commit
501e8c2a9b
@ -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(':');
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user