Skip to content

Commit

Permalink
[fix] Optimize fix for x-forwarded-for-port.
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Dec 27, 2013
1 parent d4e91eb commit 2d42709
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/node-http-proxy/http-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -957,14 +964,12 @@ HttpProxy.prototype._forwardRequest = function (req) {
};

function getPortFromHostHeader(req) {
var portMatch = req.headers.host.match(/:(\d+)$/);

if(portMatch) {
return parseInt(portMatch[1]);
}
else {
return getProto(req) === 'https' ? 443 : 80;
var match;
if ((match = extractPort.exec(req.headers.host))) {
return parseInt(match[1]);
}

return getProto(req) === 'https' ? 443 : 80;
}

function getProto(req) {
Expand Down

0 comments on commit 2d42709

Please sign in to comment.