[Feature Request]: Make it possible to set custom Host header for browser tests
Currently tests starts its own web server (nice!) but it runs on 127.0.0.1:{randomPort}.
And that means my application that uses the domain from Host to determine what language to boot site cannot be tested as it does not respond with anything without any Host.
I tried to set custom Host, but then the web server does not work at all.
it('test', function () {
$options = [
'extraHTTPHeaders' => [
[
'name' => 'Host',
'value' => 'my-domain.com',
],
],
];
$page = visit('/', $options);
$page->assertSee('Something');
});
If I enable --headed --debug when running test, I can check the network requests and it does include the Host, but as I said the built in web server does not start correctly when we set the Host.
My current workaround is to set some other random header, and I write the expected domain inside that header and then my application fetches domain from it and sets it like if it came from Host header.
it('test', function () {
$options = [
'extraHTTPHeaders' => [
[
'name' => 'X-Pest-Browser-Test',
'value' => 'my-domain.com',
],
],
];
$page = visit('/', $options);
$page->assertSee('Something');
});
So it works. But it would be nice to be able to set the Host preferable, but at least be able to set my X-Pest-Browser-Test header in a nicer way than this. Preferable in Pest.php or some other place where I do not need to send $options to all my visit calls.
Im open for any ideas, maybe there is something already and I missed it.
UPDATE: My workaround fails in some cases where a test click some elements that does some kind of ajax requests where it doesnt pass my custom header along such secondary requests. So think something more "built in" support for custom Host would be awesome that ensures its passed to any type of requests that is triggered by Pest actions.