diff --git a/src/Config/config.web.php b/src/Config/config.web.php index 84fb65a..3f0b51b 100644 --- a/src/Config/config.web.php +++ b/src/Config/config.web.php @@ -49,8 +49,11 @@ return [ 'permitted_uri_chars' => 'a-z 0-9~%.:_\-', 'charset' => 'UTF-8', + // Whether to redirect http traffic to https + 'redirect_to_https' => false, + // Whether to gzip the output when the client supports it - 'compress_output' => true, + 'compress_output' => false, // Global switch for output cache. To use, must be enabled in view as well 'cache_output' => true, diff --git a/src/FuzeWorks/Output.php b/src/FuzeWorks/Output.php index 9c58b58..8752751 100644 --- a/src/FuzeWorks/Output.php +++ b/src/FuzeWorks/Output.php @@ -145,7 +145,7 @@ class Output $output = is_null($output) ? $this->output : $output; // Write cache if requested to do so - if ($this->cacheTime > 0) + if ($this->cacheTime > 0 && !is_null($output)) $this->writeCache($output); // First send status code diff --git a/src/FuzeWorks/WebComponent.php b/src/FuzeWorks/WebComponent.php index d4f5a2b..e7b6b0c 100644 --- a/src/FuzeWorks/WebComponent.php +++ b/src/FuzeWorks/WebComponent.php @@ -190,14 +190,31 @@ class WebComponent implements iComponent /** @var Router $router */ /** @var URI $uri */ + /** @var Input $input */ /** @var Output $output */ /** @var Security $security */ /** @var Resources $resources */ + /** @var Config $config */ $router = Factory::getInstance('router'); $uri = Factory::getInstance('uri'); + $input = Factory::getInstance('input'); $output = Factory::getInstance('output'); $security = Factory::getInstance('security'); $resources = Factory::getInstance('resources'); + $config = Factory::getInstance('config'); + + // First check if this isn't https and we need to redirect + $redirect = $config->getConfig('web')->get('redirect_to_https'); + if ($redirect && !$input->isHttps()) + { + Logger::log("Redirecting http traffic to https..."); + $httpsInputs = $input->server(['HTTPS', 'HTTP_HOST', 'REQUEST_URI']); + $location = 'https://' . $httpsInputs['HTTP_HOST'] . $httpsInputs['REQUEST_URI']; + + $output->setStatusHeader(301); + $output->setHeader('Location: ' . $location); + return true; + } // And start logging the request Logger::newLevel("Routing web request...");