Commit 5575bcf6 authored by indexzero's avatar indexzero

[minor] Remove commented out debug statements.

parent 558a8a4f
...@@ -349,6 +349,7 @@ HttpProxy.prototype.buffer = function (obj) { ...@@ -349,6 +349,7 @@ HttpProxy.prototype.buffer = function (obj) {
this.resume = function () { this.resume = function () {
console.error("Cannot resume buffer after destroying it."); console.error("Cannot resume buffer after destroying it.");
}; };
onData = onEnd = events = obj = null; onData = onEnd = events = obj = null;
}, },
resume: function () { resume: function () {
...@@ -414,9 +415,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) { ...@@ -414,9 +415,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
try { try {
res.writeHead(404); res.writeHead(404);
res.end(); res.end();
} catch (er) { }
catch (er) {
console.error("res.writeHead/res.end error: %s", er.message); console.error("res.writeHead/res.end error: %s", er.message);
} }
return; return;
} }
...@@ -492,11 +495,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) { ...@@ -492,11 +495,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
} }
} }
try { try { res.end() }
res.end(); catch (er) { console.error("res.end error: %s", er.message) }
} catch (er) {
console.error("res.end error: %s", er.message);
}
} }
outgoing = { outgoing = {
...@@ -524,11 +524,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) { ...@@ -524,11 +524,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
// `response.statusCode === 304`: No 'data' event and no 'end' // `response.statusCode === 304`: No 'data' event and no 'end'
if (response.statusCode === 304) { if (response.statusCode === 304) {
try { try { res.end() }
res.end(); catch (er) { console.error("res.end error: %s", er.message) }
} catch (er) {
console.error("res.end error: %s", er.message)
}
return; return;
} }
...@@ -540,26 +537,24 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) { ...@@ -540,26 +537,24 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
if (req.method !== 'HEAD' && res.writable) { if (req.method !== 'HEAD' && res.writable) {
try { try {
var flushed = res.write(chunk); var flushed = res.write(chunk);
} catch (er) {
console.error("res.write error: %s", er.message);
try {
res.end();
} catch (er) {
console.error("res.end error: %s", er.message);
} }
catch (er) {
console.error("res.write error: %s", er.message);
try { res.end() }
catch (er) { console.error("res.end error: %s", er.message) }
return; return;
} }
} }
if (!flushed) { if (!flushed) {
//console.error('backpressure 554');
response.pause(); response.pause();
res.once('drain', function () { res.once('drain', function () {
try { try { response.resume() }
response.resume(); catch (er) { console.error("response.resume error: %s", er.message) }
} catch (er) {
console.error("response.resume error: %s", er.message);
}
}); });
setTimeout(function () { setTimeout(function () {
res.emit('drain'); res.emit('drain');
}, 100); }, 100);
...@@ -574,11 +569,9 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) { ...@@ -574,11 +569,9 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
response.on('end', function () { response.on('end', function () {
if (!errState) { if (!errState) {
reverseProxy.removeListener('error', proxyError); reverseProxy.removeListener('error', proxyError);
try {
res.end(); try { res.end() }
} catch (er) { catch (er) { console.error("res.end error: %s", er.message) }
console.error("res.end error: %s", er.message);
}
// Emit the `end` event now that we have completed proxying // Emit the `end` event now that we have completed proxying
self.emit('end', req, res); self.emit('end', req, res);
...@@ -595,15 +588,13 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) { ...@@ -595,15 +588,13 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
if (!errState) { if (!errState) {
var flushed = reverseProxy.write(chunk); var flushed = reverseProxy.write(chunk);
if (!flushed) { if (!flushed) {
//console.error('backpressure 594');
req.pause(); req.pause();
reverseProxy.once('drain', function () { reverseProxy.once('drain', function () {
try { try { req.resume() }
req.resume(); catch (er) { console.error("req.resume error: %s", er.message) }
} catch (er) {
console.error("req.resume error: %s", er.message);
}
}); });
setTimeout(function () { setTimeout(function () {
reverseProxy.emit('drain'); reverseProxy.emit('drain');
}, 100); }, 100);
...@@ -625,7 +616,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) { ...@@ -625,7 +616,8 @@ HttpProxy.prototype.proxyRequest = function (req, res, options) {
if (options.buffer) { if (options.buffer) {
if (!errState) { if (!errState) {
options.buffer.resume(); options.buffer.resume();
} else { }
else {
options.buffer.destroy(); options.buffer.destroy();
} }
} }
...@@ -677,15 +669,13 @@ HttpProxy.prototype._forwardRequest = function (req) { ...@@ -677,15 +669,13 @@ HttpProxy.prototype._forwardRequest = function (req) {
req.on('data', function (chunk) { req.on('data', function (chunk) {
var flushed = forwardProxy.write(chunk); var flushed = forwardProxy.write(chunk);
if (!flushed) { if (!flushed) {
//console.error('backpressure 672');
req.pause(); req.pause();
forwardProxy.once('drain', function () { forwardProxy.once('drain', function () {
try { try { req.resume() }
req.resume(); catch (er) { console.error("req.resume error: %s", er.message) }
} catch (er) {
console.error("req.resume error: %s", er.message);
}
}); });
setTimeout(function () { setTimeout(function () {
forwardProxy.emit('drain'); forwardProxy.emit('drain');
}, 100); }, 100);
...@@ -786,21 +776,19 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options ...@@ -786,21 +776,19 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
self.emit('websocket:outgoing', req, socket, head, data); self.emit('websocket:outgoing', req, socket, head, data);
var flushed = reverseProxy.incoming.socket.write(data); var flushed = reverseProxy.incoming.socket.write(data);
if (!flushed) { if (!flushed) {
//console.error('backpressure 777');
proxySocket.pause(); proxySocket.pause();
reverseProxy.incoming.socket.once('drain', function () { reverseProxy.incoming.socket.once('drain', function () {
try { try { proxySocket.resume() }
proxySocket.resume(); catch (er) { console.error("proxySocket.resume error: %s", er.message) }
} catch (er) {
console.error("proxySocket.resume error: %s", er.message);
}
}); });
setTimeout(function () { setTimeout(function () {
reverseProxy.incoming.socket.emit('drain'); reverseProxy.incoming.socket.emit('drain');
}, 100); }, 100);
} }
} }
catch (e) { catch (ex) {
detach(); detach();
reverseProxy.incoming.socket.end(); reverseProxy.incoming.socket.end();
proxySocket.end(); proxySocket.end();
...@@ -817,21 +805,19 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options ...@@ -817,21 +805,19 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
self.emit('websocket:incoming', reverseProxy, reverseProxy.incoming, head, data); self.emit('websocket:incoming', reverseProxy, reverseProxy.incoming, head, data);
var flushed = proxySocket.write(data); var flushed = proxySocket.write(data);
if (!flushed) { if (!flushed) {
//console.error('backpressure 804');
reverseProxy.incoming.socket.pause(); reverseProxy.incoming.socket.pause();
proxySocket.once('drain', function () { proxySocket.once('drain', function () {
try { try { reverseProxy.incoming.socket.resume() }
reverseProxy.incoming.socket.resume(); catch (ex) { console.error("reverseProxy.incoming.socket.resume error: %s", er.message) }
} catch (er) {
console.error("reverseProxy.incoming.socket.resume error: %s", er.message);
}
}); });
setTimeout(function () { setTimeout(function () {
proxySocket.emit('drain'); proxySocket.emit('drain');
}, 100); }, 100);
} }
} }
catch (e) { catch (ex) {
detach(); detach();
proxySocket.end(); proxySocket.end();
socket.end(); socket.end();
...@@ -991,15 +977,13 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options ...@@ -991,15 +977,13 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
socket.write(sdata); socket.write(sdata);
var flushed = socket.write(data); var flushed = socket.write(data);
if (!flushed) { if (!flushed) {
//console.error('backpressure 974');
reverseProxy.socket.pause(); reverseProxy.socket.pause();
socket.once('drain', function () { socket.once('drain', function () {
try { try { reverseProxy.socket.resume() }
reverseProxy.socket.resume(); catch (er) { console.error("reverseProxy.socket.resume error: %s", er.message) }
} catch (er) {
console.error("reverseProxy.socket.resume error: %s", er.message);
}
}); });
setTimeout(function () { setTimeout(function () {
socket.emit('drain'); socket.emit('drain');
}, 100); }, 100);
...@@ -1007,7 +991,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options ...@@ -1007,7 +991,7 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
} }
catch (ex) { catch (ex) {
proxyError(ex) proxyError(ex);
} }
// Catch socket errors // Catch socket errors
...@@ -1034,7 +1018,8 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options ...@@ -1034,7 +1018,8 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, options
if (options.buffer) { if (options.buffer) {
if (!errState) { if (!errState) {
options.buffer.resume(); options.buffer.resume();
} else { }
else {
options.buffer.destroy(); options.buffer.destroy();
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment