Skip to content

Commit

Permalink
http: headers(Distinct), trailers(Distinct) setters to be no-op
Browse files Browse the repository at this point in the history
PR-URL: #45176
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
sonimadhuri authored and RafaelGSS committed Nov 10, 2022
1 parent ba89cea commit 1a04881
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
16 changes: 4 additions & 12 deletions lib/_http_incoming.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'headers', {
}
return this[kHeaders];
},
set: function(val) {
this[kHeaders] = val;
}
set: function(val) {}
});

ObjectDefineProperty(IncomingMessage.prototype, 'headersDistinct', {
Expand All @@ -142,9 +140,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'headersDistinct', {
}
return this[kHeadersDistinct];
},
set: function(val) {
this[kHeadersDistinct] = val;
}
set: function(val) {}
});

ObjectDefineProperty(IncomingMessage.prototype, 'trailers', {
Expand All @@ -162,9 +158,7 @@ ObjectDefineProperty(IncomingMessage.prototype, 'trailers', {
}
return this[kTrailers];
},
set: function(val) {
this[kTrailers] = val;
}
set: function(val) {}
});

ObjectDefineProperty(IncomingMessage.prototype, 'trailersDistinct', {
Expand All @@ -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) {
Expand Down
54 changes: 54 additions & 0 deletions test/parallel/test-http-set-headers-distinct.js
Original file line number Diff line number Diff line change
@@ -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();
})
);
11 changes: 5 additions & 6 deletions test/parallel/test-set-incoming-message-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
}

0 comments on commit 1a04881

Please sign in to comment.