Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: expand test-http-response-multiheaders test
Include writeHead in the test per @bnoordhuis' suggestion
  • Loading branch information
jasnell committed Oct 6, 2015
commit 4652af7bb545b4842254348030c60f0d2b0548bc
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');
})
);
}
}));