diff --git a/src/Event/Http/Psr7Bridge.php b/src/Event/Http/Psr7Bridge.php index 1745fdd86..fcae50356 100644 --- a/src/Event/Http/Psr7Bridge.php +++ b/src/Event/Http/Psr7Bridge.php @@ -48,7 +48,7 @@ public static function convertRequest(HttpRequestEvent $event, Context $context) 'REQUEST_URI' => $event->getUri(), 'PHP_AUTH_USER' => $user, 'PHP_AUTH_PW' => $password, - ]); + ], fn ($value) => $value !== null); foreach ($headers as $name => $values) { $server['HTTP_' . strtoupper(str_replace('-', '_', (string) $name))] = $values[0]; diff --git a/tests/Event/Http/Psr7BridgeTest.php b/tests/Event/Http/Psr7BridgeTest.php index a6d0f921c..359751120 100644 --- a/tests/Event/Http/Psr7BridgeTest.php +++ b/tests/Event/Http/Psr7BridgeTest.php @@ -32,6 +32,23 @@ public function test I can create a response from a PSR7 response() ], $response->toApiGatewayFormat()); } + public function test falsy server params are not dropped() + { + $event = new HttpRequestEvent([ + 'httpMethod' => 'GET', + 'headers' => [ + 'Content-Length' => '0', + 'Authorization' => 'Basic ' . base64_encode('user:'), + ], + ]); + $request = Psr7Bridge::convertRequest($event, Context::fake()); + + $serverParams = $request->getServerParams(); + self::assertSame('0', $serverParams['CONTENT_LENGTH']); + self::assertSame('user', $serverParams['PHP_AUTH_USER']); + self::assertSame('', $serverParams['PHP_AUTH_PW']); + } + protected function fromFixture(string $file): void { $event = new HttpRequestEvent(json_decode(file_get_contents($file), true, 512, JSON_THROW_ON_ERROR));