-
-
Notifications
You must be signed in to change notification settings - Fork 34.3k
url: allow use of URL with http.request and https.request #10638
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
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -24,6 +24,18 @@ function ClientRequest(options, cb) { | |
| if (!options.hostname) { | ||
| throw new Error('Unable to determine the domain name'); | ||
| } | ||
| } else if (options instanceof url.URL) { | ||
| options = { | ||
| protocol: options.protocol, | ||
| host: options.host, | ||
|
||
| hostname: options.hostname, | ||
| port: options.port, | ||
| hash: options.hash, | ||
| search: options.search, | ||
| pathname: options.pathname, | ||
| path: `${options.pathname}${options.search}`, | ||
| href: options.href | ||
| }; | ||
|
||
| } 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.
If I understand correctly this makes using the new URL api and using additional options(like
agent) mutual exclusive?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.
True, but that's already the case if you pass the URL as a string or the result of
url.parse. We can think later about a way to pass a URL object along with additional options but I don't think it should block this PR.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.
Ah I should have make this one a comment, not a change request :/ Sorry.
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.
No worries!
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.
Yes, making those mutually exclusive is intentional. Attaching additional non-standard properties to the URL object is not something that we should promote. And as @targos points out, that is already the case when passing the URL as a string.