Better Content-Encoding handling in Apache when content compression is disabled [#2619]

This commit is contained in:
Matias Griese
2020-03-19 11:31:24 +02:00
parent 987429208c
commit 6ba54d2b3d
2 changed files with 15 additions and 11 deletions

View File

@@ -6,6 +6,7 @@
* Added `Folder::hasChildren()` method to determine if a folder has child folders
1. [](#improved)
* Save memory when updating large flex indexes
* Better `Content-Encoding` handling in Apache when content compression is disabled [#2619](https://github.com/getgrav/grav/issues/2619)
1. [](#bugfix)
* Fixed creating new `Flex User` when folder storage has been selected
* Fixed some bugs in Flex root page methods

View File

@@ -493,30 +493,33 @@ class Grav extends Container
$this['session']->close();
}
if ($this['config']->get('system.debugger.shutdown.close_connection', true)) {
/** @var Config $config */
$config = $this['config'];
if ($config->get('system.debugger.shutdown.close_connection', true)) {
// Flush the response and close the connection to allow time consuming tasks to be performed without leaving
// the connection to the client open. This will make page loads to feel much faster.
// FastCGI allows us to flush all response data to the client and finish the request.
$success = \function_exists('fastcgi_finish_request') ? @fastcgi_finish_request() : false;
if (!$success) {
// Unfortunately without FastCGI there is no way to force close the connection.
// We need to ask browser to close the connection for us.
if ($this['config']->get('system.cache.gzip')) {
// Flush gzhandler buffer if gzip setting was enabled.
if ($config->get('system.cache.gzip')) {
// Flush gzhandler buffer if gzip setting was enabled to get the size of the compressed output.
ob_end_flush();
} else {
} elseif ($config->get('system.cache.allow_webserver_gzip')) {
// Let web server to do the hard work.
header('Content-Encoding: identity');
} elseif (function_exists('apache_setenv')) {
// Without gzip we have no other choice than to prevent server from compressing the output.
// This action turns off mod_deflate which would prevent us from closing the connection.
if ($this['config']->get('system.cache.allow_webserver_gzip')) {
header('Content-Encoding: identity');
} else {
header('Content-Encoding: none');
}
@apache_setenv('no-gzip', '1');
} else {
// Fall back to unknown content encoding, it prevents most servers from deflating the content.
header('Content-Encoding: none');
}
// Get length and close the connection.
header('Content-Length: ' . ob_get_length());
header('Connection: close');