From 49a9d0afb71a6ed45d6815e9c98456f2637df945 Mon Sep 17 00:00:00 2001 From: LavrovArtem Date: Thu, 31 May 2018 15:57:12 +0300 Subject: [PATCH] fix `Resource with the 304 status code and the 'content-length: x' header does not load` (close #1602) --- src/request-pipeline/index.js | 2 +- test/server/proxy-test.js | 40 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/request-pipeline/index.js b/src/request-pipeline/index.js index c5ad5d3708..3b097de364 100644 --- a/src/request-pipeline/index.js +++ b/src/request-pipeline/index.js @@ -84,7 +84,7 @@ const stages = { else if (!ctx.contentInfo.requireProcessing) { sendResponseHeaders(ctx); - if (!ctx.isSpecialPage) { + if (!ctx.isSpecialPage && !ctx.contentInfo.isNotModified) { ctx.requestFilterRules.forEach(rule => { const configureResponseEvent = new ConfigureResponseEvent(rule, ConfigureResponseEventOptions.DEFAULT); diff --git a/test/server/proxy-test.js b/test/server/proxy-test.js index e0769a39e6..1b9e4fc6fb 100644 --- a/test/server/proxy-test.js +++ b/test/server/proxy-test.js @@ -3327,5 +3327,45 @@ describe('Proxy', () => { testRedirectRequestStatusCode(202, false) ]); }); + + it('Should not pipe the request with the 304 status code (Not Modified) (GH-1602)', () => { + const server = net.createServer(socket => { + socket.on('data', () => { + socket.write([ + 'HTTP/1.1 304 Not Modified', + 'Content-Length: 5', + '', + '' + ].join('\r\n')); + }); + }); + + return getFreePort() + .then(port => new Promise(resolve => server.listen(port, () => resolve(port)))) + .then(port => new Promise((resolve, reject) => { + const proxyUrl = proxy.openSession(`http://127.0.0.1:${port}/`, session); + const reqOptions = Object.assign(urlLib.parse(proxyUrl), { + method: 'GET', + headers: { 'if-none-match': 'NQQ6Iyi1ttEATRNQs+U9yQ==' } + }); + + const req = http.request(reqOptions, res => { + const chunks = []; + + res.on('data', chunk => chunks.push(chunk)); + res.on('end', () => resolve({ res, body: Buffer.concat(chunks).toString() })); + }); + + req.on('error', reject); + req.setTimeout(1500, () => reject('timeout')); + req.end(); + })) + .then(({ res, body }) => { + expect(res.statusCode).eql(304); + expect(res.headers['content-length']).eql('5'); + expect(body).eql(''); + server.close(); + }); + }); }); });