Implemented HTTP->HTTPS redirect and fixed a bug with Output where a 500 is raised when no output is created.

master 1.2.3
Abel Hoogeveen 3 years ago
parent 1180445dcc
commit b976dbeae3
No known key found for this signature in database
GPG Key ID: 96C2234920BF4292
  1. 5
      src/Config/config.web.php
  2. 2
      src/FuzeWorks/Output.php
  3. 17
      src/FuzeWorks/WebComponent.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,

@ -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

@ -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...");

Loading…
Cancel
Save