File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -353,7 +353,7 @@ A client and server pair demonstrating how to listen for the `'connect'` event:
353
353
``` js
354
354
const http = require (' http' );
355
355
const net = require (' net' );
356
- const url = require (' url' );
356
+ const { URL } = require (' url' );
357
357
358
358
// Create an HTTP tunneling proxy
359
359
const proxy = http .createServer ((req , res ) => {
@@ -362,8 +362,8 @@ const proxy = http.createServer((req, res) => {
362
362
});
363
363
proxy .on (' connect' , (req , cltSocket , head ) => {
364
364
// 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, () => {
367
367
cltSocket .write (' HTTP/1.1 200 Connection Established\r\n ' +
368
368
' Proxy-agent: Node.js-Proxy\r\n ' +
369
369
' \r\n ' );
You can’t perform that action at this time.
0 commit comments