-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[BrowserKit] Corrected HTTP_HOST logic #16265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BrowserKit] Corrected HTTP_HOST logic #16265
Conversation
if (!$this->history->isEmpty()) { | ||
$server['HTTP_REFERER'] = $this->history->current()->getUri(); | ||
} | ||
|
||
$server['HTTP_HOST'] = $this->extractHost($uri); | ||
if (empty($server['HTTP_HOST'])) { | ||
$server['HTTP_HOST'] = $this->extractHost($uri); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indentation is wrong, should be increments of 4 spaces.
Looks like a bug to me and as such should be merged in 2.3 (@Naktibalda no need to re-create another PR as I can do the switch when merging). ping @dunglas |
👍 |
👍, but maybe should we emulate |
@dunglas but that's a different topic. |
Thank you @Naktibalda. |
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #16265). Discussion ---------- [BrowserKit] Corrected HTTP_HOST logic HTTP_HOST is just a header - it does not override URI, uri does not override HTTP_HOST header. If HTTP_HOST is not set then and only then hostname is extracted from uri. | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | #15398 | License | MIT | Doc PR | Commits ------- b5f524d [BrowserKit] Corrected HTTP_HOST logic #15398
This change broke our test cases for testing domain specific behavior that we were testing with
In case anyone runs into the same issue, we now use this code for the test:
|
I ran into the same issue as @advancingu. |
Please open a new issue if you think there's been a regression introduced. |
This PR was merged into the 2.8 branch. Discussion ---------- [BrowserKit] fixed BC Break for HTTP_HOST header | Q | A | ------------- | --- | Branch? | 2.7, 2.8, 3.x, 4.x | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes/no | Fixed tickets | #22933 | License | MIT | Doc PR | n/a The situation well described in the original issue. I will add only: - #10549 - makes server parameters to take precedence over URI. - #16265 - partially revererts #10549. Makes server parameters do not affect URI. But this is only true for `Client::request()`. It is still possible to set host for URI by `Client::setServerParameters()` when URI is realative (see examples below). I propose a compromise solution: add to HTTP_HOST header power to override URI when it is relative. Proposed solution: - if the request URI is relative, then use the HTTP_HOST header passed to Client::request() to generate an absolute URI - if the request URI is absolute, then ignore the HTTP_HOST header (as it now works) - do the same with HTTPS server parameter Profit: - fix BC Break - the documentation will be correct - http://symfony.com/doc/2.8/routing/hostname_pattern.html#testing-your-controllers - https://symfony.com/doc/2.8/testing.html#testing-configuration Before: ``` $client->setServerParameters(['HTTP_HOST' => 'example.com']); $client->request('GET', '/'); $this->assertEquals('http://example.com/', $client->getRequest()->getUri()); $client->request('GET', '/', [], [], ['HTTP_HOST' => 'example.com']); $this->assertEquals('http://localhost/', $client->getRequest()->getUri()); ``` Fixed (see last line): ``` $client->setServerParameters(['HTTP_HOST' => 'example.com']); $client->request('GET', '/'); $this->assertEquals('http://example.com/', $client->getRequest()->getUri()); $client->request('GET', '/', [], [], ['HTTP_HOST' => 'example.com']); $this->assertEquals('http://example.com/', $client->getRequest()->getUri()); ``` Commits ------- 8c4a594 [BrowserKit] fixed BC Break for HTTP_HOST header; implemented same behaviour for HTTPS server parameter
HTTP_HOST is just a header - it does not override URI,
uri does not override HTTP_HOST header.
If HTTP_HOST is not set then and only then hostname is extracted from uri.