diff --git a/lib/http-proxy/common.js b/lib/http-proxy/common.js index abf182c..d532396 100644 --- a/lib/http-proxy/common.js +++ b/lib/http-proxy/common.js @@ -102,17 +102,36 @@ common.setupSocket = function(socket) { return socket; }; +/** + * Get the port number from the host. Or guess it based on the connection type. + * + * @param {Request} req Incoming HTTP request. + * + * @return {String} The port number. + * + * @api private + */ common.getPort = function(req) { - var res = req.headers.host ? req.headers.host.match(/:(\d+)/) : ""; + var res = req.headers.host ? req.headers.host.match(/:(\d+)/) : ''; + return res ? res[1] : - req.connection.pair ? '443' : '80' ; + req.connection.pair ? '443' : '80'; }; -// OS-agnostic join (doesn't break on URLs like path.join does on Windows) +/** + * OS-agnostic join (doesn't break on URLs like path.join does on Windows)> + * + * @return {String} The generated path. + * + * @api private + */ + common.urlJoin = function() { var args = Array.prototype.slice.call(arguments); - // Join all strings, but remove empty strings so we don't get extra slashes from + // Join all strings, but remove empty strings so we don't get extra slashes from // joining e.g. ['', 'am'] - return args.filter(function(a) { return !!a; }).join('/').replace(/\/+/g, '/'); + return args.filter(function filter(a) { + return !!a; + }).join('/').replace(/\/+/g, '/'); };