Skip to content
Open
Show file tree
Hide file tree
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
22 changes: 11 additions & 11 deletions tests/config/testserver/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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}`);
Expand All @@ -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
Expand All @@ -251,7 +251,7 @@ export class TestServer {
}

private async _serveFile(request: http.IncomingMessage, response: http.ServerResponse, filePath?: string): Promise<void> {
let pathName = url.parse(request.url!).path;
let pathName = new URL(request.url, 'http://localhost').pathname;
if (!filePath) {
if (pathName === '/')
pathName = '/index.html';
Expand Down
6 changes: 2 additions & 4 deletions tests/third_party/proxy/index.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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,
Expand Down
Loading