mirror of
https://github.com/the-djmaze/snappymail.git
synced 2024-12-25 16:42:13 +08:00
Move brotli and gzip compress option to application.ini
This commit is contained in:
parent
b5db67d23f
commit
202fb08d09
4 changed files with 24 additions and 27 deletions
10
_include.php
10
_include.php
|
@ -4,16 +4,6 @@
|
|||
|
||||
//header('Strict-Transport-Security: max-age=31536000');
|
||||
|
||||
/**
|
||||
* Uncomment to use gzip compressed output
|
||||
*/
|
||||
//define('USE_GZIP', 1);
|
||||
|
||||
/**
|
||||
* Uncomment to use brotli compressed output
|
||||
*/
|
||||
//define('USE_BROTLI', 1);
|
||||
|
||||
/**
|
||||
* Uncomment to enable multiple domain installation.
|
||||
*/
|
||||
|
|
|
@ -171,7 +171,10 @@ class Application extends \RainLoop\Config\AbstractConfig
|
|||
'message_read_delay' => array(5, 'Mark message read after N seconds'),
|
||||
|
||||
'attachment_size_limit' => array(\min($upload_max_filesize, 25), 'File size limit (MB) for file upload on compose screen
|
||||
0 for unlimited.')
|
||||
0 for unlimited.'),
|
||||
|
||||
'compress_output' => array(false, 'brotli or gzip compress the output.
|
||||
Warning: only enable when server does not do this, else double compression errors occur')
|
||||
),
|
||||
|
||||
'interface' => array(
|
||||
|
|
|
@ -43,6 +43,26 @@ abstract class Service
|
|||
exit;
|
||||
}
|
||||
|
||||
// See https://github.com/kjdev/php-ext-brotli
|
||||
if (!empty($_SERVER['HTTP_ACCEPT_ENCODING'])
|
||||
&& $oConfig->Get('webmail', 'compress_output', false)
|
||||
&& !\ini_get('zlib.output_compression')
|
||||
&& !\ini_get('brotli.output_compression')
|
||||
) {
|
||||
if (\is_callable('brotli_compress_add') && false !== \stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'br')) {
|
||||
\ob_start(function(string $buffer, int $phase){
|
||||
static $resource;
|
||||
if ($phase & PHP_OUTPUT_HANDLER_START) {
|
||||
\header('Content-Encoding: br');
|
||||
$resource = \brotli_compress_init(/*int $quality = 11, int $mode = BROTLI_GENERIC*/);
|
||||
}
|
||||
return \brotli_compress_add($resource, $buffer, ($phase & PHP_OUTPUT_HANDLER_FINAL) ? BROTLI_FINISH : BROTLI_PROCESS);
|
||||
});
|
||||
} else {
|
||||
\ob_start('ob_gzhandler');
|
||||
}
|
||||
}
|
||||
|
||||
$sQuery = \trim($_SERVER['QUERY_STRING'] ?? '');
|
||||
$iPos = \strpos($sQuery, '&');
|
||||
if (0 < $iPos) {
|
||||
|
|
|
@ -134,22 +134,6 @@ if (isset($_SERVER['HTTPS'])) {
|
|||
header('Strict-Transport-Security: max-age=31536000');
|
||||
}
|
||||
|
||||
// See https://github.com/kjdev/php-ext-brotli
|
||||
if (!ini_get('zlib.output_compression') && !ini_get('brotli.output_compression')) {
|
||||
if (defined('USE_BROTLI') && is_callable('brotli_compress_add') && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'br')) {
|
||||
ob_start(function(string $buffer, int $phase){
|
||||
static $resource;
|
||||
if ($phase & PHP_OUTPUT_HANDLER_START) {
|
||||
header('Content-Encoding: br');
|
||||
$resource = brotli_compress_init(/*int $quality = 11, int $mode = BROTLI_GENERIC*/);
|
||||
}
|
||||
return brotli_compress_add($resource, $buffer, ($phase & PHP_OUTPUT_HANDLER_FINAL) ? BROTLI_FINISH : BROTLI_PROCESS);
|
||||
});
|
||||
} else if (defined('USE_GZIP')) {
|
||||
ob_start('ob_gzhandler');
|
||||
}
|
||||
}
|
||||
|
||||
// cPanel https://github.com/the-djmaze/snappymail/issues/697
|
||||
if (!empty($_ENV['CPANEL']) && !is_dir(APP_PLUGINS_PATH.'login-remote')) {
|
||||
require __DIR__ . '/cpanel.php';
|
||||
|
|
Loading…
Reference in a new issue