mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Merge pull request #136 from bmeck/drain-fix
[fix] only set one drain listener while paused
This commit is contained in:
commit
cdb45247ca
@ -224,6 +224,7 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
|
||||
// If the res socket has been killed already, then write()
|
||||
// will throw. Nevertheless, try our best to end it nicely.
|
||||
//
|
||||
var paused = false;
|
||||
response.on('data', function (chunk) {
|
||||
if (req.method !== 'HEAD' && res.writable) {
|
||||
try {
|
||||
@ -238,9 +239,11 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!flushed) {
|
||||
if (!flushed && !paused) {
|
||||
paused = true;
|
||||
response.pause();
|
||||
res.once('drain', function () {
|
||||
paused = false;
|
||||
try { response.resume() }
|
||||
catch (er) { console.error("response.resume error: %s", er.message) }
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user