From 28080c975c2c7b042d9bf1202fa100b9099de0f1 Mon Sep 17 00:00:00 2001 From: Igor Rusinov Date: Sun, 20 Mar 2016 20:53:52 +0300 Subject: [PATCH] Fixedissue with priority of headers --- .gitignore | 1 + src/Unirest/Request.php | 2 +- tests/Unirest/RequestTest.php | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dd198a3..3a25e7b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .DS_Store +.idea build composer.lock composer.phar diff --git a/src/Unirest/Request.php b/src/Unirest/Request.php index a061b2e..e64e241 100755 --- a/src/Unirest/Request.php +++ b/src/Unirest/Request.php @@ -504,7 +504,7 @@ public static function getFormattedHeaders($headers) { $formattedHeaders = array(); - $combinedHeaders = array_change_key_case(array_merge((array) $headers, self::$defaultHeaders)); + $combinedHeaders = array_change_key_case(array_merge(self::$defaultHeaders, (array) $headers)); foreach ($combinedHeaders as $key => $val) { $formattedHeaders[] = self::getHeaderString($key, $val); diff --git a/tests/Unirest/RequestTest.php b/tests/Unirest/RequestTest.php index eee9182..d9b5633 100644 --- a/tests/Unirest/RequestTest.php +++ b/tests/Unirest/RequestTest.php @@ -48,6 +48,12 @@ public function testDefaultHeaders() $this->assertObjectHasAttribute('header2', $response->body->headers); $this->assertEquals('world', $response->body->headers->header2); + $response = Request::get('http://mockbin.com/request', ['header1' => 'Custom value']); + + $this->assertEquals(200, $response->code); + $this->assertObjectHasAttribute('header1', $response->body->headers); + $this->assertEquals('Custom value', $response->body->headers->header1); + Request::clearDefaultHeaders(); $response = Request::get('http://mockbin.com/request');