mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-10 10:26:35 +00:00
Merge pull request #112 from zachborboa/master
Use CaseInsensitiveArray for request headers
This commit is contained in:
+9
-2
@@ -49,6 +49,7 @@ class Curl
|
||||
$this->setDefaultUserAgent();
|
||||
$this->setOpt(CURLINFO_HEADER_OUT, true);
|
||||
$this->setOpt(CURLOPT_RETURNTRANSFER, true);
|
||||
$this->headers = new CaseInsensitiveArray();
|
||||
}
|
||||
|
||||
public function get($url_mixed, $data = array())
|
||||
@@ -211,8 +212,14 @@ class Curl
|
||||
|
||||
public function setHeader($key, $value)
|
||||
{
|
||||
$this->headers[$key] = $key . ': ' . $value;
|
||||
$this->setOpt(CURLOPT_HTTPHEADER, array_values($this->headers));
|
||||
$this->headers[$key] = $value;
|
||||
$headers = array();
|
||||
foreach ($this->headers as $key => $value) {
|
||||
$headers[$key] = $value;
|
||||
}
|
||||
$this->setOpt(CURLOPT_HTTPHEADER, array_map(function($value, $key) {
|
||||
return $key . ': ' . $value;
|
||||
}, $headers, array_keys($headers)));
|
||||
}
|
||||
|
||||
public function unsetHeader($key)
|
||||
|
||||
@@ -507,7 +507,24 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('HTTP/1.1 401 Unauthorized', $test->curl->error_message);
|
||||
}
|
||||
|
||||
public function testHeaders()
|
||||
public function testRequestHeaderCaseSensitivity()
|
||||
{
|
||||
$content_type = 'application/json';
|
||||
$curl = new Curl();
|
||||
$curl->setHeader('Content-Type', $content_type);
|
||||
|
||||
$reflector = new ReflectionClass('\Curl\Curl');
|
||||
$property = $reflector->getProperty('headers');
|
||||
$property->setAccessible(true);
|
||||
$headers = $property->getValue($curl);
|
||||
|
||||
$this->assertEquals($content_type, $headers['Content-Type']);
|
||||
$this->assertEquals($content_type, $headers['content-type']);
|
||||
$this->assertEquals($content_type, $headers['CONTENT-TYPE']);
|
||||
$this->assertEquals($content_type, $headers['cOnTeNt-TyPe']);
|
||||
}
|
||||
|
||||
public function testResponseHeaders()
|
||||
{
|
||||
$test = new Test();
|
||||
$test->curl->setHeader('Content-Type', 'application/json');
|
||||
@@ -518,7 +535,7 @@ class CurlTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('application/json', $test->server('server', 'GET', array('key' => 'HTTP_ACCEPT')));
|
||||
}
|
||||
|
||||
public function testHeaderCaseSensitivity()
|
||||
public function testResponseHeaderCaseSensitivity()
|
||||
{
|
||||
$content_type = 'application/json';
|
||||
$test = new Test();
|
||||
|
||||
Reference in New Issue
Block a user