From c649964d9516d5c37ae9f602d94ec5a7743d1739 Mon Sep 17 00:00:00 2001 From: juneszh <juneszh@gmail.com> Date: Sat, 3 Apr 2021 00:21:26 +0800 Subject: [PATCH 1/2] add content_length configuration --- flight/Engine.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/flight/Engine.php b/flight/Engine.php index 0fd9c50..784d431 100644 --- a/flight/Engine.php +++ b/flight/Engine.php @@ -141,6 +141,7 @@ class Engine { $this->set('flight.log_errors', false); $this->set('flight.views.path', './views'); $this->set('flight.views.extension', '.php'); + $this->set('flight.content_length', true); // Startup configuration $this->before('start', function() use ($self) { @@ -152,6 +153,8 @@ class Engine { // Set case-sensitivity $self->router()->case_sensitive = $self->get('flight.case_sensitive'); + // Set Content-Length + $self->response()->content_length = $self->get('flight.content_length'); }); $initialized = true; From ed9bbed28774757fc956c13b88879d2245b7cf9b Mon Sep 17 00:00:00 2001 From: juneszh <juneszh@gmail.com> Date: Sat, 3 Apr 2021 00:26:53 +0800 Subject: [PATCH 2/2] add content_length configuration --- flight/net/Response.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/flight/net/Response.php b/flight/net/Response.php index c4f6ec7..9f4b925 100644 --- a/flight/net/Response.php +++ b/flight/net/Response.php @@ -33,6 +33,13 @@ class Response { * @var bool HTTP response sent */ protected $sent = false; + + /** + * header Content-Length + * + * @var boolean + */ + public $content_length = true; /** * @var array HTTP status codes @@ -251,11 +258,13 @@ class Response { } } - // Send content length - $length = $this->getContentLength(); + if ($this->content_length) { + // Send content length + $length = $this->getContentLength(); - if ($length > 0) { - header('Content-Length: '.$length); + if ($length > 0) { + header('Content-Length: '.$length); + } } return $this;