-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: allow Content-Length header for 304 responses
Fixes: #31037 PR-URL: #34835 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ricky Zhou <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |