mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Merge branch 'master' of github.com:nodejitsu/node-http-proxy
This commit is contained in:
commit
f086692619
@ -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`
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user