mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
[debug] Removed pool as a dependency for stress test
This commit is contained in:
parent
266e5246ea
commit
73381cf71a
@ -145,78 +145,83 @@ HttpProxy.prototype = {
|
||||
self.body = '';
|
||||
|
||||
// Open new HTTP request to internal resource with will act as a reverse proxy pass
|
||||
var p = manager.getPool(port, server);
|
||||
sys.puts('Current pool count for ' + req.headers.host + ":" + port + ' ' + p.clients.length + ', Busy: ' + p.getBusy() + ', Free: ' + p.getFree());
|
||||
//var p = manager.getPool(port, server);
|
||||
//sys.puts('Current pool count for ' + req.headers.host + ":" + port + ' ' + p.clients.length + ', Busy: ' + p.getBusy() + ', Free: ' + p.getFree());
|
||||
|
||||
p.on('error', function (err) {
|
||||
//p.on('error', function (err) {
|
||||
// Remark: We should probably do something here
|
||||
// but this is a hot-fix because I don't think 'pool'
|
||||
// should be emitting this event.
|
||||
});
|
||||
//});
|
||||
|
||||
var client = http.createClient(port, server);
|
||||
var reverse_proxy = client.request(req.method, req.url, req.headers);
|
||||
|
||||
p.request(req.method, req.url, req.headers, function (reverse_proxy) {
|
||||
// Create an error handler so we can use it temporarily
|
||||
var error = function (err) {
|
||||
res.writeHead(500, {'Content-Type': 'text/plain'});
|
||||
//p.request(req.method, req.url, req.headers, function (reverse_proxy) {
|
||||
|
||||
// Create an error handler so we can use it temporarily
|
||||
var error = function (err) {
|
||||
res.writeHead(500, {'Content-Type': 'text/plain'});
|
||||
|
||||
if(req.method !== 'HEAD') {
|
||||
res.write('An error has occurred: ' + JSON.stringify(err));
|
||||
}
|
||||
|
||||
// Response end may never come so removeListener here
|
||||
reverse_proxy.removeListener('error', error);
|
||||
res.end();
|
||||
};
|
||||
|
||||
// Add a listener for the connection timeout event
|
||||
reverse_proxy.addListener('error', error);
|
||||
|
||||
// Add a listener for the reverse_proxy response event
|
||||
reverse_proxy.addListener('response', function (response) {
|
||||
if (response.headers.connection) {
|
||||
if (req.headers.connection) response.headers.connection = req.headers.connection;
|
||||
else response.headers.connection = 'close';
|
||||
}
|
||||
|
||||
// Set the response headers of the client response
|
||||
res.writeHead(response.statusCode, response.headers);
|
||||
|
||||
// Status code = 304
|
||||
// No 'data' event and no 'end'
|
||||
if (response.statusCode === 304) {
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
// Add event handler for the proxied response in chunks
|
||||
response.addListener('data', function (chunk) {
|
||||
if(req.method !== 'HEAD') {
|
||||
res.write('An error has occurred: ' + JSON.stringify(err));
|
||||
res.write(chunk, 'binary');
|
||||
self.body += chunk;
|
||||
}
|
||||
|
||||
// Response end may never come so removeListener here
|
||||
});
|
||||
|
||||
// Add event listener for end of proxied response
|
||||
response.addListener('end', function () {
|
||||
// Remark: Emit the end event for testability
|
||||
self.emitter.emit('proxy', null, self.body);
|
||||
reverse_proxy.removeListener('error', error);
|
||||
res.end();
|
||||
};
|
||||
|
||||
// Add a listener for the connection timeout event
|
||||
reverse_proxy.addListener('error', error);
|
||||
|
||||
// Add a listener for the reverse_proxy response event
|
||||
reverse_proxy.addListener('response', function (response) {
|
||||
if (response.headers.connection) {
|
||||
if (req.headers.connection) response.headers.connection = req.headers.connection;
|
||||
else response.headers.connection = 'close';
|
||||
}
|
||||
|
||||
// Set the response headers of the client response
|
||||
res.writeHead(response.statusCode, response.headers);
|
||||
|
||||
// Status code = 304
|
||||
// No 'data' event and no 'end'
|
||||
if (response.statusCode === 304) {
|
||||
res.end();
|
||||
return;
|
||||
}
|
||||
|
||||
// Add event handler for the proxied response in chunks
|
||||
response.addListener('data', function (chunk) {
|
||||
if(req.method !== 'HEAD') {
|
||||
res.write(chunk, 'binary');
|
||||
self.body += chunk;
|
||||
}
|
||||
});
|
||||
|
||||
// Add event listener for end of proxied response
|
||||
response.addListener('end', function () {
|
||||
// Remark: Emit the end event for testability
|
||||
self.emitter.emit('proxy', null, self.body);
|
||||
reverse_proxy.removeListener('error', error);
|
||||
res.end();
|
||||
});
|
||||
});
|
||||
|
||||
// Chunk the client request body as chunks from the proxied request come in
|
||||
req.addListener('data', function (chunk) {
|
||||
reverse_proxy.write(chunk, 'binary');
|
||||
})
|
||||
|
||||
// At the end of the client request, we are going to stop the proxied request
|
||||
req.addListener('end', function () {
|
||||
reverse_proxy.end();
|
||||
});
|
||||
|
||||
self.unwatch(req);
|
||||
});
|
||||
|
||||
// Chunk the client request body as chunks from the proxied request come in
|
||||
req.addListener('data', function (chunk) {
|
||||
reverse_proxy.write(chunk, 'binary');
|
||||
})
|
||||
|
||||
// At the end of the client request, we are going to stop the proxied request
|
||||
req.addListener('end', function () {
|
||||
reverse_proxy.end();
|
||||
});
|
||||
|
||||
self.unwatch(req);
|
||||
|
||||
//});
|
||||
},
|
||||
|
||||
proxyWebSocketRequest: function (port, server, host) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user