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: make globalAgent of http and https as overridable properties #9386

Closed
wants to merge 1 commit into from

Conversation

diorahman
Copy link

@diorahman diorahman commented Oct 31, 2016

Checklist
  • make -j8 test (UNIX), or vcbuild test nosign (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

http, https

Description of change

The http.globalAgent and https.globalAgent previously cannot be overridden directly by reassigning new a value.

By exposing the globalAgents of http and https, now it can be reassigned by:

http.globalAgent = new MyAgent();
https.globalAgent = new MySecureAgent();

Fix #9057

The `http.globalAgent` and `https.globalAgent` previously cannot be
overridden directly by reassigning new a value.

By exposing the `globalAgent`s of `http` and `https`, now it can be
reassigned by:

    http.globalAgent = new MyAgent();
    https.globalAgent = new MySecureAgent();
@nodejs-github-bot nodejs-github-bot added http Issues or PRs related to the http subsystem. https Issues or PRs related to the https subsystem. labels Oct 31, 2016
@sam-github
Copy link
Contributor

I would include docs in the PR, because the docs will show how the API changes, and let you document the usefulness of it.

Also, does this really work? What happens to any requests that are in process and using the old global agent? And to its cached connections? Do they just leak, or do they timeout and go away?

I'm also pretty surprised to see that https.request seems to be modifying its options argument, that will go badly if you use the same options for several requests, particularly if you modify the globalAgent in between as this PR allows.

What about just making the globalAgent propert read-only, so nobody can try to assign to it by mistake?

@Trott
Copy link
Member

Trott commented Oct 31, 2016

Can you add a test? See https://github.com/nodejs/node/blob/master/doc/guides/writing_tests.md and maybe try to find a similar test in test/parallel/test-http*. It looks like there's some code in #9057 that could be the basis for a test case.

@sam-github
Copy link
Contributor

@Trott I suspect that @diorahman deliberately didn't test or doc, because it is not sure people are 👍 or 👎 on the entire idea. Which is reasonable, IMO. I suggested docs because I think its hard to evaluate the reasonableness of API changes that are doc-less. That may just be me.

@@ -23,6 +23,7 @@ const client = require('_http_client');
const ClientRequest = exports.ClientRequest = client.ClientRequest;

exports.request = function request(options, cb) {
options._defaultAgent = options._defaultAgent || exports.globalAgent || agent.globalAgent;
Copy link
Member

Choose a reason for hiding this comment

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

Long line. make test would have caught this, it runs make lint.

Copy link
Author

Choose a reason for hiding this comment

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

OK @bnoordhuis will fix this.

@diorahman
Copy link
Author

@sam-github @Trott yes, as Sam said (and it is outlined in the #9057) the idea is still unclear. Will try to provide tests and experiment with what suggested by @sam-github in #9386 (comment)

@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Nov 2, 2016
@jasnell
Copy link
Member

jasnell commented Nov 2, 2016

@nodejs/http ... thoughts?

@diorahman ... would you mind adding a test?

@lance
Copy link
Member

lance commented Jan 19, 2017

This seems to have been dropped. Is there any reason to push it forward or can it be closed along with #9057?

@bnoordhuis
Copy link
Member

I'll go ahead and close it. Can reopen if @diorahman wants to follow through.

@bnoordhuis bnoordhuis closed this Jan 19, 2017
whut added a commit to whut/node that referenced this pull request Jul 17, 2023
Under ECMAScript modules when you do "import * as https from 'https'"
you get a new object with properties copied from https module exports.
So if this is a regular data property, you will just override a copy,
but if this would be a accessor property, we can still access the actual
https.globalAgent.

Refs: nodejs#25170, nodejs#9386
whut added a commit to whut/node that referenced this pull request Jul 17, 2023
Under ECMAScript modules when you do "import * as https from 'https'"
you get a new object with properties copied from https module exports.
So if this is a regular data property, you will just override a copy,
but if this would be a accessor property, we can still access the actual
https.globalAgent.

Refs: nodejs#25170, nodejs#9386
whut added a commit to whut/node that referenced this pull request Jul 17, 2023
Under ECMAScript modules when you do "import * as https from 'https'"
you get a new object with properties copied from https module exports.
So if this is a regular data property, you will just override a copy,
but if this would be a accessor property, we can still access the actual
https.globalAgent.

Refs: nodejs#25170, nodejs#9386
whut added a commit to whut/node that referenced this pull request Jul 17, 2023
Under ECMAScript modules when you do "import * as https from 'https'"
you get a new object with properties copied from https module exports.
So if this is a regular data property, you will just override a copy,
but if this would be a accessor property, we can still access the actual
https.globalAgent.

Refs: nodejs#25170, nodejs#9386
whut added a commit to whut/node that referenced this pull request Jul 19, 2023
Under ECMAScript modules when you do "import * as https from 'https'"
you get a new object with properties copied from https module exports.
So if this is a regular data property, you will just override a copy,
but if this would be a accessor property, we can still access the actual
https.globalAgent.

Refs: nodejs#25170, nodejs#9386
whut added a commit to whut/node that referenced this pull request Jul 20, 2023
Under ECMAScript modules when you do "import * as https from 'https'"
you get a new object with properties copied from https module exports.
So if this is a regular data property, you will just override a copy,
but if this would be a accessor property, we can still access the actual
https.globalAgent.

Refs: nodejs#25170, nodejs#9386
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem. https Issues or PRs related to the https subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants