Skip to content

Commit

Permalink
doc: use the WHATWG URL API in http code examples
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
watson committed Oct 11, 2019
1 parent a350d8b commit 5909532
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions doc/api/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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');
Expand Down

0 comments on commit 5909532

Please sign in to comment.