Skip to content

Commit 3155ab4

Browse files
watsontargos
authored andcommitted
doc: use the WHATWG URL API in http code examples
PR-URL: #29917 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: David Carlier <[email protected]>
1 parent b916ea3 commit 3155ab4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

doc/api/http.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ A client and server pair demonstrating how to listen for the `'connect'` event:
353353
```js
354354
const http = require('http');
355355
const net = require('net');
356-
const url = require('url');
356+
const { URL } = require('url');
357357

358358
// Create an HTTP tunneling proxy
359359
const proxy = http.createServer((req, res) => {
@@ -362,8 +362,8 @@ const proxy = http.createServer((req, res) => {
362362
});
363363
proxy.on('connect', (req, cltSocket, head) => {
364364
// Connect to an origin server
365-
const srvUrl = url.parse(`http://${req.url}`);
366-
const srvSocket = net.connect(srvUrl.port, srvUrl.hostname, () => {
365+
const { port, hostname } = new URL(`http://${req.url}`);
366+
const srvSocket = net.connect(port || 80, hostname, () => {
367367
cltSocket.write('HTTP/1.1 200 Connection Established\r\n' +
368368
'Proxy-agent: Node.js-Proxy\r\n' +
369369
'\r\n');

0 commit comments

Comments
 (0)