-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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,https: avoid instanceof for WHATWG URL #12983
Conversation
@@ -218,7 +218,8 @@ exports.request = function request(options, cb) { | |||
if (!options.hostname) { | |||
throw new Error('Unable to determine the domain name'); | |||
} | |||
} else if (options instanceof url.URL) { | |||
} else if (options && options[searchParamsSymbol] && | |||
options[searchParamsSymbol][searchParamsSymbol]) { |
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.
Would a require('internal/url').isURL()
utility function be worthwhile to make this more convenient? Or would that kill any perf gain? I imagine wanting to use similar checks elsewhere.
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.
See here.
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.
Ha! I thought the question sounded familiar as I was typing it ;-)
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.
It's unfortunate we can't write an isURL
without performance regression, but 🤷♂️
@@ -82,7 +82,8 @@ function ClientRequest(options, cb) { | |||
if (!options.hostname) { | |||
throw new Error('Unable to determine the domain name'); | |||
} | |||
} else if (options instanceof url.URL) { | |||
} else if (options && options[searchParamsSymbol] && | |||
options[searchParamsSymbol][searchParamsSymbol]) { |
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 am now wondering if this way of checking URLs is a bit hard to understand for someone who don't know the implementation details of URL...
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.
There's not a whole lot that can be done about that. Using a helper function as previously noted incurs a measurable performance hit.
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.
@mscdex Maybe a comment would help?
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.
Done.
43954e6
to
41ea7e9
Compare
CI before landing: https://ci.nodejs.org/job/node-test-pull-request/8234/ |
PR-URL: nodejs#12983 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
41ea7e9
to
ed36565
Compare
PR-URL: #12983 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: #12983 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Benchmark results:
CI: https://ci.nodejs.org/job/node-test-pull-request/8025/
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)