mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-31 12:43:14 +00:00
Use CaseInsensitiveArray when setting headers
This commit is contained in:
+6
-1
@@ -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())
|
||||
@@ -212,9 +213,13 @@ class Curl
|
||||
public function setHeader($key, $value)
|
||||
{
|
||||
$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;
|
||||
}, $this->headers, array_keys($this->headers)));
|
||||
}, $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