ZF-179: when redirect to another host, header don't set a new host name.


With Zend_Http_Client incubator version, When a redirect response to another host is returned, the _prepare_headers method doesn't set the new host name, so the redirect action doesn't work rightly.

    // Set the host header
    if (! isset($this->headers['host'])) {
        $host = $this->uri->getHost() . ($this->uri->getPort() == 80 ? '' : ':' . $this->uri->getPort());
        $this->setHeader('host', $host);

will be fixed to

    // Set the host header
    $host = $this->uri->getHost() . ($this->uri->getPort() == 80 ? '' : ':' . $this->uri->getPort());
    $this->setHeader('host', $host);

Please check it.


Please test again with revision 771 - I think the bug is fixed but I have no way to test it right now.

I didn't use the patch you proposed because I want to give people the option to override the "Host" header if they want to by setting it before the request. Instead, I changed the Zend_Http_Client::request() code to unset the "Host" header when redirecting to a valid URI.

Let me know if the problem is solved or not.

Has this been confirmed fixed? If not, set the fix version to 0.2.0 and try to confirm by then.

Sorry, too late. I tested to access "http://pcweb.mycom.co.jp/" with trunk version(revision 866). And success redirecting to another host url: "http://jounal.mycom.co.jp/". Thanks.

// test code require_once 'Zend.php'; require_once 'Zend/Http/Client.php';

$url = 'http://pcweb.mycom.co.jp/'; $client = new Zend_Http_Client($url); $response = $client->get(); echo $client->getUri(); // http://journal.mycom.co.jp:80/

Then I guess this confirms that the issue is fixed.

Thank you.

0.1.5 released