-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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: allow url and options to be passed to http.request #21616
Conversation
8674cbb
to
211140a
Compare
doc/api/http.md
Outdated
<!-- YAML | ||
added: v0.3.6 | ||
changes: | ||
- version: v11.0.0 |
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.
version fields for additions/removals/changes should always have a value of REPLACEME
doc/api/http.md
Outdated
@@ -1920,10 +1924,13 @@ changes: | |||
Node.js maintains several connections per server to make HTTP requests. | |||
This function allows one to transparently issue requests. | |||
|
|||
`options` can be an object, a string, or a [`URL`][] object. If `options` is a | |||
`url` can be an a string or a [`URL`][] object. If `url` is a |
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 should only be one space between 'string' and 'or' 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.
be an a
-> be a
doc/api/http.md
Outdated
string, it is automatically parsed with [`new URL()`][]. If it is a [`URL`][] | ||
object, it will be automatically converted to an ordinary `options` object. | ||
|
||
if both `url` and `options` are specified, the objects are merged, with the |
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.
s/if/If/
doc/api/http.md
Outdated
string, it is automatically parsed with [`new URL()`][]. If it is a [`URL`][] | ||
object, it will be automatically converted to an ordinary `options` object. | ||
|
||
if both `url` and `options` are specified, the objects are merged, with the | ||
options properties taking precedence. |
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.
s/options/`options`/
Notes:
|
Doc section headings affect autogenerated sections ids for section links. So each time we change a heading, we need to grep for the old hash and update all found instances. Currently, it seems these instances need to be updated (with |
Also these for https change (with |
doc/api/http.md
Outdated
@@ -1869,16 +1869,20 @@ added: v0.5.9 | |||
Global instance of `Agent` which is used as the default for all HTTP client | |||
requests. | |||
|
|||
## http.request(options[, callback]) | |||
## http.request([url] [, options] [, callback]) |
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 feel like this should be something like: input[, options][, callback]
to show that at least one argument is required and not that both are optional with perhaps additional explanation below or follow in the footsteps of documented functions like this and show multiple signatures for the same function. I'm not sure if we have a standard yet for showing multiple signatures for more complicated situations.
Ditto for https.request
.
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 followed the example of response.end.
I don't think it is a good idea to describe the syntax in a way that implies that url is required even if subsequent text says to ignore that implication.
Technically, nothing is required, as http.request()
would be evaluated the same as http.request({ })
.
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.
Also, http.request
accepts a url
parameter despite ClientRequest giving this argument a different name so as to not collide with the url
package which was previously required. Chose the name input
based on Request().
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.
FWIW, we have a section with various signatures:
https://nodejs.org/docs/latest/api/console.html#console_new_console_stdout_stderr_ignoreerrors
https://nodejs.org/docs/latest/api/console.html#console_new_console_options
doc/api/https.md
Outdated
<!-- YAML | ||
added: v0.3.6 | ||
changes: | ||
- version: v11.0.0 |
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.
Ditto about REPLACEME
const http = require('http'); | ||
|
||
// two arguments: URL + options | ||
const request = http.request('http://example.com', { path: '/path' }); |
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 think it would be better to have a real test by setting up a local http.Server
on a random port, connecting to that, and verifying the path and such inside the incoming connection handler (wrapped in a common.mustCall()
).
doc/api/http.md
Outdated
<!-- YAML | ||
added: v0.3.6 | ||
changes: | ||
- version: v11.0.0 | ||
pr-url: https://github.com/nodejs/node/pull/21616 | ||
description: allow url and options to be passed to http.request |
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.
Allow URL and options to be passed to `http.request()`.
?
doc/api/http.md
Outdated
@@ -1920,10 +1924,13 @@ changes: | |||
Node.js maintains several connections per server to make HTTP requests. | |||
This function allows one to transparently issue requests. | |||
|
|||
`options` can be an object, a string, or a [`URL`][] object. If `options` is a | |||
`url` can be an a string or a [`URL`][] object. If `url` is a |
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.
be an a
-> be a
doc/api/https.md
Outdated
<!-- YAML | ||
added: v0.3.6 | ||
changes: | ||
- version: v11.0.0 | ||
pr-url: https://github.com/nodejs/node/pull/21616 | ||
description: allow url and options to be passed to http.request |
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.
Allow URL and options to be passed to `https.request()`.
?
ff0ed95
to
ea111df
Compare
If we go with providing multiple signatures in the documentation, there is no need to update the autogenerated sections ids for section links. I still have a mild preference and believe that there is precedence for a function with all optional arguments, but I sense that I'm in the minority with that opinion. Also, I noted that |
@nodejs/http |
doc/api/https.md
Outdated
<!-- YAML | ||
added: v0.3.6 | ||
changes: | ||
- version: REPLACEME | ||
pr-url: https://github.com/nodejs/node/pull/21616 | ||
description: allow both url and options to be passed to `http.get()` |
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.
http -> https
doc/api/https.md
Outdated
@@ -154,18 +159,22 @@ added: v0.5.9 | |||
|
|||
Global instance of [`https.Agent`][] for all HTTPS client requests. | |||
|
|||
## https.request(options[, callback]) | |||
## https.request([[url [,options] [, callback]) |
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.
Should there also be 2 headings?
doc/api/http.md
Outdated
@@ -1798,15 +1798,20 @@ The `requestListener` is a function which is automatically | |||
added to the [`'request'`][] event. | |||
|
|||
## http.get(options[, callback]) | |||
## http.get(url [, options] [, callback]) |
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.
Other signatures usually use fewer spaces, like (url[, options][, callback])
.
{ hostname: 'localhost', port: server.address().port }, | ||
common.mustCall((res) => { | ||
res.on('close', common.mustCall(() => { | ||
server.close(); |
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 think this could be moved to the server's request handler.
lib/_http_client.js
Outdated
} else { | ||
options = util._extend({}, options); | ||
if (cb) throw new ERR_INVALID_ARG_TYPE('url', ['string', 'URL'], input); |
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 think this would make this PR a semver-major change, and I'd like to avoid that if possible. How about we just remove this check?
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
I started to look at the backport (rubys@cbe9d7d), and found that the test/parallel/test-http-invalid-urls.js test was failing. While looking into that failure, I noticed that the https support is incomplete (there should have been a small change to lib/https.js, but it isn't there). I'll look into completing this change (with a new pull request, and ensuring that there is a test for https), and then circle back to backport both to 10.x. |
Fixes: nodejs#20795 PR-URL: nodejs#21616 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Ron Korving <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Fixes: #20795 PR-URL: #21616 Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Ron Korving <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Backport-PR-URL: #21880 Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Notable changes: * deps: Upgrade V8 from 6.7 to 6.8 (Michaël Zasso) #21079 * Memory reduction and performance improvements, details at: https://v8project.blogspot.com/2018/06/v8-release-68.html * fs: Implement a fs.mkdir() recursive option, similar to the mkdirp npm package or mkdir -p on the command line (Benjamin Coe) #21875 * http: http.get() and http.request() (and https variants) can now accept three arguments to allow for a URL and an options object (Sam Ruby) #21616
Notable changes: * deps: Upgrade V8 from 6.7 to 6.8 (Michaël Zasso) #21079 * Memory reduction and performance improvements, details at: https://v8project.blogspot.com/2018/06/v8-release-68.html * fs: Implement a fs.mkdir() recursive option, similar to the mkdirp npm package or mkdir -p on the command line (Benjamin Coe) #21875 * http: http.get() and http.request() (and https variants) can now accept three arguments to allow for a URL and an options object (Sam Ruby) #21616 * Added new collaborators * Sam Ruby (https://github.com/rubys) * George Adams (https://github.com/gdams)
Notable changes: * buffer: * Fix out-of-bounds (OOB) write in `Buffer.write()` for UCS-2 encoding (CVE-2018-12115) * Fix unintentional exposure of uninitialized memory in `Buffer.alloc()` (CVE-2018-7166) * deps: * Upgrade to OpenSSL 1.1.0i, fixing: - Client DoS due to large DH parameter (CVE-2018-0732) - ECDSA key extraction via local side-channel (CVE not assigned) * Upgrade V8 from 6.7 to 6.8 (Michaël Zasso) #21079 - Memory reduction and performance improvements, details at: https://v8project.blogspot.com/2018/06/v8-release-68.html * http: `http.get()` and `http.request()` (and `https` variants) can now accept three arguments to allow for a `URL` _and_ an `options` object (Sam Ruby) #21616 * Added new collaborators * Sam Ruby (https://github.com/rubys) * George Adams (https://github.com/gdams)
Notable changes: * buffer: * Fix out-of-bounds (OOB) write in `Buffer.write()` for UCS-2 encoding (CVE-2018-12115) * Fix unintentional exposure of uninitialized memory in `Buffer.alloc()` (CVE-2018-7166) * deps: * Upgrade to OpenSSL 1.1.0i, fixing: - Client DoS due to large DH parameter (CVE-2018-0732) - ECDSA key extraction via local side-channel (CVE not assigned) * Upgrade V8 from 6.7 to 6.8 (Michaël Zasso) #21079 - Memory reduction and performance improvements, details at: https://v8project.blogspot.com/2018/06/v8-release-68.html * http: `http.get()` and `http.request()` (and `https` variants) can now accept three arguments to allow for a `URL` _and_ an `options` object (Sam Ruby) #21616 * Added new collaborators * Sam Ruby (https://github.com/rubys) * George Adams (https://github.com/gdams)
PR-URL: #22949 Refs: #21616 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
PR-URL: #22949 Refs: #21616 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
fixes #20795
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes