diff --git a/src/Vinelab/Http/Response.php b/src/Vinelab/Http/Response.php index 2dcfb1a..d0b0159 100644 --- a/src/Vinelab/Http/Response.php +++ b/src/Vinelab/Http/Response.php @@ -46,6 +46,7 @@ public function __construct($cURL) $this->info = curl_getinfo($cURL); $this->headers = $this->parseHeaders($response, $this->info['header_size']); $this->content = $this->parseBody($response, $this->info['header_size']); + $this->caseInsensitiveHeaders = array_change_key_case($this->headers); } else { throw new HttpClientRequestFailedException(curl_error($cURL)); } @@ -148,7 +149,11 @@ public function headers() */ public function header($name) { - return (array_key_exists($name, $this->headers)) ? $this->headers[$name] : null; + if (array_key_exists(strtolower($name), $this->caseInsensitiveHeaders)) { + return $this->caseInsensitiveHeaders[strtolower($name)]; + } + + return null; } /** diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 608b8aa..03ce35b 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -37,6 +37,10 @@ public function testHeaders() $this->assertArrayHasKey('Content-Type', $headers); $this->assertEquals('application/json', $headers['Content-Type']); + + // RFC7230 case-insensitive header fields + $testResponse = $this->client->get($request); + $this->assertEquals($testResponse->header('content-type'), $testResponse->header('Content-Type')); } public function testGetRequestWithoutParams()