Skip to content
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

REST.php $I->haveHttpHeader not working as expected #1650

Closed
russellsimpkins opened this issue Jan 16, 2015 · 15 comments
Closed

REST.php $I->haveHttpHeader not working as expected #1650

russellsimpkins opened this issue Jan 16, 2015 · 15 comments
Assignees
Labels

Comments

@russellsimpkins
Copy link

I noticed that I can not set the Host header using:

$I->haveHttpHeader("Host", "www.expected.com")

When I do that, I see in my Apache log files that I'm getting the DNS name I used to make the request instead of the value I used e.g. "www.expected.com"
_However_ If I do the following:

$I->haveHttpHeader(" Host", "www.expected.com")

I can see the value of "www.expected.com" in my Apache logs.

Is this a bug or a feature? Is this how I need to set header variables?

I'm using codeceptino 2.0.9 and php 5.5.10

@hughmandeville
Copy link

I have the same problem. PhpBrowser's setHeader and REST's haveHttpHeader work for all other headers, except "host". Seems like Symfony2 or Guzzle is replacing the host header. Maybe they are calling updateHeader instead of addHeader, which wouldn't overwrite an existing header.

@DavertMik
Copy link
Member

Yeah this one looks really funny )
I'll take it into work.

@DavertMik DavertMik added the Bug label Feb 2, 2015
@DavertMik DavertMik added this to the 2.0.10 milestone Feb 2, 2015
DavertMik added a commit that referenced this issue Feb 2, 2015
@DavertMik
Copy link
Member

I don't have any idea why... but this works )
Thanks for $I->haveHttpHeader(" Host", "www.expected.com") hook! 👍
I hope one day we will discover the real issue and fix it in a proper way. Or maybe not )

@Naktibalda
Copy link
Member

The test passed because both headers were sent to server:

array (
'Host' => 'localhost:8000',
'User-Agent' => 'Symfony2 BrowserKit',
'host' => 'http://www.example.com',
)

Probably case sensitivity was the original issue.

@Naktibalda Naktibalda reopened this Jul 22, 2015
@Naktibalda
Copy link
Member

@DavertMik

testHostHeaders() is failing on hhvm-serve and I can't convince myself that modifying hhvm-serve to make this test pass is the right thing to do.

It seems like the test is incorrect and it only passes because of case-sensitivity of getallheaders().
$_SERVER['HTTP_HOST'] still contains the host from the URL.

I feel inclined to delete the test, but is the fix code worth keeping?

@Naktibalda
Copy link
Member

The cheat used to make the test pass doesn't work,
to make it pass, we have to change this BrowserKit line https://github.com/symfony/BrowserKit/blob/292751e7b351b1e7d400c7529c07d713af2ff92a/Client.php#L313

@Naktibalda
Copy link
Member

Also the Host header is overridden by extractHeaders method used in Guzzle, Guzzle6, ZF1 and ZF2 connectors and by Laravel5 constructor.

@Naktibalda
Copy link
Member

I made a pull request to symfony to fix http_host handling: symfony/symfony#15427

@Naktibalda
Copy link
Member

My patch was accepted and released in Symfony 3.0.2, 2.8.3, 2.7.10 and 2.3.38 versions.

@Naktibalda
Copy link
Member

My change was considered a BC-break and reverted in symfony/browser-kit v2.8.48, v3.4.19, v4.1.8 and v4.2.0-RC1.

@Naktibalda
Copy link
Member

Well, not exactly reverted, but it behaves differently.
Instead of making request to specified URL with specified Host header, browser-kit makes request to host specified in Http-Host, so it broke my test which was testing this issue.

@mauricios
Copy link

mauricios commented Dec 6, 2018

@Naktibalda I'm running into similar issue with the haveHttpHeader, when setting the Host header the request is made to the domain in the header instaed of keeping the original url, see the following example:

$I->amOnUrl('https://www.google.com');
$I->amOnPage('/');
$I->haveHttpHeader('Host', 'www.wikipedia.org');
$I->amOnPage('/');

This is the output with debug:

Scenario --
 I am on url "https://www.google.com"
  [Host] https://www.google.com
  [Request Headers] []
  [Page] /
  [Response] 200
  [Request Cookies] []
  [Response Headers] {"Date":["Thu, 06 Dec 2018 15:00:43 GMT"],"Expires":["-1"],"Cache-Control":["private, max-age=0"],"Content-Type":["text/html; charset=ISO-8859-1"],"P3P":["CP="This is not a P3P policy! See g.co/p3phelp for more info.""],"Server":["gws"],"X-XSS-Protection":["1; mode=block"],"X-Frame-Options":["SAMEORIGIN"],"Set-Cookie":["1P_JAR=2018-12-06-15; expires=Sat, 05-Jan-2019 15:00:43 GMT; path=/; domain=.google.com","NID=150=CAx917Zw5A9wBdzsWdoRZBodc1-SmOKsrCdgsyOPo289hLOYeEqPa62kUETnjdlDQW5wMMaYPZ8I_Ip1dPE6O55qxegqWmkPkM0IcdVXrAblnmUXKp_yEx5PrxuSfExrBL1sxMyJjPNTeT2CqKzUWmHjWZ3xb3XCpn9PUJLsOjo; expires=Fri, 07-Jun-2019 15:00:43 GMT; path=/; domain=.google.com; HttpOnly"],"Alt-Svc":["quic=":443"; ma=2592000; v="44,43,39,35""],"Accept-Ranges":["none"],"Vary":["Accept-Encoding"],"Transfer-Encoding":["chunked"]}
 I am on page "/"
  [Request Headers] []
  [Page] /
  [Response] 200
  [Request Cookies] {"1P_JAR":"2018-12-06-15","NID":"150=CAx917Zw5A9wBdzsWdoRZBodc1-SmOKsrCdgsyOPo289hLOYeEqPa62kUETnjdlDQW5wMMaYPZ8I_Ip1dPE6O55qxegqWmkPkM0IcdVXrAblnmUXKp_yEx5PrxuSfExrBL1sxMyJjPNTeT2CqKzUWmHjWZ3xb3XCpn9PUJLsOjo"}
  [Response Headers] {"Date":["Thu, 06 Dec 2018 15:00:43 GMT"],"Expires":["-1"],"Cache-Control":["private, max-age=0"],"Content-Type":["text/html; charset=ISO-8859-1"],"P3P":["CP="This is not a P3P policy! See g.co/p3phelp for more info.""],"Server":["gws"],"X-XSS-Protection":["1; mode=block"],"X-Frame-Options":["SAMEORIGIN"],"Set-Cookie":["1P_JAR=2018-12-06-15; expires=Sat, 05-Jan-2019 15:00:43 GMT; path=/; domain=.google.com","NID=150=X4osKkYdFxd0OvQN9UD1f0qPm3ukrGV9JPmdU4fJyU87XK9WcofxOMoSvM-n9DdTW3iLakgYnak1PsYwPR1Ya_anceZPiegtEHJXeoCtZ-U61_U7pVHA3y3KU1gXWPZ2NVIabsr-nwIHGtJ4QE2b_1AdPruWsisEvKKDX9au9Gk; expires=Fri, 07-Jun-2019 15:00:43 GMT; path=/; domain=.google.com; HttpOnly"],"Alt-Svc":["quic=":443"; ma=2592000; v="44,43,39,35""],"Accept-Ranges":["none"],"Vary":["Accept-Encoding"],"Transfer-Encoding":["chunked"]}
 I have http header "Host","www.wikipedia.org"
 I am on page "/"
  [Request Headers] {"Host":"www.wikipedia.org"}
  [Page] /
  [Response] 200
  [Request Cookies] []
  [Response Headers] {"Date":["Thu, 06 Dec 2018 15:00:43 GMT"],"Content-Type":["text/html;charset=utf-8"],"Content-Length":["82849"],"Connection":["keep-alive"],"Server":["mw1327.eqiad.wmnet"],"Last-Modified":["Wed, 05 Dec 2018 12:26:25 GMT"],"Backend-Timing":["D=269 t=1544095379496271"],"Cache-Control":["s-maxage=86400, must-revalidate, max-age=3600"],"ETag":["W/"143a1-57c457d9ef5ea""],"Vary":["Accept-Encoding"],"X-Varnish":["162319343 113610437, 321860860 254320896"],"Via":["1.1 varnish (Varnish/5.1), 1.1 varnish (Varnish/5.1)"],"Age":["13063"],"X-Cache":["cp1079 hit/6, cp1075 hit/44500"],"X-Cache-Status":["hit-front"],"Server-Timing":["cache;desc="hit-front""],"Strict-Transport-Security":["max-age=106384710; includeSubDomains; preload"],"Set-Cookie":["WMF-Last-Access=06-Dec-2018;Path=/;HttpOnly;secure;Expires=Mon, 07 Jan 2019 12:00:00 GMT","WMF-Last-Access-Global=06-Dec-2018;Path=/;Domain=.wikipedia.org;HttpOnly;secure;Expires=Mon, 07 Jan 2019 12:00:00 GMT","GeoIP=CO:DC:Bogot__:4.65:-74.06:v4; Path=/; secure; Domain=.wikipedia.org"],"X-Analytics":["https=1;nocookies=1"],"X-Client-IP":["190.146.127.7"],"Accept-Ranges":["bytes"]}
 PASSED

As you can see in the response the first call to / is requesting the URL www.google.com, then the header Host is set to www.wikipedia.org, but instead of keeping the original URL and send the Host header, the request is made to www.wikipedia.org. It seems the haveHttpHeader changing the requested URL instead of changing the Host header only.

@Naktibalda
Copy link
Member

Yes, that's what it is doing.

@mauricios
Copy link

@Naktibalda Did you find any workaround to test Host header without changing the actual hostname in the request?

@Naktibalda
Copy link
Member

I wasn't looking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants