Skip to content

Commit 026e0ae

Browse files
committed
Strip out debugging logic.
1 parent 89662f9 commit 026e0ae

File tree

3 files changed

+5
-88
lines changed

3 files changed

+5
-88
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ server.listen(8080);
521521

522522
### Configuring your Socket limits
523523

524-
By default, `node-http-proxy` will set a 100 socket limit for all `host:port` proxy targets. You can change this in two ways:
524+
By default, `node-http-proxy` will set a 200 socket limit for all `host:port` proxy targets. You can change this in two ways:
525525

526526
1. By passing the `maxSockets` option to `httpProxy.createServer()`
527527
2. By calling `httpProxy.setMaxSockets(n)`, where `n` is the number of sockets you with to use.

lib/node-http-proxy.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
var util = require('util'),
2828
http = require('http'),
2929
events = require('events'),
30-
maxSockets = 500;
30+
maxSockets = 200;
3131

3232
//
3333
// Expose version information through `pkginfo`.

lib/node-http-proxy/http-proxy.js

+3-86
Original file line numberDiff line numberDiff line change
@@ -103,43 +103,13 @@ var HttpProxy = exports.HttpProxy = function (options) {
103103
// Inherit from events.EventEmitter
104104
util.inherits(HttpProxy, events.EventEmitter);
105105

106-
function ReqCanary(){
107-
this.___events = [];
108-
}
109-
function ResCanary(){
110-
this.___events = [];
111-
}
112-
113-
var cc = {};
114-
115-
var logEvt = function(canary, event){
116-
if (canary && canary.___events){
117-
canary.___events.push(event);
118-
} else{
119-
console.log("No canary for event : " + event);
120-
}
121-
122-
if (!cc[event]){
123-
cc[event] = 1;
124-
} else{
125-
cc[event]+=1;
126-
}
127-
128-
console.dir(cc);
129-
}
130-
131106
//
132107
// ### function proxyRequest (req, res, buffer)
133108
// #### @req {ServerRequest} Incoming HTTP Request to proxy.
134109
// #### @res {ServerResponse} Outgoing HTTP Request to write proxied data to.
135110
// #### @buffer {Object} Result from `httpProxy.buffer(req)`
136111
//
137112
HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
138-
req.canary = new ReqCanary();
139-
res.canary = new ResCanary();
140-
141-
logEvt(res.canary, "Init");
142-
143113
var self = this,
144114
errState = false,
145115
outgoing = new(this.target.base),
@@ -196,8 +166,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
196166
//
197167
this.emit('start', req, res, this.target);
198168

199-
logEvt(res.canary, "Start");
200-
201169
//
202170
// #### function proxyError (err)
203171
// #### @err {Error} Error contacting the proxy target
@@ -207,8 +175,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
207175
function proxyError(err) {
208176
errState = true;
209177

210-
logEvt(res.canary, "ProxyError");
211-
212178
//
213179
// Emit an `error` event, allowing the application to use custom
214180
// error handling. The error handler should end the response.
@@ -217,8 +183,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
217183
return;
218184
}
219185

220-
logEvt(res.canary, "Writing 500");
221-
222186
res.writeHead(500, { 'Content-Type': 'text/plain' });
223187

224188
if (req.method !== 'HEAD') {
@@ -236,20 +200,15 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
236200

237201
try {
238202
res.end();
239-
logEvt(res.canary, "Ended properly");
240-
//CLEANUP
203+
241204
if (res){
242205
res.removeAllListeners();
243206
res = null;
244207
}
245208
if (req){
246209
req.removeAllListeners();
247210
req = null;
248-
}
249-
if (response){
250-
response.removeAllListeners();
251-
response = null;
252-
}
211+
}
253212
}
254213
catch (ex) { console.error("res.end error: %s", ex.message) }
255214
}
@@ -272,9 +231,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
272231
// as a reverse proxy pass
273232
//
274233
reverseProxy = this.target.protocol.request(outgoing, function (response) {
275-
276-
logEvt(res.canary, "Reverse proxying");
277-
278234
//
279235
// Process the `reverseProxy` `response` when it's received.
280236
//
@@ -300,7 +256,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
300256
//
301257
var ended = false;
302258
response.on('close', function () {
303-
logEvt(res.canary, "Close, emiting 'end'");
304259
if (!ended) { response.emit('end') }
305260
});
306261

@@ -312,47 +267,25 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
312267
// This code makes sure that we flush pending data.
313268
//
314269
response.connection.on('end', function () {
315-
if (res)
316-
logEvt(res.canary, 'response connection ended');
317270

318271
if (response && response.readable && response.resume) {
319-
if (res)
320-
logEvt(res.canary, 'response resuming');
321-
322272
response.resume();
323273
}
324-
// CLEANUP?
325-
if (res){
326-
res.removeAllListeners();
327-
res = null;
328-
}
329-
if (req){
330-
req.removeAllListeners();
331-
req = null;
332-
}
333274
if (response){
334275
response.removeAllListeners();
335276
response = null;
336277
}
337278
});
338279

339280
response.on('end', function () {
340-
logEvt(res.canary, 'response ended');
341281
ended = true;
342282
if (!errState) {
343283
try {
344-
res.end();
345-
logEvt(res.canary, 'end res');
346-
// CLEANUP?
284+
res.end();
347285
res.removeAllListeners();
348-
// Note that nulling this will prevent the response resuming' event from
349-
// coming in, since it won't fire on a null event.
350286
res = null;
351287
req.removeAllListeners();
352288
req = null;
353-
response.removeAllListeners();
354-
response = null;
355-
356289
}
357290
catch (ex) { console.error("res.end error: %s", ex.message) }
358291

@@ -375,15 +308,13 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
375308
res.writeHead(response.statusCode);
376309

377310
function ondata(chunk) {
378-
logEvt(res.canary, "Data");
379311
if (res.writable) {
380312
// Only pause if the underlying buffers are full,
381313
// *and* the connection is not in 'closing' state.
382314
// Otherwise, the pause will cause pending data to
383315
// be discarded and silently lost.
384316
if (false === res.write(chunk) && response.pause
385317
&& response.connection.readable) {
386-
logEvt(res.canary, "Pausing due to full buffer");
387318
response.pause();
388319
}
389320
}
@@ -392,9 +323,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
392323
response.on('data', ondata);
393324

394325
function ondrain() {
395-
logEvt(res.canary, "On drain");
396326
if (response.readable && response.resume) {
397-
logEvt(res.canary, "On drain resuming.");
398327
response.resume();
399328
}
400329
}
@@ -412,7 +341,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
412341

413342
// Set a timeout on the socket if `this.timeout` is specified.
414343
reverseProxy.once('socket', function (socket) {
415-
logEvt(res.canary, "Socket");
416344
if (self.timeout) {
417345
socket.setTimeout(self.timeout);
418346
}
@@ -427,7 +355,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
427355
// If `req` is aborted, we abort our `reverseProxy` request as well.
428356
//
429357
req.on('aborted', function () {
430-
logEvt(res.canary, "Aborted");
431358
reverseProxy.abort();
432359
});
433360

@@ -436,13 +363,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
436363
// `req` write it to the `reverseProxy` request.
437364
//
438365
req.on('data', function (chunk) {
439-
logEvt(res.canary, 'req data');
440366
if (!errState) {
441367
var flushed = reverseProxy.write(chunk);
442368
if (!flushed) {
443369
req.pause();
444370
reverseProxy.once('drain', function () {
445-
logEvt(res.canary, "Drain");
446371
try { req.resume() }
447372
catch (er) { console.error("req.resume error: %s", er.message) }
448373
});
@@ -452,7 +377,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
452377
// happened on its own.
453378
//
454379
setTimeout(function () {
455-
logEvt(res.canary, "Force drain");
456380
reverseProxy.emit('drain');
457381
}, 100);
458382
}
@@ -464,29 +388,22 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
464388
// request unless we have entered an error state.
465389
//
466390
req.on('end', function () {
467-
logEvt(res.canary, "Req ended");
468391
if (!errState) {
469392
reverseProxy.end();
470-
} else{
471-
logEvt(res.canary, "Req errored end");
472393
}
473394
});
474395

475396
//Aborts reverseProxy if client aborts the connection.
476397
req.on('close', function () {
477-
logEvt(res.canary, "Req closed");
478398
if (!errState) {
479399
reverseProxy.abort();
480-
} else {
481-
logEvt(res.canary, "Req errored close");
482400
}
483401
});
484402

485403
//
486404
// If we have been passed buffered data, resume it.
487405
//
488406
if (buffer) {
489-
logEvt(res.canary, "Resuming buffer " + errState ? "1" : "0");
490407
return !errState
491408
? buffer.resume()
492409
: buffer.destroy();

0 commit comments

Comments
 (0)