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

user-agent header gets overwritten #4576

Closed
Somebi opened this Issue Oct 19, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@Somebi

Somebi commented Oct 19, 2017

Only by changing to User-Agentt header appears inside printed by php headers list.

modules:
    config:
        PhpBrowser:
          headers:
            User-Agentt: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1

PHP received headers inside acceptance test:

[HTTP_USER_AGENTT] => Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1

[HTTP_USER_AGENT] => Symfony2 BrowserKit

This is not working:

modules:
    config:
        PhpBrowser:
          headers:
            User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1
@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Oct 20, 2017

Member

It works if you set User_Agent instead of User-Agent.

Member

Naktibalda commented Oct 20, 2017

It works if you set User_Agent instead of User-Agent.

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Oct 20, 2017

Member

The actual result I got was User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1,Symfony BrowserKit

Member

Naktibalda commented Oct 20, 2017

The actual result I got was User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13B143 Safari/601.1,Symfony BrowserKit

@Naktibalda

This comment has been minimized.

Show comment
Hide comment
@Naktibalda

Naktibalda Oct 22, 2017

Member

Fixed.

The root cause was the long chain of libraries: PhpBrowser -> BrowserKit -> Guzzle -> curl.
Headers option was passed to constructor of Guzzle, so BrowserKit was not aware of these headers.
Constructor options are default values for requests in Guzzle, when BrowserKit received request from PhpBrowser, it checked if User-Agent is set, and set it's own if it wasn't.
User-Agent set in request by BrowserKit was considered to be the real one by Guzzle and it was used instead of the "default" one set in constructor parameters.

I fixed the issue by making PhpBrowser to keep headers to itself, this way the headers traverse the whole chain and nothing overrides them.
$headers property was introduced to InnerBrowser a while back by refactoring of haveHttpHeader method.

Member

Naktibalda commented Oct 22, 2017

Fixed.

The root cause was the long chain of libraries: PhpBrowser -> BrowserKit -> Guzzle -> curl.
Headers option was passed to constructor of Guzzle, so BrowserKit was not aware of these headers.
Constructor options are default values for requests in Guzzle, when BrowserKit received request from PhpBrowser, it checked if User-Agent is set, and set it's own if it wasn't.
User-Agent set in request by BrowserKit was considered to be the real one by Guzzle and it was used instead of the "default" one set in constructor parameters.

I fixed the issue by making PhpBrowser to keep headers to itself, this way the headers traverse the whole chain and nothing overrides them.
$headers property was introduced to InnerBrowser a while back by refactoring of haveHttpHeader method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment