Skip to content

Commit f1f9f7b

Browse files
committed
http: improve invalid header character error
This commit includes the header name in the error message when invalid characters are in the value.
1 parent 4896f0f commit f1f9f7b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/_http_outgoing.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ OutgoingMessage.prototype.setHeader = function(name, value) {
355355
if (this._header)
356356
throw new Error('Can\'t set headers after they are sent.');
357357
if (common._checkInvalidHeaderChar(value) === true) {
358-
throw new TypeError('The header content contains invalid characters');
358+
throw new TypeError(`The header content for ${JSON.stringify(name)} ` +
359+
'contains invalid characters');
359360
}
360361
if (this._headers === null)
361362
this._headers = {};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
5+
6+
assert.throws(function() {
7+
// Header value with CRLF should throw
8+
http.get({
9+
path: '/',
10+
headers: {
11+
a: 'bad value\r\n'
12+
}
13+
}, common.fail);
14+
}, /header content for "a" contains invalid characters/);

0 commit comments

Comments
 (0)