Issues

ZF-12522: Adapter Proxy fails to add Proxy-Authorization header

Issue Type: Bug Created: 2013-02-14T11:16:26.000+0000 Last Updated: 2013-02-14T12:31:54.000+0000 Status: Resolved Fix version(s): - 1.12.2 (25/Feb/13)

Reporter: Dimitris Giotas (dgiotas) Assignee: Frank Brückner (frosch) Tags: - Zend_Http_Client

Related issues: Attachments:

Description

When trying to add proxy authorization header the following code fails:

<pre class="highlight">
$hasProxyAuthHeader = false;
foreach ($headers as $k => $v) {
    if ($k == 'proxy-authorization' || preg_match("/^proxy-authorization:/i", $v) ) {
        $hasProxyAuthHeader = true;
        break;
    }
}
if (!$hasProxyAuthHeader) {
    $headers[] = 'proxy-authorization: ' . Zend_Http_Client::encodeAuthHeader(
        $this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']
    );
}

The $headers array is of this type:

<pre class="highlight">
$headers = array(
                 'Host: demo.domain.com',
                 'Content-length: 0'
                 );

According to PHP (http://php.net/manual/en/…) if we compare an integer with a string, the string will always be returned as 0, so the first loop inside the foreach always returns true. Quick solution is to change the if statement:

<pre class="highlight">
if ($k == 'proxy-authorization' || preg_match("/^proxy-authorization:/i", $v) ) {

to convert $k to string:

<pre class="highlight">
if ((string) $k == 'proxy-authorization' || preg_match("/^proxy-authorization:/i", $v) ) {

Comments

Posted by Frank Brückner (frosch) on 2013-02-14T12:31:15.000+0000

Fixed on trunk (25260) and release-1.12 (25261)

Posted by Frank Brückner (frosch) on 2013-02-14T12:31:54.000+0000

@Dimitris Thanks for reporting.

Have you found an issue?

See the Overview section for more details.

Copyright

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

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

Contacts