fix: give Events with an empty Host the localhost default tooUnverified
An empty Host header left the Request URI at "http://:/", and PSR-15 Applications, which no longer default the host themselves, failed with a 500 on such Events.
ee88812 parent: 5b47e80 modified
src/HttpConverter.php +4 -2 | @@ -69,9 +69,11 @@ final class HttpConverter | ||
| 69 | 69 | $contentType = strtolower($value); |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | - // Events need not carry a Host (CRON ones may not), and without it the Request's URI would be "http://:/"; | |
| 72 | + // Events need not carry a Host (CRON ones may not), and without one the Request's URI would be "http://:/"; | |
| 73 | 73 | // Request::create() falls back to the same default. |
| 74 | - $server['HTTP_HOST'] ??= 'localhost'; | |
| 74 | + if ('' === ($server['HTTP_HOST'] ?? '')) { | |
| 75 | + $server['HTTP_HOST'] = 'localhost'; | |
| 76 | + } | |
| 75 | 77 | |
| 76 | 78 | // PHP only parses form bodies into $_POST for POST; Symfony's createFromGlobals() covers the other body methods. |
| 77 | 79 | $post = $files = []; |
| @@ -69,9 +69,11 @@ final class HttpConverter | |||
| 69 | $contentType = strtolower($value); | 69 | $contentType = strtolower($value); |
| 70 | } | 70 | } |
| 71 | } | 71 | } |
| 72 | - // Events need not carry a Host (CRON ones may not), and without it the Request's URI would be "http://:/"; | 72 | + // Events need not carry a Host (CRON ones may not), and without one the Request's URI would be "http://:/"; |
| 73 | // Request::create() falls back to the same default. | 73 | // Request::create() falls back to the same default. |
| 74 | - $server['HTTP_HOST'] ??= 'localhost'; | 74 | + if ('' === ($server['HTTP_HOST'] ?? '')) { |
| 75 | + $server['HTTP_HOST'] = 'localhost'; | ||
| 76 | + } | ||
| 75 | 77 | ||
| 76 | // PHP only parses form bodies into $_POST for POST; Symfony's createFromGlobals() covers the other body methods. | 78 | // PHP only parses form bodies into $_POST for POST; Symfony's createFromGlobals() covers the other body methods. |
| 77 | $post = $files = []; | 79 | $post = $files = []; |
modified
tests/HttpConverterTest.php +1 -0 | @@ -273,6 +273,7 @@ final class HttpConverterTest extends TestCase | ||
| 273 | 273 | |
| 274 | 274 | self::assertSame('http://localhost/jobs', $request->getUri()); |
| 275 | 275 | self::assertSame(80, $request->getPort()); |
| 276 | + self::assertSame('http://localhost/jobs', HttpConverter::toRequest(['path' => '/jobs', 'headers' => ['Host' => '']])->getUri()); | |
| 276 | 277 | } |
| 277 | 278 | |
| 278 | 279 | public function testFunctionResponseFromTextResponse(): void |
| @@ -273,6 +273,7 @@ final class HttpConverterTest extends TestCase | |||
| 273 | 273 | ||
| 274 | self::assertSame('http://localhost/jobs', $request->getUri()); | 274 | self::assertSame('http://localhost/jobs', $request->getUri()); |
| 275 | self::assertSame(80, $request->getPort()); | 275 | self::assertSame(80, $request->getPort()); |
| 276 | + self::assertSame('http://localhost/jobs', HttpConverter::toRequest(['path' => '/jobs', 'headers' => ['Host' => '']])->getUri()); | ||
| 276 | } | 277 | } |
| 277 | 278 | ||
| 278 | public function testFunctionResponseFromTextResponse(): void | 279 | public function testFunctionResponseFromTextResponse(): void |