node/test/parallel/test-http-write-head.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

50 lines
1.2 KiB
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const http = require('http');
// Verify that ServerResponse.writeHead() works as setHeader.
// Issue 5036 on github.
const s = http.createServer(function(req, res) {
res.setHeader('test', '1');
// toLowerCase() is used on the name argument, so it must be a string.
let threw = false;
try {
res.setHeader(0xf00, 'bar');
} catch (e) {
assert.ok(e instanceof TypeError);
threw = true;
}
assert.ok(threw, 'Non-string names should throw');
// undefined value should throw, via 979d0ca8
threw = false;
try {
res.setHeader('foo', undefined);
} catch (e) {
assert.ok(e instanceof Error);
assert.strictEqual(e.message,
'"value" required in setHeader("foo", value)');
threw = true;
}
assert.ok(threw, 'Undefined value should throw');
res.writeHead(200, { Test: '2' });
res.end();
});
s.listen(0, runTest);
function runTest() {
http.get({ port: this.address().port }, function(response) {
response.on('end', function() {
assert.strictEqual(response.headers['test'], '2');
assert.notStrictEqual(response.rawHeaders.indexOf('Test'), -1);
s.close();
});
response.resume();
});
}