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

https-agent: fix issue where creating connection modifies arguments #31151

Closed
wants to merge 1 commit into from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/https.js
Expand Up @@ -95,9 +95,11 @@ function createConnection(port, host, options) {
if (port !== null && typeof port === 'object') {
options = port;
} else if (host !== null && typeof host === 'object') {
options = host;
options = { ...host };
} else if (options === null || typeof options !== 'object') {
options = {};
} else {
options = { ...options };
}

if (typeof port === 'number') {
Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-https-agent-create-connection.js
Expand Up @@ -132,3 +132,27 @@ function createServer() {
}));
}));
}

// `options` should not be modified
{
const server = createServer();
server.listen(0, common.mustCall(() => {
const port = server.address().port;
const host = 'localhost';
const options = {
port: 3000,
rejectUnauthorized: false
};

const socket = agent.createConnection(port, host, options);
socket.on('connect', common.mustCall((data) => {
socket.end();
}));
socket.on('end', common.mustCall(() => {
assert.deepStrictEqual(options, {
port: 3000, rejectUnauthorized: false
});
server.close();
}));
}));
}