[fix] Optimize fix for x-forwarded-for-port.

This commit is contained in:
indexzero 2013-12-26 23:59:48 -08:00
parent d4e91ebc33
commit 2d42709c32

View File

@ -30,6 +30,13 @@ var events = require('events'),
url = require('url'),
httpProxy = require('../node-http-proxy');
//
// @private {RegExp} extractPort
// Reusable regular expression for getting the
// port from a host string.
//
var extractPort = /:(\d+)$/;
//
// ### function HttpProxy (options)
// #### @options {Object} Options for this instance.
@ -957,14 +964,12 @@ HttpProxy.prototype._forwardRequest = function (req) {
};
function getPortFromHostHeader(req) {
var portMatch = req.headers.host.match(/:(\d+)$/);
var match;
if ((match = extractPort.exec(req.headers.host))) {
return parseInt(match[1]);
}
if(portMatch) {
return parseInt(portMatch[1]);
}
else {
return getProto(req) === 'https' ? 443 : 80;
}
return getProto(req) === 'https' ? 443 : 80;
}
function getProto(req) {