address feedback

This commit is contained in:
Simon Knott 2024-12-18 11:40:40 +01:00
parent 41aeb0ee56
commit 9087dd7af6
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 7 additions and 7 deletions

View file

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

View file

@ -340,7 +340,7 @@ test('should show request source context id', async ({ runUITest, server }) => {
await expect(page.getByText('api#1')).toBeVisible(); await expect(page.getByText('api#1')).toBeVisible();
}); });
test('should work behind proxy', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33705' } }, async ({ runUITest, proxyServer }, testInfo) => { test('should work behind reverse proxy', { annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/33705' } }, async ({ runUITest, proxyServer: reverseProxy }) => {
const { page } = await runUITest({ const { page } = await runUITest({
'a.test.ts': ` 'a.test.ts': `
import { test, expect } from '@playwright/test'; import { test, expect } from '@playwright/test';
@ -352,9 +352,9 @@ test('should work behind proxy', { annotation: { type: 'issue', description: 'ht
`, `,
}); });
const origin = new URL(page.url()); const uiModeUrl = new URL(page.url());
proxyServer.forwardTo(+origin.port, { prefix: '/subdir', dontTouchHost: true }); reverseProxy.forwardTo(+uiModeUrl.port, { prefix: '/subdir', preserveHostname: true });
await page.goto(`${proxyServer.URL}/subdir${origin.pathname}?${origin.searchParams}`); await page.goto(`${reverseProxy.URL}/subdir${uiModeUrl.pathname}?${uiModeUrl.searchParams}`);
await page.getByText('trace test').dblclick(); await page.getByText('trace test').dblclick();