Skip to content

Commit 73381cf

Browse files
committed
[debug] Removed pool as a dependency for stress test
1 parent 266e524 commit 73381cf

File tree

1 file changed

+60
-55
lines changed

1 file changed

+60
-55
lines changed

Diff for: lib/node-http-proxy.js

+60-55
Original file line numberDiff line numberDiff line change
@@ -145,78 +145,83 @@ HttpProxy.prototype = {
145145
self.body = '';
146146

147147
// Open new HTTP request to internal resource with will act as a reverse proxy pass
148-
var p = manager.getPool(port, server);
149-
sys.puts('Current pool count for ' + req.headers.host + ":" + port + ' ' + p.clients.length + ', Busy: ' + p.getBusy() + ', Free: ' + p.getFree());
148+
//var p = manager.getPool(port, server);
149+
//sys.puts('Current pool count for ' + req.headers.host + ":" + port + ' ' + p.clients.length + ', Busy: ' + p.getBusy() + ', Free: ' + p.getFree());
150150

151-
p.on('error', function (err) {
151+
//p.on('error', function (err) {
152152
// Remark: We should probably do something here
153153
// but this is a hot-fix because I don't think 'pool'
154154
// should be emitting this event.
155-
});
155+
//});
156+
157+
var client = http.createClient(port, server);
158+
var reverse_proxy = client.request(req.method, req.url, req.headers);
156159

157-
p.request(req.method, req.url, req.headers, function (reverse_proxy) {
158-
// Create an error handler so we can use it temporarily
159-
var error = function (err) {
160-
res.writeHead(500, {'Content-Type': 'text/plain'});
160+
//p.request(req.method, req.url, req.headers, function (reverse_proxy) {
161161

162-
if(req.method !== 'HEAD') {
163-
res.write('An error has occurred: ' + JSON.stringify(err));
164-
}
165-
166-
// Response end may never come so removeListener here
167-
reverse_proxy.removeListener('error', error);
168-
res.end();
169-
};
162+
// Create an error handler so we can use it temporarily
163+
var error = function (err) {
164+
res.writeHead(500, {'Content-Type': 'text/plain'});
170165

171-
// Add a listener for the connection timeout event
172-
reverse_proxy.addListener('error', error);
166+
if(req.method !== 'HEAD') {
167+
res.write('An error has occurred: ' + JSON.stringify(err));
168+
}
169+
170+
// Response end may never come so removeListener here
171+
reverse_proxy.removeListener('error', error);
172+
res.end();
173+
};
173174

174-
// Add a listener for the reverse_proxy response event
175-
reverse_proxy.addListener('response', function (response) {
176-
if (response.headers.connection) {
177-
if (req.headers.connection) response.headers.connection = req.headers.connection;
178-
else response.headers.connection = 'close';
179-
}
175+
// Add a listener for the connection timeout event
176+
reverse_proxy.addListener('error', error);
180177

181-
// Set the response headers of the client response
182-
res.writeHead(response.statusCode, response.headers);
178+
// Add a listener for the reverse_proxy response event
179+
reverse_proxy.addListener('response', function (response) {
180+
if (response.headers.connection) {
181+
if (req.headers.connection) response.headers.connection = req.headers.connection;
182+
else response.headers.connection = 'close';
183+
}
183184

184-
// Status code = 304
185-
// No 'data' event and no 'end'
186-
if (response.statusCode === 304) {
187-
res.end();
188-
return;
189-
}
185+
// Set the response headers of the client response
186+
res.writeHead(response.statusCode, response.headers);
190187

191-
// Add event handler for the proxied response in chunks
192-
response.addListener('data', function (chunk) {
193-
if(req.method !== 'HEAD') {
194-
res.write(chunk, 'binary');
195-
self.body += chunk;
196-
}
197-
});
188+
// Status code = 304
189+
// No 'data' event and no 'end'
190+
if (response.statusCode === 304) {
191+
res.end();
192+
return;
193+
}
198194

199-
// Add event listener for end of proxied response
200-
response.addListener('end', function () {
201-
// Remark: Emit the end event for testability
202-
self.emitter.emit('proxy', null, self.body);
203-
reverse_proxy.removeListener('error', error);
204-
res.end();
205-
});
195+
// Add event handler for the proxied response in chunks
196+
response.addListener('data', function (chunk) {
197+
if(req.method !== 'HEAD') {
198+
res.write(chunk, 'binary');
199+
self.body += chunk;
200+
}
206201
});
207202

208-
// Chunk the client request body as chunks from the proxied request come in
209-
req.addListener('data', function (chunk) {
210-
reverse_proxy.write(chunk, 'binary');
211-
})
212-
213-
// At the end of the client request, we are going to stop the proxied request
214-
req.addListener('end', function () {
215-
reverse_proxy.end();
203+
// Add event listener for end of proxied response
204+
response.addListener('end', function () {
205+
// Remark: Emit the end event for testability
206+
self.emitter.emit('proxy', null, self.body);
207+
reverse_proxy.removeListener('error', error);
208+
res.end();
216209
});
210+
});
217211

218-
self.unwatch(req);
212+
// Chunk the client request body as chunks from the proxied request come in
213+
req.addListener('data', function (chunk) {
214+
reverse_proxy.write(chunk, 'binary');
215+
})
216+
217+
// At the end of the client request, we are going to stop the proxied request
218+
req.addListener('end', function () {
219+
reverse_proxy.end();
219220
});
221+
222+
self.unwatch(req);
223+
224+
//});
220225
},
221226

222227
proxyWebSocketRequest: function (port, server, host) {

0 commit comments

Comments
 (0)