With Playwright in a container, I want to have it call 'example.com', and when it does, reroute that request to some other domain, such as httpbin.org. In my case this would be a load balancer.
How it works - Playwright uses its proxy feature and calls Squid.
The Squid container has been configured to think that example.com is on the nginx container's IP address.
Nginx just uses TCP forwarding and sends the request on to httpbin.org.
Nginx doesn't use HTTP proxying because then it would need to host a certificate.
Bring up the nginx and squid
docker compose up nginx squid
Set Playwright to use Squid proxy
proxy: {
server: 'http://127.0.0.1:3128',
}
And have it go to /anything on the domain which translates to httpbin.org/anything
await page.goto('https://example.com/anything');
When you run npx playwright test --headed
, and it goes to https://example.com/anything
, the request goes to Squid which resolves the DNS to nginx, which takes the request and sends it on to https://httpbin.org/anything
. The resopnse from httpbin.org/anything shows 'example.com' as the Host header.