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

Commit

Permalink
Merge branch 'hotfix/5065' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Sep 4, 2013
2 parents fdedc25 + 5a46d9b commit f05b8f8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -1154,9 +1154,10 @@ protected function prepareHeaders($body, $uri)
}

// Merge the headers of the request (if any)
$requestHeaders = $this->getRequest()->getHeaders()->toArray();
foreach ($requestHeaders as $key => $value) {
$headers[$key] = $value;
// here we need right 'http field' and not lowercase letters
$requestHeaders = $this->getRequest()->getHeaders();
foreach ($requestHeaders as $requestHeaderElement) {
$headers[$requestHeaderElement->getFieldName()] = $requestHeaderElement->getFieldValue();
}
return $headers;
}
Expand Down
27 changes: 27 additions & 0 deletions test/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ZendTest\Http;

use ReflectionClass;
use Zend\Uri\Http;
use Zend\Http\Client;
use Zend\Http\Cookies;
use Zend\Http\Exception;
Expand Down Expand Up @@ -393,4 +394,30 @@ public function testUsageOfCustomResponseCustomCode()
$this->assertEquals(497, $response->getStatusCode());
$this->assertEquals('Whatever content', $response->getContent());
}

public function testPrepareHeadersCreateRightHttpField()
{
$body = json_encode(array('foofoo'=>'barbar'));

$client = new Client();
$prepareHeadersReflection = new \ReflectionMethod($client, 'prepareHeaders');
$prepareHeadersReflection->setAccessible(true);

$request= new Request();
$request->getHeaders()->addHeaderLine('content-type','application/json');
$request->getHeaders()->addHeaderLine('content-length',strlen($body));
$client->setRequest($request);

$client->setEncType('application/json');

$this->assertSame($client->getRequest(),$request);

$headers = $prepareHeadersReflection->invoke($client,$body,new Http('http://localhost:5984'));

$this->assertArrayNotHasKey('content-type', $headers);
$this->assertArrayHasKey('Content-Type', $headers);

$this->assertArrayNotHasKey('content-length', $headers);
$this->assertArrayHasKey('Content-Length', $headers);
}
}

0 comments on commit f05b8f8

Please sign in to comment.