0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/parallel/test-http-response-multiheaders.js
Gibson Fahnestock 3d2aef3979 test: s/assert.equal/assert.strictEqual/
Use assert.strictEqual instead of assert.equal in tests, manually
convert types where necessary.

PR-URL: https://github.com/nodejs/node/pull/10698
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
2017-01-11 14:19:26 +00:00

70 lines
1.8 KiB
JavaScript

'use strict';
const common = require('../common');
const http = require('http');
const assert = require('assert');
// Test that certain response header fields do not repeat.
// 'content-length' should also be in this list but it is
// handled differently because multiple content-lengths are
// an error (see test-http-response-multi-content-length.js).
const norepeat = [
'content-type',
'user-agent',
'referer',
'host',
'authorization',
'proxy-authorization',
'if-modified-since',
'if-unmodified-since',
'from',
'location',
'max-forwards',
'retry-after',
'etag',
'last-modified',
'server',
'age',
'expires'
];
const server = http.createServer(function(req, res) {
const num = req.headers['x-num'];
if (num === '1') {
for (const name of norepeat) {
res.setHeader(name, ['A', 'B']);
}
res.setHeader('X-A', ['A', 'B']);
} else if (num === '2') {
const headers = {};
for (const name of norepeat) {
headers[name] = ['A', 'B'];
}
headers['X-A'] = ['A', 'B'];
res.writeHead(200, headers);
}
res.end('ok');
});
server.listen(0, common.mustCall(function() {
let count = 0;
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: this.address().port, headers: {'x-num': n}},
common.mustCall(function(res) {
if (++count === 2) server.close();
for (const name of norepeat) {
assert.strictEqual(res.headers[name], 'A');
}
assert.strictEqual(res.headers['x-a'], 'A, B');
})
);
}
}));