From ba85d2daf9b7f08b27fff00c869ab3f2c14c2a39 Mon Sep 17 00:00:00 2001 From: Joanhey Date: Tue, 6 Aug 2024 22:40:35 +0200 Subject: [PATCH 1/2] Response construct propery promotion --- src/Protocols/Http/Response.php | 37 ++++++--------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/src/Protocols/Http/Response.php b/src/Protocols/Http/Response.php index 0dceca14f..0df251983 100644 --- a/src/Protocols/Http/Response.php +++ b/src/Protocols/Http/Response.php @@ -39,19 +39,6 @@ */ class Response implements Stringable { - /** - * Header data. - * - * @var array - */ - protected array $headers = []; - - /** - * Http status. - * - * @var int - */ - protected int $status; /** * Http reason. @@ -67,13 +54,6 @@ class Response implements Stringable */ protected string $version = '1.1'; - /** - * Http body. - * - * @var string - */ - protected string $body = ''; - /** * Send file info * @@ -177,20 +157,15 @@ public static function init(): void /** * Response constructor. * - * @param int $status - * @param array|null $headers + * @param int $status + * @param array $headers * @param string $body */ public function __construct( - int $status = 200, - ?array $headers = [], - string $body = '' - ) - { - $this->status = $status; - $this->headers = $headers; - $this->body = $body; - } + protected int $status = 200, + protected array $headers = [], + protected string $body = '' + ) {} /** * Set header. From 870220d15bd83ada95902af64dbd332579ee2aad Mon Sep 17 00:00:00 2001 From: Joanhey Date: Tue, 6 Aug 2024 22:59:22 +0200 Subject: [PATCH 2/2] Fix Http class to use Response headers as array --- src/Protocols/Http.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocols/Http.php b/src/Protocols/Http.php index ef7355964..c528ee08b 100644 --- a/src/Protocols/Http.php +++ b/src/Protocols/Http.php @@ -248,7 +248,7 @@ public static function encode(mixed $response, TcpConnection $connection): strin } $handler = fopen($file, 'r'); if (false === $handler) { - $connection->close(new Response(403, null, '403 Forbidden')); + $connection->close(new Response(403, [], '403 Forbidden')); return ''; } $connection->send((string)$response, true);