Skip to content

Commit

Permalink
fix `Resource with the 304 status code and the 'content-length: x' he…
Browse files Browse the repository at this point in the history
…ader does not load` (close #1602)
  • Loading branch information
LavrovArtem committed May 31, 2018
1 parent 44639eb commit 49a9d0a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/request-pipeline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
40 changes: 40 additions & 0 deletions test/server/proxy-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
});

0 comments on commit 49a9d0a

Please sign in to comment.