Skip to content

Commit 11c3d71

Browse files
mcollinaaduh95
authored andcommitted
benchmark: add implicit-framing case to http/set-header
The existing `setHeader` and `setHeaderWH` cases set `Content-Length` explicitly, and `normal` passes every header to `writeHead()`. The very common handler shape `res.setHeader(...)` + `res.end(body)`, where `end()` derives the framing, exercises a different path and was not covered. Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #66420 Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
1 parent 83a1697 commit 11c3d71

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎benchmark/fixtures/simple-http-server.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ module.exports = http.createServer((req, res) => {
114114
else
115115
res.writeHead(status, { 'Content-Length': len.toString() });
116116
break;
117+
case 'setHeaderImplicit':
118+
// Let end() derive the message framing: no Content-Length or
119+
// Transfer-Encoding header and no writeHead() call.
120+
res.statusCode = status;
121+
res.setHeader('Content-Type', 'text/plain');
122+
break;
117123
default:
118124
if (chunkedEnc) {
119125
res.writeHead(status, {

‎benchmark/http/set-header.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
const common = require('../common.js');
33

44
const bench = common.createBenchmark(main, {
5-
res: ['normal', 'setHeader', 'setHeaderWH'],
5+
res: ['normal', 'setHeader', 'setHeaderWH', 'setHeaderImplicit'],
66
duration: 5,
77
});
88

@@ -15,6 +15,7 @@ const c = 50;
1515
// normal: writeHead(status, {...})
1616
// setHeader: statusCode = status, setHeader(...) x2
1717
// setHeaderWH: setHeader(...), writeHead(status, ...)
18+
// setHeaderImplicit: statusCode = status, setHeader(...) x1, framing left to end()
1819
function main({ res, duration }) {
1920
const server = require('../fixtures/simple-http-server.js')
2021
.listen(0)

0 commit comments

Comments
 (0)