Skip to content
Permalink
Browse files

doc: use the WHATWG URL API in http code examples

PR-URL: #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>
  • Loading branch information
watson authored and targos committed Oct 10, 2019
1 parent b916ea3 commit 3155ab4134aad2602c907b6275ce1c6eb0baeccb
Showing with 3 additions and 3 deletions.
  1. +3 −3 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');

0 comments on commit 3155ab4

Please sign in to comment.
You can’t perform that action at this time.