From 37e25418916a31e4a513ee5866d6013858d579cf Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 8 Sep 2011 16:36:19 -0700 Subject: [PATCH] Emit drain if it doesn't happen on its own in 100ms --- lib/node-http-proxy/http-proxy.js | 48 +++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/lib/node-http-proxy/http-proxy.js b/lib/node-http-proxy/http-proxy.js index 00fc05e..89a447a 100644 --- a/lib/node-http-proxy/http-proxy.js +++ b/lib/node-http-proxy/http-proxy.js @@ -240,6 +240,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { res.once('drain', function () { response.resume(); }); + + // + // Force the `drain` event in 100ms if it hasn't + // happened on its own. + // + setTimeout(function () { + res.emit('drain'); + }, 100); } } }); @@ -281,6 +289,14 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) { reverseProxy.once('drain', function () { req.resume(); }); + + // + // Force the `drain` event in 100ms if it hasn't + // happened on its own. + // + setTimeout(function () { + reverseProxy.emit('drain'); + }, 100); } } }); @@ -356,6 +372,14 @@ HttpProxy.prototype._forwardRequest = function (req) { forwardProxy.once('drain', function () { req.resume(); }); + + // + // Force the `drain` event in 100ms if it hasn't + // happened on its own. + // + setTimeout(function () { + forwardProxy.emit('drain'); + }, 100); } }); @@ -448,6 +472,14 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) reverseProxy.incoming.socket.once('drain', function () { proxySocket.resume(); }); + + // + // Force the `drain` event in 100ms if it hasn't + // happened on its own. + // + setTimeout(function () { + reverseProxy.incoming.socket.emit('drain'); + }, 100); } } catch (ex) { @@ -471,6 +503,14 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) proxySocket.once('drain', function () { reverseProxy.incoming.socket.resume(); }); + + // + // Force the `drain` event in 100ms if it hasn't + // happened on its own. + // + setTimeout(function () { + proxySocket.emit('drain'); + }, 100); } } catch (ex) { @@ -635,6 +675,14 @@ HttpProxy.prototype.proxyWebSocketRequest = function (req, socket, head, buffer) socket.once('drain', function () { reverseProxy.socket.resume(); }); + + // + // Force the `drain` event in 100ms if it hasn't + // happened on its own. + // + setTimeout(function () { + socket.emit('drain'); + }, 100); } } catch (ex) {