From 70607d1b902ef9e735ccfc87b3d9b7a7e70971c7 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 13 Dec 2024 09:01:51 +0800 Subject: [PATCH 1/5] [11.x] Fixes `Illuminate\Http\Response` to output empty string if `$content` is set to `null` 1. Symfony set the content to `null` for `response()->noContent()` https://github.com/symfony/http-foundation/blob/e88a66c3997859532bc2ddd6dd8f35aba2711744/Response.php#L246-L249 2. This cause issue with PSR-7 HTTP Stream in Octane fixed laravel/octane#972 Signed-off-by: Mior Muhammad Zaki --- src/Illuminate/Http/Response.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Illuminate/Http/Response.php b/src/Illuminate/Http/Response.php index ef158d276a7c..32178e8843d1 100755 --- a/src/Illuminate/Http/Response.php +++ b/src/Illuminate/Http/Response.php @@ -75,6 +75,15 @@ public function setContent(mixed $content): static return $this; } + /** + * Gets the current response content. + */ + #[\Override] + public function getContent(): string|false + { + return $this->content; + } + /** * Determine if the given content should be turned into JSON. * From e0953e41d437c49cc18d9995b6524b13a29a0ed6 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 13 Dec 2024 09:05:23 +0800 Subject: [PATCH 2/5] wip Signed-off-by: Mior Muhammad Zaki --- src/Illuminate/Http/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Response.php b/src/Illuminate/Http/Response.php index 32178e8843d1..861c9a764d9a 100755 --- a/src/Illuminate/Http/Response.php +++ b/src/Illuminate/Http/Response.php @@ -81,7 +81,7 @@ public function setContent(mixed $content): static #[\Override] public function getContent(): string|false { - return $this->content; + return transform(parent::getContent(), fn ($content) => $content ?? ''); } /** From a7d3f5fb85d1cb8ecb8d06cf38f65513ae06ea59 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 13 Dec 2024 09:11:39 +0800 Subject: [PATCH 3/5] wip Signed-off-by: Mior Muhammad Zaki --- src/Illuminate/Http/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Response.php b/src/Illuminate/Http/Response.php index 861c9a764d9a..fb59ce38df64 100755 --- a/src/Illuminate/Http/Response.php +++ b/src/Illuminate/Http/Response.php @@ -81,7 +81,7 @@ public function setContent(mixed $content): static #[\Override] public function getContent(): string|false { - return transform(parent::getContent(), fn ($content) => $content ?? ''); + return transform(parent::getContent(), fn ($content) => $content, ''); } /** From bc32585979de9ce76ce708cac4a46af2a719472d Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 20 Dec 2024 08:51:44 -0600 Subject: [PATCH 4/5] Update Response.php --- src/Illuminate/Http/Response.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Illuminate/Http/Response.php b/src/Illuminate/Http/Response.php index fb59ce38df64..12ca59e34977 100755 --- a/src/Illuminate/Http/Response.php +++ b/src/Illuminate/Http/Response.php @@ -37,6 +37,15 @@ public function __construct($content = '', $status = 200, array $headers = []) $this->setProtocolVersion('1.0'); } + /** + * Get the current response content. + */ + #[\Override] + public function getContent(): string|false + { + return transform(parent::getContent(), fn ($content) => $content, ''); + } + /** * Set the content on the response. * @@ -75,15 +84,6 @@ public function setContent(mixed $content): static return $this; } - /** - * Gets the current response content. - */ - #[\Override] - public function getContent(): string|false - { - return transform(parent::getContent(), fn ($content) => $content, ''); - } - /** * Determine if the given content should be turned into JSON. * From 7e26f4299db7085bdd11bf3f66172768fcb8f223 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Fri, 20 Dec 2024 08:52:01 -0600 Subject: [PATCH 5/5] Update Response.php --- src/Illuminate/Http/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Response.php b/src/Illuminate/Http/Response.php index 12ca59e34977..b1661063dd63 100755 --- a/src/Illuminate/Http/Response.php +++ b/src/Illuminate/Http/Response.php @@ -38,7 +38,7 @@ public function __construct($content = '', $status = 200, array $headers = []) } /** - * Get the current response content. + * Get the response content. */ #[\Override] public function getContent(): string|false