From 5ae170d0b52ff17d76e1fd595ce1d14355872822 Mon Sep 17 00:00:00 2001 From: Rafael Kraut <14234815+RafaelKr@users.noreply.github.com> Date: Tue, 24 Sep 2024 08:23:59 +0200 Subject: [PATCH 1/2] Correctly split headers without leading whitespace According to https://datatracker.ietf.org/doc/html/rfc7230#section-3.2 headers may contain optional leading whitespace before the value. The previous implementation threw an error if there was no whitespace. Fixes #401. --- src/Roots/Acorn/Application/Concerns/Bootable.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Roots/Acorn/Application/Concerns/Bootable.php b/src/Roots/Acorn/Application/Concerns/Bootable.php index d3e90512..f60b0270 100644 --- a/src/Roots/Acorn/Application/Concerns/Bootable.php +++ b/src/Roots/Acorn/Application/Concerns/Bootable.php @@ -143,7 +143,10 @@ protected function registerDefaultRoute(): void { Route::any('{any?}', fn () => tap(response(''), function (Response $response) { foreach (headers_list() as $header) { - [$header, $value] = explode(': ', $header, 2); + [$header, $value] = explode(':', $header, 2); + // HTTP/1.1 Header specification: https://datatracker.ietf.org/doc/html/rfc7230#section-3.2 + // remove the optional leading whitespace + $value = ltrim($value); if (! headers_sent()) { header_remove($header); From a0b78d6b6df37ac22ee495517e72d3f99bc22552 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Tue, 24 Sep 2024 09:53:15 -0700 Subject: [PATCH 2/2] Update src/Roots/Acorn/Application/Concerns/Bootable.php --- src/Roots/Acorn/Application/Concerns/Bootable.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Roots/Acorn/Application/Concerns/Bootable.php b/src/Roots/Acorn/Application/Concerns/Bootable.php index f60b0270..c0052b17 100644 --- a/src/Roots/Acorn/Application/Concerns/Bootable.php +++ b/src/Roots/Acorn/Application/Concerns/Bootable.php @@ -144,9 +144,6 @@ protected function registerDefaultRoute(): void Route::any('{any?}', fn () => tap(response(''), function (Response $response) { foreach (headers_list() as $header) { [$header, $value] = explode(':', $header, 2); - // HTTP/1.1 Header specification: https://datatracker.ietf.org/doc/html/rfc7230#section-3.2 - // remove the optional leading whitespace - $value = ltrim($value); if (! headers_sent()) { header_remove($header);