diff --git a/tests/config/testserver/index.ts b/tests/config/testserver/index.ts index 7538badf9de6c..91f8d8840fb12 100644 --- a/tests/config/testserver/index.ts +++ b/tests/config/testserver/index.ts @@ -20,7 +20,6 @@ import type http from 'http'; import mime from 'mime'; import type net from 'net'; import path from 'path'; -import url from 'url'; import util from 'util'; import type stream from 'stream'; import ws from 'ws'; @@ -90,7 +89,7 @@ export class TestServer { this._upgradeCallback({ doUpgrade, socket }); return; } - const pathname = url.parse(request.url!).path; + const pathname = new URL(request.url, 'http://localhost').pathname; if (pathname === '/ws-401') { socket.write('HTTP/1.1 401 Unauthorized\r\n\r\nUnauthorized body'); socket.destroy(); @@ -218,10 +217,11 @@ export class TestServer { }); request.on('end', () => resolve(Buffer.concat(chunks))); }); - const path = url.parse(request.url!).path; - this.debugServer(`request ${request.method} ${path}`); - if (this._auths.has(path)) { - const auth = this._auths.get(path)!; + const url = new URL(request.url, 'http://localhost'); + const pathWithSearch = url.pathname + url.search; + this.debugServer(`request ${request.method} ${pathWithSearch}`); + if (this._auths.has(pathWithSearch)) { + const auth = this._auths.get(pathWithSearch)!; const credentials = Buffer.from((request.headers.authorization || '').split(' ')[1] || '', 'base64').toString(); this.debugServer(`request credentials ${credentials}`); this.debugServer(`actual credentials ${auth.username}:${auth.password}`); @@ -233,11 +233,11 @@ export class TestServer { } } // Notify request subscriber. - if (this._requestSubscribers.has(path)) { - this._requestSubscribers.get(path)![fulfillSymbol].call(null, request); - this._requestSubscribers.delete(path); + if (this._requestSubscribers.has(pathWithSearch)) { + this._requestSubscribers.get(pathWithSearch)![fulfillSymbol].call(null, request); + this._requestSubscribers.delete(pathWithSearch); } - const handler = this._routes.get(path); + const handler = this._routes.get(pathWithSearch); if (handler) handler.call(null, request, response); else @@ -251,7 +251,7 @@ export class TestServer { } private async _serveFile(request: http.IncomingMessage, response: http.ServerResponse, filePath?: string): Promise { - let pathName = url.parse(request.url!).path; + let pathName = new URL(request.url, 'http://localhost').pathname; if (!filePath) { if (pathName === '/') pathName = '/index.html'; diff --git a/tests/third_party/proxy/index.ts b/tests/third_party/proxy/index.ts index e3faaec65741d..b3b4c450f2d65 100644 --- a/tests/third_party/proxy/index.ts +++ b/tests/third_party/proxy/index.ts @@ -1,6 +1,5 @@ import assert from 'assert'; import * as net from 'net'; -import * as url from 'url'; import * as http from 'http'; import * as os from 'os'; import { pipeline } from 'stream/promises'; @@ -101,7 +100,7 @@ async function onrequest( } socket.resume(); - const parsed = url.parse(req.url || '/'); + const parsed = new URL(req.url, 'http://localhost'); // setup outbound proxy request HTTP headers const headers: http.OutgoingHttpHeaders = {}; @@ -197,8 +196,7 @@ async function onrequest( } let gotResponse = false; - const proxyReq = http.request({ - ...parsed, + const proxyReq = http.request(parsed, { method: req.method, headers, localAddress: this.localAddress,