diff --git a/lib/node-http-proxy.js b/lib/node-http-proxy.js index 7b3d3be..c0c85a5 100644 --- a/lib/node-http-proxy.js +++ b/lib/node-http-proxy.js @@ -57,6 +57,7 @@ var HttpProxy = exports.HttpProxy = require('./node-http-proxy/http-proxy' exports.createServer = function () { var args = Array.prototype.slice.call(arguments), handlers = [], + callback, options = {}, message, handler, @@ -77,7 +78,7 @@ exports.createServer = function () { case 'string': host = arg; break; case 'number': port = arg; break; case 'object': options = arg || {}; break; - case 'function': handlers.push(arg); break; + case 'function': callback = arg; handlers.push(callback); break; }; }); @@ -180,7 +181,7 @@ exports.createServer = function () { proxy.close(); }); - if (handlers.length <= 1) { + if (!callback) { // // If an explicit callback has not been supplied then // automagically proxy the request using the `HttpProxy` diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 8bbee09..127d65f 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -195,8 +195,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { outgoing.path = req.url; outgoing.headers = req.headers; - if(this.changeOrigin) - outgoing.headers.host = this.target.host + (this.target.port == 80 ? '' : ':' + this.target.port) // // Open new HTTP request to internal resource with will act // as a reverse proxy pass @@ -210,6 +208,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { else { response.headers.connection = 'close' } } + // Remove `Transfer-Encoding` header if client's protocol is HTTP/1.0 + if (req.httpVersion === '1.0') { + delete response.headers['transfer-encoding']; + } + // Set the headers of the client response res.writeHead(response.statusCode, response.headers); diff --git a/lib/node-http-proxy/proxy-table.js b/lib/node-http-proxy/proxy-table.js index 4ab6690..0cdce50 100644 --- a/lib/node-http-proxy/proxy-table.js +++ b/lib/node-http-proxy/proxy-table.js @@ -138,14 +138,12 @@ ProxyTable.prototype.getProxyLocation = function (req) { var route = this.routes[i]; if (target.match(route.route)) { - var segments = route.path.split('/'); + var pathSegments = route.path.split('/'); - if (segments.length > 0) { - var lastSegment = new RegExp("/" + segments[segments.length - 1] + "$"); - - if(req.url.match(lastSegment)) { - req.url = req.url.replace(lastSegment, '/'); - } + if (pathSegments.length > 1) { + // don't include the proxytable path segments in the proxied request url + pathSegments = new RegExp("/" + pathSegments.slice(1).join('/')); + req.url = req.url.replace(pathSegments, ''); } var location = route.target.split(':'), @@ -172,4 +170,4 @@ ProxyTable.prototype.close = function () { if (typeof this.routeFile === 'string') { fs.unwatchFile(this.routeFile); } -}; \ No newline at end of file +};