Issues

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

Description

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


$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:


$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:


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

to convert {{$k}} to string:


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

Comments

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

@Dimitris Thanks for reporting.