mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
http: allow Content-Length header for 304 responses
Fixes: https://github.com/nodejs/node/issues/31037 PR-URL: https://github.com/nodejs/node/pull/34835 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
committed by
Rich Trott
parent
1df50ffb55
commit
23d6c42495
@@ -654,6 +654,11 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
|
||||
if (method === 'HEAD')
|
||||
return 1; // Skip body but don't treat as Upgrade.
|
||||
|
||||
if (res.statusCode === 304) {
|
||||
res.complete = true;
|
||||
return 1; // Skip body as there won't be any
|
||||
}
|
||||
|
||||
return 0; // No special treatment.
|
||||
}
|
||||
|
||||
|
||||
32
test/parallel/test-http-allow-content-length-304.js
Normal file
32
test/parallel/test-http-allow-content-length-304.js
Normal file
@@ -0,0 +1,32 @@
|
||||
'use strict';
|
||||
const common = require('../common');
|
||||
|
||||
// This test ensures that the http-parser doesn't expect a body when
|
||||
// a 304 Not Modified response has a non-zero Content-Length header
|
||||
|
||||
const assert = require('assert');
|
||||
const http = require('http');
|
||||
|
||||
const server = http.createServer(common.mustCall((req, res) => {
|
||||
res.setHeader('Content-Length', 11);
|
||||
res.statusCode = 304;
|
||||
res.end(null);
|
||||
}));
|
||||
|
||||
server.listen(0, () => {
|
||||
const request = http.request({
|
||||
port: server.address().port,
|
||||
});
|
||||
|
||||
request.on('response', common.mustCall((response) => {
|
||||
response.on('data', common.mustNotCall());
|
||||
response.on('aborted', common.mustNotCall());
|
||||
response.on('end', common.mustCall(() => {
|
||||
assert.strictEqual(response.headers['content-length'], '11');
|
||||
assert.strictEqual(response.statusCode, 304);
|
||||
server.close();
|
||||
}));
|
||||
}));
|
||||
|
||||
request.end(null);
|
||||
});
|
||||
Reference in New Issue
Block a user