[BUGFIX] PSR-7 responses return header using getHeader() 52/56952/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Sun, 11 Mar 2018 06:02:30 +0000 (07:02 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 13 May 2018 09:51:10 +0000 (11:51 +0200)
The base PSR-7 implementation of the Response object does not
sanitize the headers properly when handing them in as an array,
thus, it is stored wrong in the Response object.

Resolves: #84853
Releases: master, 8.7
Change-Id: I7571f1438bc602bcae9367b82f99946ed22d8308
Reviewed-on: https://review.typo3.org/56952
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Classes/Http/Response.php
typo3/sysext/core/Tests/Unit/Http/ResponseTest.php

index 0c8e700..6d5d01b 100644 (file)
@@ -140,7 +140,7 @@ class Response extends Message implements ResponseInterface
         $this->statusCode = (int)$statusCode;
 
         $this->reasonPhrase = $this->availableStatusCodes[$this->statusCode];
-        $headers = $this->filterHeaders($headers)[1];
+        list($this->lowercasedHeaderNames, $headers) = $this->filterHeaders($headers);
         $this->assertHeaders($headers);
         $this->headers = $headers;
     }
index 7f6199a..d18cfb0 100644 (file)
@@ -224,9 +224,21 @@ class ResponseTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
      * @test
      * @dataProvider headersWithInjectionVectorsDataProvider
      */
-    public function cnstructorRaisesExceptionForHeadersWithCRLFVectors($name, $value)
+    public function constructorRaisesExceptionForHeadersWithCRLFVectors($name, $value)
     {
         $this->expectException(\InvalidArgumentException::class);
         new Response('php://memory', 200, [$name => $value]);
     }
+
+    /**
+     * @test
+     */
+    public function getHeaderReturnsHeaderSetByConstructorArgument()
+    {
+        $subject = new Response('php://memory', 200, ['location' => 'foo']);
+        $expected = [
+            0 => 'foo',
+        ];
+        $this->assertSame($expected, $subject->getHeader('location'));
+    }
 }