Merge branch 'master' of github.com:nodejitsu/node-http-proxy

This commit is contained in:
Marak Squires 2011-12-05 14:20:32 -08:00
commit f086692619
3 changed files with 14 additions and 12 deletions

View File

@ -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`

View File

@ -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);

View File

@ -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);
}
};
};