From 3ae1689e9b8177d50ec35de1ba35fa93dd28e4f4 Mon Sep 17 00:00:00 2001 From: Adrian Suter Date: Wed, 29 Jan 2020 15:38:23 +0100 Subject: [PATCH] Fix Authorization Headers --- src/Response.php | 2 +- tests/ResponseTest.php | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/Response.php b/src/Response.php index 514d251..131add1 100644 --- a/src/Response.php +++ b/src/Response.php @@ -124,7 +124,7 @@ public function __construct( ?StreamInterface $body = null ) { $this->status = $this->filterStatus($status); - $this->headers = $headers ? $headers : new Headers(); + $this->headers = $headers ? $headers : new Headers([], []); $this->body = $body ? $body : (new StreamFactory())->createStream(); } diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index 5c5d2bf..382bf54 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -13,6 +13,7 @@ use InvalidArgumentException; use PHPUnit\Framework\TestCase; use ReflectionProperty; +use Slim\Psr7\Environment; use Slim\Psr7\Headers; use Slim\Psr7\Response; use Slim\Psr7\Stream; @@ -146,7 +147,7 @@ public function testEmptyReasonPhraseForUnrecognisedCode() { $response = new Response(); $response = $response->withStatus(199); - + $this->assertSame('', $response->getReasonPhrase()); } @@ -165,4 +166,16 @@ public function testGetCustomReasonPhrase() $this->assertEquals('Custom Phrase', $clone->getReasonPhrase()); } + + public function testResponseHeadersDoNotContainAuthorizationHeader() + { + $_SERVER = Environment::mock( + [ + 'PHP_AUTH_USER' => 'foo' + ] + ); + + $response = new Response(); + $this->assertEmpty($response->getHeaders()); + } }