Skip to content

Commit 4652af7

Browse files
committed
test: expand test-http-response-multiheaders test
Include writeHead in the test per @bnoordhuis' suggestion
1 parent 65047e0 commit 4652af7

1 file changed

Lines changed: 31 additions & 10 deletions

File tree

test/parallel/test-http-response-multiheaders.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,40 @@ const norepeat = [
1515
];
1616

1717
const server = http.createServer(function(req, res) {
18-
for (let name of norepeat) {
19-
res.setHeader(name, ['A', 'B']);
18+
var num = req.headers['x-num'];
19+
if (num == 1) {
20+
for (let name of norepeat) {
21+
res.setHeader(name, ['A', 'B']);
22+
}
23+
res.setHeader('X-A', ['A', 'B']);
24+
} else if (num == 2) {
25+
let headers = {};
26+
for (let name of norepeat) {
27+
headers[name] = ['A', 'B'];
28+
}
29+
headers['X-A'] = ['A', 'B'];
30+
res.writeHead(200, headers);
2031
}
21-
res.setHeader('X-A', ['A', 'B']);
2232
res.end('ok');
2333
});
2434

2535
server.listen(common.PORT, common.mustCall(function() {
26-
http.get({port:common.PORT}, common.mustCall(function(res) {
27-
server.close();
28-
for (let name of norepeat) {
29-
assert.equal(res.headers[name], 'A');
30-
}
31-
assert.equal(res.headers['x-a'], 'A, B');
32-
}));
36+
for (let n = 1; n <= 2 ; n++) {
37+
// this runs twice, the first time, the server will use
38+
// setHeader, the second time it uses writeHead. The
39+
// result on the client side should be the same in
40+
// either case -- only the first instance of the header
41+
// value should be reported for the header fields listed
42+
// in the norepeat array.
43+
http.get(
44+
{port:common.PORT, headers:{'x-num': n}},
45+
common.mustCall(function(res) {
46+
if (n == 2) server.close();
47+
for (let name of norepeat) {
48+
assert.equal(res.headers[name], 'A');
49+
}
50+
assert.equal(res.headers['x-a'], 'A, B');
51+
})
52+
);
53+
}
3354
}));

0 commit comments

Comments
 (0)