mirror of
https://github.com/http-party/node-http-proxy.git
synced 2025-12-08 20:59:18 +00:00
Fix truncated chunked responses
This commit is contained in:
parent
af9eb06e47
commit
ef66833c4d
@ -277,6 +277,20 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
|
|||||||
if (!ended) { response.emit('end') }
|
if (!ended) { response.emit('end') }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//
|
||||||
|
// After reading a chunked response, the underlying socket
|
||||||
|
// will hit EOF and emit a 'end' event, which will abort
|
||||||
|
// the request. If the socket was paused at that time,
|
||||||
|
// pending data gets discarded, truncating the response.
|
||||||
|
// This code makes sure that we flush pending data.
|
||||||
|
//
|
||||||
|
response.connection.on('end', function () {
|
||||||
|
if (response.readable && response.resume) {
|
||||||
|
{
|
||||||
|
response.resume();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
response.on('end', function () {
|
response.on('end', function () {
|
||||||
ended = true;
|
ended = true;
|
||||||
if (!errState) {
|
if (!errState) {
|
||||||
@ -296,7 +310,12 @@ HttpProxy.prototype.proxyRequest = function (req, res, buffer) {
|
|||||||
|
|
||||||
function ondata(chunk) {
|
function ondata(chunk) {
|
||||||
if (res.writable) {
|
if (res.writable) {
|
||||||
if (false === res.write(chunk) && response.pause) {
|
// Only pause if the underlying buffers are full,
|
||||||
|
// *and* the connection is not in 'closing' state.
|
||||||
|
// Otherwise, the pause will cause pending data to
|
||||||
|
// be discarded and silently lost.
|
||||||
|
if (false === res.write(chunk) && response.pause
|
||||||
|
&& response.connection.readable) {
|
||||||
response.pause();
|
response.pause();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user