diff --git a/lib/_http_incoming.js b/lib/_http_incoming.js index 950c8c6e08bbc9..a83c8660db589b 100644 --- a/lib/_http_incoming.js +++ b/lib/_http_incoming.js @@ -122,9 +122,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'headers', { } return this[kHeaders]; }, - set: function(val) { - this[kHeaders] = val; - } + set: function(val) {} }); ObjectDefineProperty(IncomingMessage.prototype, 'headersDistinct', { @@ -142,9 +140,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'headersDistinct', { } return this[kHeadersDistinct]; }, - set: function(val) { - this[kHeadersDistinct] = val; - } + set: function(val) {} }); ObjectDefineProperty(IncomingMessage.prototype, 'trailers', { @@ -162,9 +158,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'trailers', { } return this[kTrailers]; }, - set: function(val) { - this[kTrailers] = val; - } + set: function(val) {} }); ObjectDefineProperty(IncomingMessage.prototype, 'trailersDistinct', { @@ -182,9 +176,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'trailersDistinct', { } return this[kTrailersDistinct]; }, - set: function(val) { - this[kTrailersDistinct] = val; - } + set: function(val) {} }); IncomingMessage.prototype.setTimeout = function setTimeout(msecs, callback) { diff --git a/test/parallel/test-http-set-headers-distinct.js b/test/parallel/test-http-set-headers-distinct.js new file mode 100644 index 00000000000000..3a3c99cdcc5f00 --- /dev/null +++ b/test/parallel/test-http-set-headers-distinct.js @@ -0,0 +1,54 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const { createServer, request } = require('http'); + +const server = createServer( + common.mustCall((req, res) => { + req.headersDistinct = { 'x-req-a': ['zzz'] }; + + // headersDistinct setter should be a No-Op + assert.deepStrictEqual(req.headersDistinct, { + 'transfer-encoding': [ + 'chunked', + ], + 'connection': [ + 'keep-alive', + ], + 'host': [ + `127.0.0.1:${server.address().port}`, + ] + }); + + req.on('end', function() { + res.write('BODY'); + res.end(); + }); + + req.resume(); + }) +); + +server.listen( + 0, + common.mustCall(() => { + const req = request( + { + host: '127.0.0.1', + port: server.address().port, + path: '/', + method: 'POST', + }, + common.mustCall((res) => { + res.on('end', function() { + server.close(); + }); + res.resume(); + }) + ); + + req.write('BODY'); + req.end(); + }) +); diff --git a/test/parallel/test-set-incoming-message-header.js b/test/parallel/test-set-incoming-message-header.js index 9ac05a8138d445..1fab6cd1e5a724 100644 --- a/test/parallel/test-set-incoming-message-header.js +++ b/test/parallel/test-set-incoming-message-header.js @@ -4,24 +4,23 @@ require('../common'); const { IncomingMessage } = require('http'); const assert = require('assert'); -// Headers setter function set a header correctly +// Headers setter should be a No-Op { const im = new IncomingMessage(); im.headers = { key: 'value' }; - assert.deepStrictEqual(im.headers, { key: 'value' }); + assert.deepStrictEqual(im.headers, {}); } -// Trailers setter function set a header correctly +// Trailers setter should be a No-Op { const im = new IncomingMessage(); im.trailers = { key: 'value' }; - assert.deepStrictEqual(im.trailers, { key: 'value' }); + assert.deepStrictEqual(im.trailers, {}); } // _addHeaderLines function set a header correctly { const im = new IncomingMessage(); - im.headers = { key1: 'value1' }; im._addHeaderLines(['key2', 'value2'], 2); - assert.deepStrictEqual(im.headers, { key1: 'value1', key2: 'value2' }); + assert.deepStrictEqual(im.headers, { key2: 'value2' }); }