Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

rubys
Copy link
Member

@rubys rubys commented Jul 1, 2018

fixes #20795

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the http Issues or PRs related to the http subsystem. label Jul 1, 2018
@rubys rubys force-pushed the issue-20795 branch 2 times, most recently from 8674cbb to 211140a Compare July 1, 2018 15:11
doc/api/http.md Outdated
<!-- YAML
added: v0.3.6
changes:
- version: v11.0.0
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/options/`options`/

@rubys
Copy link
Member Author

rubys commented Jul 1, 2018

Notes:

  • went with a 3-arg signature with options overriding path if there is overlap (based on comment by @joyeecheung .
  • should be 100% backward compatible as URL is optional.
  • not sure how to test that the callback was identified correctly other than to run some requests and ensure that the callback is called. Not sure it is worth it?
  • HTTP/2 function signatures are enough different that this does not apply there.
  • HTTPS changes are doc only

@vsemozhetbyt
Copy link
Contributor

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 #http_http_request_url_options_callback):

https://github.com/nodejs/node/blame/3d04e6c9a5522b6391a4a914ca16f2337abb35e7/doc/api/deprecations.md#L1042

https://github.com/nodejs/node/blame/8ab7ea6eed76d069dfd82684e2157e7d88badebf/doc/api/http.md#L2068

https://github.com/nodejs/node/blame/67790962daccb5ff19c977119d7231cbe175c206/doc/api/https.md#L365

@vsemozhetbyt
Copy link
Contributor

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])
Copy link
Contributor

@mscdex mscdex Jul 1, 2018

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.

Copy link
Member Author

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({ }).

Copy link
Member Author

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().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc/api/https.md Outdated
<!-- YAML
added: v0.3.6
changes:
- version: v11.0.0
Copy link
Contributor

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' });
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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()`.?

@vsemozhetbyt vsemozhetbyt added the https Issues or PRs related to the https subsystem. label Jul 1, 2018
@rubys rubys force-pushed the issue-20795 branch 2 times, most recently from ff0ed95 to ea111df Compare July 1, 2018 22:54
@rubys
Copy link
Member Author

rubys commented Jul 1, 2018

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 http.get and https.get have the same signature as their corresponding .request methods, so I updated them too to handle a separate url argument. The test case provided makes use of http.get(), which calls http.request(), which calls ClientRequest() .

@Trott
Copy link
Member

Trott commented Jul 1, 2018

@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()`
Copy link
Contributor

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])
Copy link
Contributor

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])
Copy link
Contributor

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();
Copy link
Contributor

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.

} else {
options = util._extend({}, options);
if (cb) throw new ERR_INVALID_ARG_TYPE('url', ['string', 'URL'], input);
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@rubys
Copy link
Member Author

rubys commented Jul 26, 2018

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.

targos pushed a commit to targos/node that referenced this pull request Aug 2, 2018
Fixes: nodejs#20795
PR-URL: nodejs#21616
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ron Korving <ron@ronkorving.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
targos pushed a commit that referenced this pull request Aug 7, 2018
Fixes: #20795
PR-URL: #21616
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Ron Korving <ron@ronkorving.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>

Backport-PR-URL: #21880
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
rvagg added a commit that referenced this pull request Aug 13, 2018
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
rvagg added a commit that referenced this pull request Aug 15, 2018
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)
rvagg added a commit that referenced this pull request Aug 16, 2018
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)
rvagg added a commit that referenced this pull request Aug 16, 2018
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)
tniessen added a commit to tniessen/node that referenced this pull request Sep 19, 2018
@tniessen tniessen mentioned this pull request Sep 19, 2018
3 tasks
tniessen added a commit that referenced this pull request Sep 19, 2018
PR-URL: #22949
Refs: #21616
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@targos targos added this to Backported in v10.x Sep 23, 2018
targos pushed a commit that referenced this pull request Sep 25, 2018
PR-URL: #22949
Refs: #21616
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
@refack refack mentioned this pull request Oct 18, 2018
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
http Issues or PRs related to the http subsystem. https Issues or PRs related to the https subsystem. semver-minor PRs that contain new features and should be released in the next minor version.
Projects
No open projects
v10.x
  
Backported
Development

Successfully merging this pull request may close these issues.

http: Using URL with http.request (feature suggestion)