Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http: headers(Distinct), trailers(Distinct) setters to be no-op #45176

Merged
merged 2 commits into from Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 4 additions & 12 deletions lib/_http_incoming.js
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
@@ -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
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' });
}