-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: allow url and options to be passed to https.request #22003
Conversation
I would prefer avoiding adding new (underscore-prefixed) functions to the prototype. I believe this could be resolved at least by one of:
Also, I think the commit message should technically have an |
lib/_http_client.js
Outdated
|
||
ClientRequest.prototype._defaultAgent = function() { | ||
return Agent.globalAgent; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would avoid exposing those two directly. Maybe we should move them under a private Symbol?
return new ClientRequest(options, cb); | ||
args.unshift(options); | ||
|
||
return new ClientRequest(...args); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last I checked, this was still significantly slower in V8 I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in Node 8.3? See https://github.com/davidmarkclements/v8-perf
Here’s the takeaway: if we want to write performant code around processing function inputs as an array (which in my experience seems fairly common), then in Node 8.3 and up we should use the spread operator.
Responding to your original suggestions:
Making HttpsClientRequest have no additional methods and checking this.constructor === HttpsClientRequest
The issue is that without additional methods, it never would be called... unless we duplicated the entire constructor.
Allow passing a 4th option to ClientRequest that if not undefined, must be a private symbol indicating an https client request
This will impact the ability to add future arguments. And we are currently dealing with three arguments, all optional...
Make the few changes needed to the original code in https to support both url and options
I went this way for now.
The other option:
Maybe we should move them under a private Symbol?
This is clean and would work. The symbols would need to be exported by lib/_http_client.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is clean and would work. The symbols would need to be exported by lib/_http_client.js
I would prefer it. Unfortunately there is a lot of monkey patching around core methods, and I would prefer this would be as private as possible. I would not block this for it.
If you feel strongly about going _
, then ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcollina I'm not following.... in particular, I'm not sure what 'it' refers to.
Should I go back to the previous approach of subclassing ClientRequest for https, and introducing two new methods, this time with the method names being Symbols? My thoughts are that that approach is more understandable and maintainable.
Or would you prefer the current approach which duplicates a bit of code, but doesn't introduce any new methods. My thoughts are that approach is more private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually commenting on some old code. The current approach is fine. LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Making HttpsClientRequest have no additional methods and checking this.constructor === HttpsClientRequest
The issue is that without additional methods, it never would be called... unless we duplicated the entire constructor.
@rubys I'm not sure what you mean, HttpsClientRequest
would extend from ClientRequest
and be empty itself (no explicit constructor or additional methods). Then inside ClientRequest
, checking this.constructor
like:
var defaultAgent = options._defaultAgent ||
(this.constructor === https[ClientRequestSym]
? https.globalAgent : Agent.globalAgent);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@McDex Fair point, but making that work would involve a circular require.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rubys Not if it's lazy loaded.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Resume Build: https://ci.nodejs.org/job/node-test-pull-request/16071/ |
I believe that this is ready to land. @McDex and @mcollina had similar concerns on my first implementation and collectively provided four alternatives. I selected and implemented @McDex's third option, and @mcollina approved the approach. What remains is side conversation as to whether @McDex's first suggestion could also be made to work (it could, but wouldn't be as clear/straightforward as the third suggestion, in my opinion). Assuming that @McDex is still comfortable with his third suggestion (he should be, he suggested it :-)), I think we are good to go. |
I don't have a problem adding the missing code to |
@mscdex Just to make sure I'm understanding: You're OK with this landing without the lazy loading? That can be implemented in a subsequent PR or not at all and that's OK? |
@Trott My comment about the |
Landed in 19aa41c |
PR-URL: nodejs#22003 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This should be backported along with #21616 |
PR-URL: nodejs#22003 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This completes #21616 by adding https which was inadvertently left out.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes