Merge pull request #433 from juneszh/master

add content_length configuration
pull/434/head
Mike Cao 4 years ago committed by GitHub
commit b6429d2a3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -141,6 +141,7 @@ class Engine {
$this->set('flight.log_errors', false); $this->set('flight.log_errors', false);
$this->set('flight.views.path', './views'); $this->set('flight.views.path', './views');
$this->set('flight.views.extension', '.php'); $this->set('flight.views.extension', '.php');
$this->set('flight.content_length', true);
// Startup configuration // Startup configuration
$this->before('start', function() use ($self) { $this->before('start', function() use ($self) {
@ -152,6 +153,8 @@ class Engine {
// Set case-sensitivity // Set case-sensitivity
$self->router()->case_sensitive = $self->get('flight.case_sensitive'); $self->router()->case_sensitive = $self->get('flight.case_sensitive');
// Set Content-Length
$self->response()->content_length = $self->get('flight.content_length');
}); });
$initialized = true; $initialized = true;

@ -33,6 +33,13 @@ class Response {
* @var bool HTTP response sent * @var bool HTTP response sent
*/ */
protected $sent = false; protected $sent = false;
/**
* header Content-Length
*
* @var boolean
*/
public $content_length = true;
/** /**
* @var array HTTP status codes * @var array HTTP status codes
@ -251,11 +258,13 @@ class Response {
} }
} }
// Send content length if ($this->content_length) {
$length = $this->getContentLength(); // Send content length
$length = $this->getContentLength();
if ($length > 0) { if ($length > 0) {
header('Content-Length: '.$length); header('Content-Length: '.$length);
}
} }
return $this; return $this;

Loading…
Cancel
Save