test: refactor test-http-response-splitting
* move repeated code to function * remove unneeded `common.mustCall()` usage with function arguments that are not callbacks * add error message checking PR-URL: https://github.com/nodejs/node/pull/11429 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
This commit is contained in:
parent
1b31ca6cca
commit
66476889ff
@ -19,23 +19,23 @@ const y = 'foo⠊Set-Cookie: foo=bar';
|
|||||||
|
|
||||||
let count = 0;
|
let count = 0;
|
||||||
|
|
||||||
|
function test(res, code, header) {
|
||||||
|
assert.throws(() => {
|
||||||
|
res.writeHead(code, header);
|
||||||
|
}, /^TypeError: The header content contains invalid characters$/);
|
||||||
|
}
|
||||||
|
|
||||||
const server = http.createServer((req, res) => {
|
const server = http.createServer((req, res) => {
|
||||||
switch (count++) {
|
switch (count++) {
|
||||||
case 0:
|
case 0:
|
||||||
const loc = url.parse(req.url, true).query.lang;
|
const loc = url.parse(req.url, true).query.lang;
|
||||||
assert.throws(common.mustCall(() => {
|
test(res, 302, {Location: `/foo?lang=${loc}`});
|
||||||
res.writeHead(302, {Location: `/foo?lang=${loc}`});
|
|
||||||
}));
|
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
assert.throws(common.mustCall(() => {
|
test(res, 200, {'foo': x});
|
||||||
res.writeHead(200, {'foo': x});
|
|
||||||
}));
|
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
assert.throws(common.mustCall(() => {
|
test(res, 200, {'foo': y});
|
||||||
res.writeHead(200, {'foo': y});
|
|
||||||
}));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
common.fail('should not get to here.');
|
common.fail('should not get to here.');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user