};
function storeHeader(self, state, field, value) {
- // Protect against response splitting. The if statement is there to
- // minimize the performance impact in the common case.
- if (/[\r\n]/.test(value))
- value = value.replace(/[\r\n]+[ \t]*/g, '');
-
+ value = escapeHeaderValue(value);
state.messageHeader += field + ': ' + value + CRLF;
if (connectionExpression.test(field)) {
}
+function escapeHeaderValue(value) {
+ // Protect against response splitting. The regex test is there to
+ // minimize the performance impact in the common case.
+ return /[\r\n]/.test(value) ? value.replace(/[\r\n]+[ \t]*/g, '') : value;
+}
+
+
OutgoingMessage.prototype.addTrailers = function(headers) {
this._trailer = '';
var keys = Object.keys(headers);
value = headers[key];
}
- this._trailer += field + ': ' + value + CRLF;
+ this._trailer += field + ': ' + escapeHeaderValue(value) + CRLF;
}
};
http = require('http');
var testIndex = 0;
-const testCount = 4 * 6;
+const testCount = 2 * 4 * 6;
const responseBody = 'Hi mars!';
var server = http.createServer(function(req, res) {
default:
assert.fail('unreachable');
}
- res.end(responseBody);
+ res.write(responseBody);
+ if (testIndex % 8 < 4) {
+ res.addTrailers({ ta: header, tb: header });
+ } else {
+ res.addTrailers([['ta', header], ['tb', header]]);
+ }
+ res.end();
}
- switch ((testIndex / 4) | 0) {
+ switch ((testIndex / 8) | 0) {
case 0:
reply('foo \r\ninvalid: bar');
break;
res.on('data', function(s) { data += s; });
res.on('end', common.mustCall(function() {
assert.equal(data, responseBody);
+ assert.strictEqual(res.trailers.ta, 'foo invalid: bar');
+ assert.strictEqual(res.trailers.tb, 'foo invalid: bar');
+ assert.strictEqual(res.trailers.foo, undefined);
+ assert.strictEqual(res.trailers.invalid, undefined);
}));
res.resume();
}));