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

don't mutate configuration when updating http agent #42

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 10 additions & 7 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,20 @@ utils.setHttpAgent = function setHttpAgent(
bypassProxy = false,
AwsConstructor
) {
config.httpOptions = _.merge(config.httpOptions, {});

if (bypassProxy) {
config.httpOptions.agent = new https.Agent({
const getNonProxyAgent = () =>
new https.Agent({
keepAlive: true,
rejectUnauthorized: true,
maxSockets: 50
});
}

config = _.omit(config, 'bypassProxy');
const newConfig = {
...config,
httpOptions: {
...config.httpOptions,
...(bypassProxy ? { agent: getNonProxyAgent() } : {})
}
};

return new AwsConstructor(config);
return new AwsConstructor(_.omit(newConfig, 'bypassProxy'));
};
86 changes: 33 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"dependencies": {
"aws-sdk": "^2.327.0",
"bluebird": "^3.5.0",
"lodash": "^4.17.11",
"lodash": "^4.17.15",
"proxy-agent": "^3.0.3",
"sinon-chai": "^3.3.0",
"uuid": "^3.3.2"
Expand Down
11 changes: 11 additions & 0 deletions test/unit/lib/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ describe('AWS Library utilities', function() {
});
});

it('should not mutate the passed in config when setting http agent', function() {
const awsMock = sinon.stub();
// bypassProxy shouldn't be passed to the AWS constructor
const config = { bypassProxy: 'a value' };
utils.setHttpAgent(config, true, awsMock);
expect(awsMock).to.have.been.calledWith({
httpOptions: { agent: sinon.match.any }
});
expect(config).to.deep.equal({ bypassProxy: 'a value' });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

});

it('should default to not setting up http keepalives', function() {
const awsMock = sinon.stub();

Expand Down