-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ const http = require('http'); | |
const util = require('util'); | ||
const inherits = util.inherits; | ||
const debug = util.debuglog('https'); | ||
const urlToOptions = require('internal/url').urlToOptions; | ||
const { urlToOptions, searchParamsSymbol } = require('internal/url'); | ||
|
||
function Server(opts, requestListener) { | ||
if (!(this instanceof Server)) return new Server(opts, requestListener); | ||
|
@@ -221,7 +221,9 @@ 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 commentThe reason will be displayed to describe this comment to others. Learn more. Would a There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Ha! I thought the question sounded familiar as I was typing it ;-) |
||
// url.URL instance | ||
options = urlToOptions(options); | ||
} else { | ||
options = util._extend({}, options); | ||
|
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.