Skip to content

Commit

Permalink
test: expand test-http-response-multiheaders test
Browse files Browse the repository at this point in the history
Include writeHead in the test per @bnoordhuis' suggestion
  • Loading branch information
jasnell committed Oct 6, 2015
1 parent 65047e0 commit 4652af7
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions test/parallel/test-http-response-multiheaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,40 @@ const norepeat = [
];

const server = http.createServer(function(req, res) {
for (let name of norepeat) {
res.setHeader(name, ['A', 'B']);
var num = req.headers['x-num'];
if (num == 1) {
for (let name of norepeat) {
res.setHeader(name, ['A', 'B']);
}
res.setHeader('X-A', ['A', 'B']);
} else if (num == 2) {
let headers = {};
for (let name of norepeat) {
headers[name] = ['A', 'B'];
}
headers['X-A'] = ['A', 'B'];
res.writeHead(200, headers);
}
res.setHeader('X-A', ['A', 'B']);
res.end('ok');
});

server.listen(common.PORT, common.mustCall(function() {
http.get({port:common.PORT}, common.mustCall(function(res) {
server.close();
for (let name of norepeat) {
assert.equal(res.headers[name], 'A');
}
assert.equal(res.headers['x-a'], 'A, B');
}));
for (let n = 1; n <= 2 ; n++) {
// this runs twice, the first time, the server will use
// setHeader, the second time it uses writeHead. The
// result on the client side should be the same in
// either case -- only the first instance of the header
// value should be reported for the header fields listed
// in the norepeat array.
http.get(
{port:common.PORT, headers:{'x-num': n}},
common.mustCall(function(res) {
if (n == 2) server.close();
for (let name of norepeat) {
assert.equal(res.headers[name], 'A');
}
assert.equal(res.headers['x-a'], 'A, B');
})
);
}
}));

0 comments on commit 4652af7

Please sign in to comment.