diff --git a/lib/_http_outgoing.js b/lib/_http_outgoing.js index f8ae30d4dee4f2..e06a51bb825643 100644 --- a/lib/_http_outgoing.js +++ b/lib/_http_outgoing.js @@ -440,7 +440,8 @@ function storeHeader(self, state, key, value, validate) { throw new Error('Header "%s" value must not be undefined', key); } else if (checkInvalidHeaderChar(value)) { debug('Header "%s" contains invalid characters', key); - throw new TypeError('The header content contains invalid characters'); + throw new TypeError( + 'The header content contains invalid characters ["' + key + '"]'); } } state.header += key + ': ' + escapeHeaderValue(value) + CRLF; @@ -498,7 +499,8 @@ function validateHeader(msg, name, value) { throw new Error('Can\'t set headers after they are sent.'); if (checkInvalidHeaderChar(value)) { debug('Header "%s" contains invalid characters', name); - throw new TypeError('The header content contains invalid characters'); + throw new TypeError( + 'The header content contains invalid characters ["' + name + '"]'); } } OutgoingMessage.prototype.setHeader = function setHeader(name, value) { diff --git a/test/parallel/test-http-outgoing-proto.js b/test/parallel/test-http-outgoing-proto.js index 202a185c7843e3..9bdc466acafc02 100644 --- a/test/parallel/test-http-outgoing-proto.js +++ b/test/parallel/test-http-outgoing-proto.js @@ -38,7 +38,7 @@ assert.throws(() => { assert.throws(() => { const outgoingMessage = new OutgoingMessage(); outgoingMessage.setHeader('200', 'あ'); -}, /^TypeError: The header content contains invalid characters$/); +}, /^TypeError: The header content contains invalid characters \["200"\]$/); // write assert.throws(() => { diff --git a/test/parallel/test-http-response-splitting.js b/test/parallel/test-http-response-splitting.js index b14d59e59ce8f9..bda6d9c041571e 100644 --- a/test/parallel/test-http-response-splitting.js +++ b/test/parallel/test-http-response-splitting.js @@ -19,23 +19,26 @@ const y = 'foo⠊Set-Cookie: foo=bar'; let count = 0; -function test(res, code, header) { +function test(res, code, header, failing) { + const expected = + '^TypeError: The header content contains invalid characters \\["' + + failing + '"\\]$'; assert.throws(() => { res.writeHead(code, header); - }, /^TypeError: The header content contains invalid characters$/); + }, new RegExp(expected)); } const server = http.createServer((req, res) => { switch (count++) { case 0: const loc = url.parse(req.url, true).query.lang; - test(res, 302, { Location: `/foo?lang=${loc}` }); + test(res, 302, { Location: `/foo?lang=${loc}` }, 'Location'); break; case 1: - test(res, 200, { 'foo': x }); + test(res, 200, { 'foo': x }, 'foo'); break; case 2: - test(res, 200, { 'foo': y }); + test(res, 200, { 'foo': y }, 'foo'); break; default: assert.fail('should not get to here.');