summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorThomas Watson <w@tson.dk>2019-10-10 11:05:48 +0200
committerThomas Watson <w@tson.dk>2019-10-11 13:52:16 +0200
commit5909532aace7412c5988bbfe2c777333aea2fd94 (patch)
treefc92749ed55903e0f3833604e67987597591be67 /doc
parenta350d8b7805765744a10415551bd4a741b6519ff (diff)
downloadandroid-node-v8-5909532aace7412c5988bbfe2c777333aea2fd94.tar.gz
android-node-v8-5909532aace7412c5988bbfe2c777333aea2fd94.tar.bz2
android-node-v8-5909532aace7412c5988bbfe2c777333aea2fd94.zip
doc: use the WHATWG URL API in http code examples
PR-URL: https://github.com/nodejs/node/pull/29917 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/http.md6
1 files changed, 3 insertions, 3 deletions
diff --git a/doc/api/http.md b/doc/api/http.md
index 0d98c91b93..351add59b5 100644
--- a/doc/api/http.md
+++ b/doc/api/http.md
@@ -353,7 +353,7 @@ A client and server pair demonstrating how to listen for the `'connect'` event:
```js
const http = require('http');
const net = require('net');
-const url = require('url');
+const { URL } = require('url');
// Create an HTTP tunneling proxy
const proxy = http.createServer((req, res) => {
@@ -362,8 +362,8 @@ const proxy = http.createServer((req, res) => {
});
proxy.on('connect', (req, cltSocket, head) => {
// Connect to an origin server
- const srvUrl = url.parse(`http://${req.url}`);
- const srvSocket = net.connect(srvUrl.port, srvUrl.hostname, () => {
+ const { port, hostname } = new URL(`http://${req.url}`);
+ const srvSocket = net.connect(port || 80, hostname, () => {
cltSocket.write('HTTP/1.1 200 Connection Established\r\n' +
'Proxy-agent: Node.js-Proxy\r\n' +
'\r\n');