From e8d09bef209a2ec256cc6c3d2c880e4bf0e7f215 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Wed, 8 Jul 2026 22:48:57 +0200 Subject: [PATCH] =?UTF-8?q?Preserve=20falsy=20request=20headers=20like?= =?UTF-8?q?=C2=A0`0`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Event/Http/Psr7Bridge.php | 2 +- tests/Event/Http/Psr7BridgeTest.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) 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));