diff --git a/core/basepage.php b/core/basepage.php index 61530187..f8827ae9 100644 --- a/core/basepage.php +++ b/core/basepage.php @@ -7,6 +7,7 @@ abstract class PageMode const DATA = 'data'; const PAGE = 'page'; const FILE = 'file'; + const MANUAL = 'manual'; } /** @@ -238,16 +239,13 @@ class BasePage // ============================================== - /** - * Display the page according to the mode and data given. - */ - public function display(): void + public function send_headers(): void { - header("HTTP/1.0 {$this->code} Shimmie"); - header("Content-type: " . $this->type); - header("X-Powered-By: Shimmie-" . VERSION); - if (!headers_sent()) { + header("HTTP/1.0 {$this->code} Shimmie"); + header("Content-type: " . $this->type); + header("X-Powered-By: Shimmie-" . VERSION); + foreach ($this->http_headers as $head) { header($head); } @@ -257,8 +255,25 @@ class BasePage } else { print "Error: Headers have already been sent to the client."; } + } + + public function flush_output(): void + { + + } + + /** + * Display the page according to the mode and data given. + */ + public function display(): void + { + if($this->mode!=PageMode::MANUAL) { + $this->send_headers(); + } switch ($this->mode) { + case PageMode::MANUAL: + break; case PageMode::PAGE: usort($this->blocks, "blockcmp"); $this->add_auto_html_headers(); diff --git a/core/polyfills.php b/core/polyfills.php index 8a54ac2d..0b733987 100644 --- a/core/polyfills.php +++ b/core/polyfills.php @@ -150,6 +150,14 @@ function list_files(string $base, string $_sub_dir=""): array return $file_list; } +function flush_output(): void +{ + if (!defined("UNITTEST")) { + @ob_flush(); + } + flush(); +} + function stream_file(string $file, int $start, int $end): void { $fp = fopen($file, 'r'); @@ -162,10 +170,7 @@ function stream_file(string $file, int $start, int $end): void $buffer = $end - $p + 1; } echo fread($fp, $buffer); - if (!defined("UNITTEST")) { - @ob_flush(); - } - flush(); + flush_output(); // After flush, we can tell if the client browser has disconnected. // This means we can start sending a large file, and if we detect they disappeared