From 84b6ae3bebabf3a4333880a3a2bd80b80dae0d8f Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Thu, 10 Oct 2019 11:05:48 +0200 Subject: [PATCH] doc: use the WHATWG URL API in http code examples --- doc/api/http.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/api/http.md b/doc/api/http.md index 73de8c36b235df..943e7929c64e25 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');