From 73977fb6f593ebd80f8b4687aa4f53deb3576cbd Mon Sep 17 00:00:00 2001 From: Ingmar Aasoja Date: Tue, 24 Sep 2019 20:10:57 +0300 Subject: [PATCH 1/2] Make header fields case-insensitive in as stated in RFC7130 --- src/Vinelab/Http/Response.php | 6 +++++- tests/ClientTest.php | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Vinelab/Http/Response.php b/src/Vinelab/Http/Response.php index 2dcfb1a..c9d181f 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,10 @@ 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() From aafdaeba8cfe8c6ba0ea9635ab30810638092d14 Mon Sep 17 00:00:00 2001 From: Ingmar Aasoja Date: Tue, 24 Sep 2019 20:11:38 +0300 Subject: [PATCH 2/2] Make header fields case-insensitive in as stated in RFC7130 --- src/Vinelab/Http/Response.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Vinelab/Http/Response.php b/src/Vinelab/Http/Response.php index c9d181f..d0b0159 100644 --- a/src/Vinelab/Http/Response.php +++ b/src/Vinelab/Http/Response.php @@ -152,6 +152,7 @@ public function header($name) if (array_key_exists(strtolower($name), $this->caseInsensitiveHeaders)) { return $this->caseInsensitiveHeaders[strtolower($name)]; } + return null; }