Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'dlabs/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Client/Adapter/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
$curlMethod = CURLOPT_CUSTOMREQUEST;
$curlValue = "TRACE";
break;

case 'HEAD' :
$curlMethod = CURLOPT_CUSTOMREQUEST;
$curlValue = "HEAD";
Expand Down Expand Up @@ -364,6 +364,13 @@ public function write($method, $uri, $httpVersion = 1.1, $headers = array(), $bo
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true);
}

// Treating basic auth headers in a special way
if (array_key_exists('Authorization', $headers) && 'Basic' == substr($headers['Authorization'], 0, 5)) {
curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($this->curl, CURLOPT_USERPWD, base64_decode(substr($headers['Authorization'], 6)));
unset($headers['Authorization']);
}

// set additional headers
$headers['Accept'] = '';
$curlHeaders = array();
Expand Down
24 changes: 23 additions & 1 deletion test/Client/CurlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public function testGetCurlHandle()

$this->assertTrue(is_resource($adapter->getHandle()));
}

/**
* @group ZF-9857
*/
Expand All @@ -313,4 +313,26 @@ public function testHeadRequest()
$this->client->send();
$this->assertEquals('', $this->client->getResponse()->getBody());
}

public function testAuthorizeHeader()
{
// We just need someone to talk to
$this->client->setUri($this->baseuri. 'testHttpAuth.php');
$adapter = new Adapter\Curl();
$this->client->setAdapter($adapter);

$uid = 'alice';
$pwd = 'secret';

$hash = base64_encode($uid . ':' . $pwd);
$header = 'Authorization: Basic ' . $hash;

$this->client->setAuth($uid, $pwd);
$res = $this->client->send();

$curlInfo = curl_getinfo($adapter->getHandle());
$this->assertArrayHasKey('request_header', $curlInfo, 'Expecting request_header in curl_getinfo() return value');

$this->assertContains($header, $curlInfo['request_header'], 'Expecting valid basic authorization header');
}
}

0 comments on commit c750616

Please sign in to comment.