Only implement zlib fix for apache2handler - tested fine with Caddy

This commit is contained in:
Andy Miller 2016-05-27 17:50:31 -06:00
parent 7a3ae9186b
commit 5acfdee876
2 changed files with 6 additions and 12 deletions

View File

@ -128,12 +128,13 @@ class Grav extends Container
$this->header();
// Compress output manually if zlib enabled
if ($this['config']->get('system.zlib-output-compression', false)) {
if ($this['config']->get('system.apache_zlib_fix', false)) {
ob_start();
echo $this->output;
$debugger->render();
$output = ob_get_clean();
echo gzencode($output, 1, FORCE_GZIP);
header("Content-Encoding: gzip");
} else {
echo $this->output;
$debugger->render();
@ -290,11 +291,6 @@ class Grav extends Container
if ($this['config']->get('system.pages.vary_accept_encoding', false)) {
header('Vary: Accept-Encoding');
}
// Gzip encoding via zlib.output_compression
if ($this['config']->get('system.zlib-output-compression', false)) {
header("Content-Encoding: gzip");
}
}
/**
@ -340,7 +336,7 @@ class Grav extends Container
// Unfortunately without FastCGI there is no way to force close the connection. We need to ask browser to
// close the connection for us.
$offset = $this['config']->get('system.zlib-output-compression', false) && !$this['config']->get('system.debugger.enabled', false) ? 0 : 1;
$offset = $this['config']->get('system.apache_zlib_fix', false) && !$this['config']->get('system.debugger.enabled', false) ? 0 : 1;
while (ob_get_level() > $this['output_buffer_level'] + $offset) {
ob_end_flush();
@ -361,8 +357,6 @@ class Grav extends Container
// Run any time consuming tasks.
$this->fireEvent('onShutdown');
sleep(3);
}
/**

View File

@ -11,11 +11,11 @@ class InitializeProcessor extends ProcessorBase implements ProcessorInterface {
$this->container['output_buffer_level'] = ob_get_level();
// disable built-in gzip + shutdown if already doing zlib.output_compression
if (ini_get('zlib.output_compression')) {
// mod_php + zlib.output_compression do sutff differently
if (php_sapi_name() === 'apache2handler' && ini_get('zlib.output_compression')) {
// disable Grav's gzip option as it conflicts with zlib.output_compression
$this->container['config']->set('system.cache.gzip', false);
$this->container['config']->set('system.zlib-output-compression', true);
$this->container['config']->set('system.apache_zlib_fix', true);
}
// Use output buffering to prevent headers from being sent too early.