Skip to content

Commit

Permalink
Better Content-Encoding handling in Apache when content compression…
Browse files Browse the repository at this point in the history
… is disabled [#2619]
  • Loading branch information
mahagr committed Mar 19, 2020
1 parent 9874292 commit 6ba54d2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 14 additions & 11 deletions system/src/Grav/Common/Grav.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,30 +493,33 @@ public function shutdown()
$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');
Expand Down

0 comments on commit 6ba54d2

Please sign in to comment.