fix(proxy): preserve HTTP env proxy request target#40395
Conversation
@ agree company="OpenAI" |
@microsoft-github-policy-service agree company="OpenAI" |
Skn0tt
left a comment
There was a problem hiding this comment.
Hi Noah, thanks for the PR. The change looks good, what a subtle bug :/
Could you shorten the test a little? This should be good, I think:
test('should use env proxy with connectOverCDP discovery request', async ({ browserType, server, proxyServer, mode }) => {
test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/40394' });
test.skip(mode !== 'default'); // Out of process transport does not allow us to set env vars dynamically.
proxyServer.forwardTo(server.PORT);
const oldValue = process.env.HTTP_PROXY;
try {
process.env.HTTP_PROXY = proxyServer.URL;
await browserType.connectOverCDP(server.PREFIX).catch(() => {});
expect(proxyServer.requestUrls).toEqual([`${server.PREFIX}/json/version/`]);
} finally {
process.env.HTTP_PROXY = oldValue;
}
});The HTTPS_PROXY env var doesn't matter in this context.
3c518d7 to
56f6bbf
Compare
Done, thanks for simplifying! |
Test results for "MCP"2 failed 6675 passed, 928 skipped Merge workflow run. |
Test results for "tests 1"10 flaky41452 passed, 847 skipped Merge workflow run. |
Summary
Fixes HTTP proxy handling in
httpRequest()when proxy settings come from environment variables.When
http_proxy/HTTP_PROXYis set andNO_PROXYis empty,connectOverCDP("http://localhost:<port>")performs CDP discovery through the proxy by requesting/json/version/.In the broken path, Playwright mutates the proxy URL pathname
Because
URL.pathnamenormalizes the value as a path, this serializes the request target asFor HTTP proxying, the request target must remain absolute-form
This patch stores the original target URL in
options.pathinstead, preserving the correct proxy request target while still sending the request to the proxy server.Related context
Testing
Before the fix, the regression test fails with
After the fix, the test passes
fixes #40394