special case for ui mode proxy

This commit is contained in:
Simon Knott 2024-11-29 15:44:13 +01:00
parent 62c5fb29d1
commit 2e019eb746
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 10 additions and 4 deletions

View file

@ -59,11 +59,14 @@ export class TestProxy {
await new Promise(x => this._server.close(x));
}
forwardTo(port: number, options?: { allowConnectRequests?: boolean, prefix?: string }) {
forwardTo(port: number, options?: { allowConnectRequests?: boolean, prefix?: string, dontTouchHost?: boolean }) {
this._prependHandler('request', (req: IncomingMessage) => {
this.requestUrls.push(req.url);
const url = new URL(req.url, `http://${req.headers.host}`);
url.host = `127.0.0.1:${port}`;
if (options?.dontTouchHost)
url.port = '' + port;
else
url.host = `127.0.0.1:${port}`;
if (options?.prefix)
url.pathname = url.pathname.replace(options.prefix, '');
req.url = url.toString();
@ -79,7 +82,10 @@ export class TestProxy {
this._prependHandler('upgrade', (req: IncomingMessage) => {
this.wsUrls.push(req.url);
const url = new URL(req.url, `http://${req.headers.host}`);
url.host = `127.0.0.1:${port}`;
if (options?.dontTouchHost)
url.port = '' + port;
else
url.host = `127.0.0.1:${port}`;
if (options?.prefix)
url.pathname = url.pathname.replace(options.prefix, '');
req.url = url.toString();

View file

@ -353,7 +353,7 @@ test('should work behind proxy', { annotation: { type: 'issue', description: 'ht
});
const origin = new URL(page.url());
proxyServer.forwardTo(+origin.port, { prefix: '/subdir' });
proxyServer.forwardTo(+origin.port, { prefix: '/subdir', dontTouchHost: true });
await page.goto(`${proxyServer.URL}/subdir${origin.pathname}?${origin.searchParams}`);
await page.getByText('trace test').dblclick();