[BUGFIX] Correctly store headers in Request object 37/44937/5
authorAndreas Wolf <dev@a-w.io>
Wed, 25 Nov 2015 10:20:16 +0000 (11:20 +0100)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Fri, 27 Nov 2015 13:49:11 +0000 (14:49 +0100)
Write the lowercased header names to the correct property.

Change-Id: I89a0dc18faa8e0c428bc3f48f239d624a2bd64c7
Resolves: #71820
Releases: master
Reviewed-on: https://review.typo3.org/44937
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Frank Nägler <frank.naegler@typo3.org>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
typo3/sysext/core/Classes/Http/Request.php
typo3/sysext/core/Tests/Unit/Http/RequestTest.php

index 9fb5974..8cb4151 100644 (file)
@@ -108,7 +108,7 @@ class Request extends Message implements RequestInterface
         $this->method = $method;
         $this->uri    = $uri;
         $this->body   = $body;
-        list($this->headerNames, $headers) = $this->filterHeaders($headers);
+        list($this->lowercasedHeaderNames, $headers) = $this->filterHeaders($headers);
         $this->assertHeaders($headers);
         $this->headers = $headers;
     }
@@ -341,7 +341,7 @@ class Request extends Message implements RequestInterface
             $host .= ':' . $uri->getPort();
         }
 
-        $clonedObject->headerNames['host'] = 'Host';
+        $clonedObject->lowercasedHeaderNames['host'] = 'Host';
         $clonedObject->headers['Host'] = array($host);
         return $clonedObject;
     }
index f942bd7..4534db1 100644 (file)
@@ -460,6 +460,31 @@ class RequestTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
     /**
      * @return array
      */
+    public function headersWithUpperAndLowerCaseValuesDataProvider()
+    {
+        // 'name' => [$headerName, $headerValue, $expectedValue]
+        return [
+            'Foo'             => ['Foo', 'bar', 'bar'],
+            'foo'             => ['foo', 'bar', 'bar'],
+            'Foo-with-array'  => ['Foo', ['bar'], 'bar'],
+            'foo-with-array'  => ['foo', ['bar'], 'bar'],
+        ];
+    }
+
+    /**
+     * @test
+     * @dataProvider headersWithUpperAndLowerCaseValuesDataProvider
+     */
+    public function headerCanBeRetrieved($header, $value, $expected)
+    {
+        $request = new Request(null, null, 'php://memory', [$header => $value]);
+        $this->assertEquals([$expected], $request->getHeader(strtolower($header)));
+        $this->assertEquals([$expected], $request->getHeader(strtoupper($header)));
+    }
+
+    /**
+     * @return array
+     */
     public function headersWithInjectionVectorsDataProvider()
     {
         return [