Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
doc: use the WHATWG URL API in http code examples
  • Loading branch information
watson committed Oct 10, 2019
commit 84b6ae3bebabf3a4333880a3a2bd80b80dae0d8f
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' +
Comment thread
watson marked this conversation as resolved.
'\r\n');
Expand Down