ZF2-119: serverParameters in Zend\Http\Request are ignored on toString

Issue Type: Bug Created: 2011-12-11T20:46:48.000+0000 Last Updated: 2012-01-02T07:53:30.000+0000 Status: Resolved Fix version(s): Reporter: Benjamin Steininger (robo47) Assignee: Ralph Schindler (ralph) Tags: - Zend\Http

  • Zend\Http\Response

Related issues: Attachments:


Investigating this issue in Mink, which is located in Goutte ( , which then uses Zend\Http, I ended here since the problems seems to be located in Zend\Http\Request.

A short description for everyone who doesn't know what Mink and Goutte is:

Mink is library for "Web acceptance testing" used by/with Behat. Goutte is a "simple PHP Web Scraper" using Zend\Http integrating it with the Symfony2 Components for Requests/Response which is one Driver for Mink (Others are Selenium, Sahi and Zombiejs).

Now the issue is, that creating a request from a former response currently does not transfer for example the referrer. I tried writing a patch for Goutte but I didn't find a working way to do that apart doing some ugly hacks for the referrer-header only.

So i looked further into Zend\Http and From what I see in Zend\Http\Request, the serverParameters are completely ignored in Zend\Http\Request::toString (I don't find any real usage of serverParameters in Zend\Http\Request at all, expect from setting it, only the subclass Zend\Http\PhpEnvironment\Request uses it) and there to is no transformation like it would be needed if you create a new http-request from a response involving e.g. the Referer (which would have to be transformed from HTTP_REFERER into REFERER) which transforms them from server-variables into headers.

Is the current usage in Goutte or my way of wanting to use setServer() wrong for passing the data from a former response to an new request ?

While investigating this problem I found Zend\Http\PhpEnvironment\Request::setServer which uses serverToHeaders() which does the transformation which I would need/expect in Zend\Http\Request::setServer, moving the Zend\Http\PhpEnvironment\Request::serverToHeaders into Zend\Http\Request and adding another method (maybe setHeadersFromServer() ? ) which uses serverToHeaders() could be a solution for fixing my current issue and adding referer support to

If someone gives me some direction I can make a PR with a fix for it or tell me if I simply overlooked something.


Posted by Shahar Evron (shahar) on 2012-01-02T06:27:02.000+0000

You sohuld use ->headers(), not ->server() in this case. The way to set headers (such as Referer:) is using the headers() container. server() is only used by the PhpEnvironment subclass for a good reason - it is basically a mirror of the $_SERVER superglobal which is obviously only available in the PhpEnvironment type of requests and not and requests generated by Zend\Http\Client - and yes, $_SERVER contains the original requests HTTP headers but these are only relevant in the HTTP Request PHP recieves from Apache, not in ones it generates for use with Http\Client.

BTW it's possible that very soon setServer() and server() (as well as evn()) will move from Zend\Http\Request to Zend\Http\Request\PhpEnvironment.

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.