Skip to content

Commit e30ec52

Browse files
committed
Replace deprecated url.parse() with WHATWG URL API in proxy package
Use `new URL()` instead of `url.parse()` to eliminate the DEP0169 deprecation warning. Strip IPv6 bracket notation from hostname since `new URL()` preserves brackets (e.g. `[::]`) unlike `url.parse()` which returned bare addresses.
1 parent 549af5e commit e30ec52

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

packages/proxy/src/proxy.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import assert from 'assert';
22
import * as net from 'net';
3-
import * as url from 'url';
43
import * as http from 'http';
54
import * as os from 'os';
65
import pkg from './pkg.js';
@@ -98,7 +97,7 @@ async function onrequest(
9897
}
9998

10099
socket.resume();
101-
const parsed = url.parse(req.url || '/');
100+
const parsed = new URL(req.url || '/', 'http://localhost');
102101

103102
// setup outbound proxy request HTTP headers
104103
const headers: http.OutgoingHttpHeaders = {};
@@ -195,7 +194,10 @@ async function onrequest(
195194

196195
let gotResponse = false;
197196
const proxyReq = http.request({
198-
...parsed,
197+
protocol: parsed.protocol,
198+
hostname: parsed.hostname.replace(/^\[|]$/g, ''),
199+
port: parsed.port,
200+
path: parsed.pathname + parsed.search,
199201
method: req.method,
200202
headers,
201203
localAddress: this.localAddress,

0 commit comments

Comments
 (0)