mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Merge pull request #337 from indutny/feature-304-end
http-proxy: 304 responses should emit 'end' too
This commit is contained in:
commit
8b3cfdaaea
@ -256,6 +256,31 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// When the `reverseProxy` `response` ends, end the
|
||||||
|
// corresponding outgoing `res` unless we have entered
|
||||||
|
// an error state. In which case, assume `res.end()` has
|
||||||
|
// already been called and the 'error' event listener
|
||||||
|
// removed.
|
||||||
|
//
|
||||||
|
var ended = false;
|
||||||
|
response.on('close', function () {
|
||||||
|
if (!ended) { response.emit('end') }
|
||||||
|
});
|
||||||
|
|
||||||
|
response.on('end', function () {
|
||||||
|
ended = true;
|
||||||
|
if (!errState) {
|
||||||
|
reverseProxy.removeListener('error', proxyError);
|
||||||
|
|
||||||
|
try { res.end() }
|
||||||
|
catch (ex) { console.error("res.end error: %s", ex.message) }
|
||||||
|
|
||||||
|
// Emit the `end` event now that we have completed proxying
|
||||||
|
self.emit('end', req, res);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Set the headers of the client response
|
// Set the headers of the client response
|
||||||
res.writeHead(response.statusCode, response.headers);
|
res.writeHead(response.statusCode, response.headers);
|
||||||
|
|
||||||
@ -283,31 +308,6 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.on('drain', ondrain);
|
res.on('drain', ondrain);
|
||||||
|
|
||||||
//
|
|
||||||
// When the `reverseProxy` `response` ends, end the
|
|
||||||
// corresponding outgoing `res` unless we have entered
|
|
||||||
// an error state. In which case, assume `res.end()` has
|
|
||||||
// already been called and the 'error' event listener
|
|
||||||
// removed.
|
|
||||||
//
|
|
||||||
var ended = false;
|
|
||||||
response.on('close', function () {
|
|
||||||
if (!ended) { response.emit('end') }
|
|
||||||
});
|
|
||||||
|
|
||||||
response.on('end', function () {
|
|
||||||
ended = true;
|
|
||||||
if (!errState) {
|
|
||||||
reverseProxy.removeListener('error', proxyError);
|
|
||||||
|
|
||||||
try { res.end() }
|
|
||||||
catch (ex) { console.error("res.end error: %s", ex.message) }
|
|
||||||
|
|
||||||
// Emit the `end` event now that we have completed proxying
|
|
||||||
self.emit('end', req, res);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user