Skip to content

Commit a117bcc

Browse files
vladimir-trifonovjasnell
authored andcommitted
doc: Add URL argument with http/https request
PR-URL: #13405 Fixes: #13383 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]>
1 parent 68e06e6 commit a117bcc

File tree

2 files changed

+55
-10
lines changed

2 files changed

+55
-10
lines changed

doc/api/http.md

+26-4
Original file line numberDiff line numberDiff line change
@@ -1568,9 +1568,13 @@ added to the [`'request'`][] event.
15681568
## http.get(options[, callback])
15691569
<!-- YAML
15701570
added: v0.3.6
1571+
changes:
1572+
- version: v7.5.0
1573+
pr-url: https://github.com/nodejs/node/pull/10638
1574+
description: The `options` parameter can be a WHATWG `URL` object.
15711575
-->
15721576

1573-
* `options` {Object | string} Accepts the same `options` as
1577+
* `options` {Object | string | URL} Accepts the same `options` as
15741578
[`http.request()`][], with the `method` always set to `GET`.
15751579
Properties that are inherited from the prototype are ignored.
15761580
* `callback` {Function}
@@ -1636,9 +1640,13 @@ requests.
16361640
## http.request(options[, callback])
16371641
<!-- YAML
16381642
added: v0.3.6
1643+
changes:
1644+
- version: v7.5.0
1645+
pr-url: https://github.com/nodejs/node/pull/10638
1646+
description: The `options` parameter can be a WHATWG `URL` object.
16391647
-->
16401648

1641-
* `options` {Object | string}
1649+
* `options` {Object | string | URL}
16421650
* `protocol` {string} Protocol to use. Defaults to `http:`.
16431651
* `host` {string} A domain name or IP address of the server to issue the
16441652
request to. Defaults to `localhost`.
@@ -1677,8 +1685,9 @@ added: v0.3.6
16771685
Node.js maintains several connections per server to make HTTP requests.
16781686
This function allows one to transparently issue requests.
16791687

1680-
`options` can be an object or a string. If `options` is a string, it is
1681-
automatically parsed with [`url.parse()`][].
1688+
`options` can be an object, a string, or a [`URL`][] object. If `options` is a
1689+
string, it is automatically parsed with [`url.parse()`][]. If it is a [`URL`][]
1690+
object, it will be automatically converted to an ordinary `options` object.
16821691

16831692
The optional `callback` parameter will be added as a one time listener for
16841693
the [`'response'`][] event.
@@ -1750,13 +1759,26 @@ There are a few special headers that should be noted.
17501759
* Sending an Authorization header will override using the `auth` option
17511760
to compute basic authentication.
17521761

1762+
Example using a [`URL`][] as `options`:
1763+
1764+
```js
1765+
const { URL } = require('url');
1766+
1767+
const options = new URL('http://abc:[email protected]');
1768+
1769+
const req = http.request(options, (res) => {
1770+
// ...
1771+
});
1772+
```
1773+
17531774
[`'checkContinue'`]: #http_event_checkcontinue
17541775
[`'listening'`]: net.html#net_event_listening
17551776
[`'request'`]: #http_event_request
17561777
[`'response'`]: #http_event_response
17571778
[`Agent`]: #http_class_http_agent
17581779
[`EventEmitter`]: events.html#events_class_eventemitter
17591780
[`TypeError`]: errors.html#errors_class_typeerror
1781+
[`URL`]: url.html#url_the_whatwg_url_api
17601782
[`agent.createConnection()`]: #http_agent_createconnection_options_callback
17611783
[`destroy()`]: #http_agent_destroy
17621784
[`http.Agent`]: #http_class_http_agent

doc/api/https.md

+29-6
Original file line numberDiff line numberDiff line change
@@ -115,15 +115,20 @@ See [`http.listen()`][] for details.
115115
## https.get(options[, callback])
116116
<!-- YAML
117117
added: v0.3.6
118+
changes:
119+
- version: v7.5.0
120+
pr-url: https://github.com/nodejs/node/pull/10638
121+
description: The `options` parameter can be a WHATWG `URL` object.
118122
-->
119-
- `options` {Object | string} Accepts the same `options` as
123+
- `options` {Object | string | URL} Accepts the same `options` as
120124
[`https.request()`][], with the `method` always set to `GET`.
121125
- `callback` {Function}
122126

123127
Like [`http.get()`][] but for HTTPS.
124128

125-
`options` can be an object or a string. If `options` is a string, it is
126-
automatically parsed with [`url.parse()`][].
129+
`options` can be an object, a string, or a [`URL`][] object. If `options` is a
130+
string, it is automatically parsed with [`url.parse()`][]. If it is a [`URL`][]
131+
object, it will be automatically converted to an ordinary `options` object.
127132

128133
Example:
129134

@@ -153,8 +158,12 @@ Global instance of [`https.Agent`][] for all HTTPS client requests.
153158
## https.request(options[, callback])
154159
<!-- YAML
155160
added: v0.3.6
161+
changes:
162+
- version: v7.5.0
163+
pr-url: https://github.com/nodejs/node/pull/10638
164+
description: The `options` parameter can be a WHATWG `URL` object.
156165
-->
157-
- `options` {Object | string} Accepts all `options` from [`http.request()`][],
166+
- `options` {Object | string | URL} Accepts all `options` from [`http.request()`][],
158167
with some differences in default values:
159168
- `protocol` Defaults to `https:`
160169
- `port` Defaults to `443`.
@@ -168,8 +177,9 @@ The following additional `options` from [`tls.connect()`][] are also accepted wh
168177
custom [`Agent`][]:
169178
`pfx`, `key`, `passphrase`, `cert`, `ca`, `ciphers`, `rejectUnauthorized`, `secureProtocol`, `servername`
170179

171-
`options` can be an object or a string. If `options` is a string, it is
172-
automatically parsed with [`url.parse()`][].
180+
`options` can be an object, a string, or a [`URL`][] object. If `options` is a
181+
string, it is automatically parsed with [`url.parse()`][]. If it is a [`URL`][]
182+
object, it will be automatically converted to an ordinary `options` object.
173183

174184
Example:
175185

@@ -235,7 +245,20 @@ const req = https.request(options, (res) => {
235245
});
236246
```
237247

248+
Example using a [`URL`][] as `options`:
249+
250+
```js
251+
const { URL } = require('url');
252+
253+
const options = new URL('https://abc:[email protected]');
254+
255+
const req = https.request(options, (res) => {
256+
// ...
257+
});
258+
```
259+
238260
[`Agent`]: #https_class_https_agent
261+
[`URL`]: url.html#url_the_whatwg_url_api
239262
[`http.Agent`]: http.html#http_class_http_agent
240263
[`http.Server#keepAliveTimeout`]: http.html#http_server_keepalivetimeout
241264
[`http.Server#setTimeout()`]: http.html#http_server_settimeout_msecs_callback

0 commit comments

Comments
 (0)