Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,12 @@ IncomingMessage.prototype._addHeaderLine = function(field, value, dest) {
case 'from':
case 'location':
case 'max-forwards':
case 'retry-after':
case 'etag':
case 'last-modified':
case 'server':
case 'age':
case 'expires':
// drop duplicates
if (dest[field] === undefined)
dest[field] = value;
Expand Down
6 changes: 5 additions & 1 deletion lib/_http_outgoing.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ exports.OutgoingMessage = OutgoingMessage;


OutgoingMessage.prototype.setTimeout = function(msecs, callback) {
if (callback)

if (callback) {
if (typeof callback !== 'function')
throw new TypeError('callback must be a function');
this.on('timeout', callback);
}

if (!this.socket) {
this.once('socket', function(socket) {
Expand Down
54 changes: 54 additions & 0 deletions test/parallel/test-http-response-multiheaders.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

const common = require('../common');
const http = require('http');
const assert = require('assert');

// Test that certain response header fields do not repeat
const norepeat = [
'retry-after',
'etag',
'last-modified',
'server',
'age',
'expires'
];

const server = http.createServer(function(req, res) {
var num = req.headers['x-num'];
if (num == 1) {
for (let name of norepeat) {
res.setHeader(name, ['A', 'B']);
}
res.setHeader('X-A', ['A', 'B']);
} else if (num == 2) {
let headers = {};
for (let name of norepeat) {
headers[name] = ['A', 'B'];
}
headers['X-A'] = ['A', 'B'];
res.writeHead(200, headers);
}
res.end('ok');
});

server.listen(common.PORT, common.mustCall(function() {
for (let n = 1; n <= 2 ; n++) {
// this runs twice, the first time, the server will use
// setHeader, the second time it uses writeHead. The
// result on the client side should be the same in
// either case -- only the first instance of the header
// value should be reported for the header fields listed
// in the norepeat array.
http.get(
{port:common.PORT, headers:{'x-num': n}},
common.mustCall(function(res) {
if (n == 2) server.close();
for (let name of norepeat) {
assert.equal(res.headers[name], 'A');
}
assert.equal(res.headers['x-a'], 'A, B');
})
);
}
}));