Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorTadao Iseki <saitoeku3@gmail.com>2019-12-07 07:20:20 +0300
committerRich Trott <rtrott@gmail.com>2019-12-18 08:11:39 +0300
commiteaf59754be421498287a7bf2471b83e629da1911 (patch)
tree224da5ac2455d78745b803a4078956046d9f3a66 /doc
parentea86f8c902e13d8cff0e01007ed0d978f59fe132 (diff)
doc: update message.url example in http.IncomingMessage
Update message.url example to use The WHATWG URL API. This is because the old example suggests using deprecated url API. Fixes: https://github.com/nodejs/node/issues/30048 PR-URL: https://github.com/nodejs/node/pull/30830 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/http.md56
1 files changed, 17 insertions, 39 deletions
diff --git a/doc/api/http.md b/doc/api/http.md
index 3550136aebb..8c04ef2ecbb 100644
--- a/doc/api/http.md
+++ b/doc/api/http.md
@@ -1979,54 +1979,32 @@ Accept: text/plain\r\n
\r\n
```
-Then `request.url` will be:
+To parse the URL into its parts:
-<!-- eslint-disable semi -->
```js
-'/status?name=ryan'
+new URL(request.url, `http://${request.headers.host}`);
```
-To parse the url into its parts `require('url').parse(request.url)`
-can be used:
+When `request.url` is `'/status?name=ryan'` and
+`request.headers.host` is `'localhost:3000'`:
```console
$ node
-> require('url').parse('/status?name=ryan')
-Url {
- protocol: null,
- slashes: null,
- auth: null,
- host: null,
- port: null,
- hostname: null,
- hash: null,
- search: '?name=ryan',
- query: 'name=ryan',
+> new URL(request.url, request.headers.host)
+URL {
+ href: 'http://localhost:3000/status?name=ryan',
+ origin: 'http://localhost:3000',
+ protocol: 'http:',
+ username: '',
+ password: '',
+ host: 'localhost:3000',
+ hostname: 'localhost',
+ port: '3000',
pathname: '/status',
- path: '/status?name=ryan',
- href: '/status?name=ryan' }
-```
-
-To extract the parameters from the query string, the
-`require('querystring').parse` function can be used, or
-`true` can be passed as the second argument to `require('url').parse`:
-
-```console
-$ node
-> require('url').parse('/status?name=ryan', true)
-Url {
- protocol: null,
- slashes: null,
- auth: null,
- host: null,
- port: null,
- hostname: null,
- hash: null,
search: '?name=ryan',
- query: { name: 'ryan' },
- pathname: '/status',
- path: '/status?name=ryan',
- href: '/status?name=ryan' }
+ searchParams: URLSearchParams { 'name' => 'ryan' },
+ hash: ''
+}
```
## http.METHODS