diff --git a/lib/http-proxy/passes/web-outgoing.js b/lib/http-proxy/passes/web-outgoing.js index 46352f6..c5392c0 100644 --- a/lib/http-proxy/passes/web-outgoing.js +++ b/lib/http-proxy/passes/web-outgoing.js @@ -24,7 +24,7 @@ module.exports = { // <-- * @api private */ removeChunked: function removeChunked(req, res, proxyRes) { - if (req.httpVersion === '1.0') { + if (req.httpVersion === '1.0' || proxyRes.statusCode === 204 || proxyRes.statusCode === 304) { delete proxyRes.headers['transfer-encoding']; } }, diff --git a/test/lib-http-proxy-passes-web-outgoing-test.js b/test/lib-http-proxy-passes-web-outgoing-test.js index a509cf1..0c0b1fc 100644 --- a/test/lib-http-proxy-passes-web-outgoing-test.js +++ b/test/lib-http-proxy-passes-web-outgoing-test.js @@ -408,16 +408,48 @@ describe('lib/http-proxy/passes/web-outgoing.js', function () { describe('#removeChunked', function() { - var proxyRes = { - headers: { - 'transfer-encoding': 'hello' - } - }; + + it('removes "transfer-encoding" response header on httpVersion 1.0', function() { + var proxyRes = { + headers: { + 'transfer-encoding': 'hello' + } + }; - httpProxy.removeChunked({ httpVersion: '1.0' }, {}, proxyRes); + httpProxy.removeChunked({ httpVersion: '1.0' }, {}, proxyRes); + + expect(proxyRes.headers['transfer-encoding']).to.eql(undefined); + }); + + it('removes "transfer-encoding" response header on 204 response codes', function() { + var proxyRes = { + headers: { + 'transfer-encoding': 'hello' + }, + statusCode: 204 + }; + + + httpProxy.removeChunked({ httpVersion: '1.1' }, {}, proxyRes); + + expect(proxyRes.headers['transfer-encoding']).to.eql(undefined); + }); + + it('removes "transfer-encoding" response header on 304 response codes', function() { + var proxyRes = { + headers: { + 'transfer-encoding': 'hello' + }, + statusCode: 304 + }; + + + httpProxy.removeChunked({ httpVersion: '1.1' }, {}, proxyRes); + + expect(proxyRes.headers['transfer-encoding']).to.eql(undefined); + }); - expect(proxyRes.headers['transfer-encoding']).to.eql(undefined); }); });