mirror of
https://github.com/kd2org/picodav.git
synced 2025-01-03 11:22:11 +01:00
Limit gzip compression to smaller files, also exclude other kinds of files
FossilOrigin-Name: a3177a11497ba8fba76a22d20d395cd1aa852c53de11c65c11639dcbfe89b0a3
This commit is contained in:
parent
b9f7ae4f24
commit
8ad0953bc5
1 changed files with 12 additions and 7 deletions
19
index.php
19
index.php
|
@ -34,6 +34,8 @@ namespace KD2\WebDAV
|
||||||
const SHARED_LOCK = 'shared';
|
const SHARED_LOCK = 'shared';
|
||||||
const EXCLUSIVE_LOCK = 'exclusive';
|
const EXCLUSIVE_LOCK = 'exclusive';
|
||||||
|
|
||||||
|
protected bool $enable_gzip = true;
|
||||||
|
|
||||||
protected string $base_uri;
|
protected string $base_uri;
|
||||||
|
|
||||||
public string $original_uri;
|
public string $original_uri;
|
||||||
|
@ -344,17 +346,20 @@ namespace KD2\WebDAV
|
||||||
|
|
||||||
$this->log('HTTP Range requested: %s-%s', $start, $end);
|
$this->log('HTTP Range requested: %s-%s', $start, $end);
|
||||||
}
|
}
|
||||||
elseif (isset($_SERVER['HTTP_ACCEPT_ENCODING'])
|
elseif ($this->enable_gzip
|
||||||
|
&& isset($_SERVER['HTTP_ACCEPT_ENCODING'])
|
||||||
&& false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')
|
&& false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')
|
||||||
|
&& isset($props['DAV::getcontentlength'])
|
||||||
|
// Don't compress if size is larger than 8 MiB
|
||||||
|
&& $props['DAV::getcontentlength'] < 8*1024*1024
|
||||||
// Don't compress already compressed content
|
// Don't compress already compressed content
|
||||||
&& !preg_match('/\.(?:mp4|m4a|zip|docx|xlsx|ods|odt|odp|7z|gz|bz2|rar|webm|ogg|mp3|ogm|flac|ogv|mkv|avi)$/i', $uri)) {
|
&& !preg_match('/\.(?:cbz|cbr|cb7|mp4|m4a|zip|docx|xlsx|pptx|ods|odt|odp|7z|gz|bz2|lzma|lz|xz|apk|dmg|jar|rar|webm|ogg|mp3|ogm|flac|ogv|mkv|avi)$/i', $uri)) {
|
||||||
$gzip = true;
|
$gzip = true;
|
||||||
header('Content-Encoding: gzip', true);
|
header('Content-Encoding: gzip', true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to avoid common issues with output buffering and stuff
|
// Try to avoid common issues with output buffering and stuff
|
||||||
if (function_exists('apache_setenv'))
|
if (function_exists('apache_setenv')) {
|
||||||
{
|
|
||||||
@apache_setenv('no-gzip', 1);
|
@apache_setenv('no-gzip', 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,7 +441,7 @@ namespace KD2\WebDAV
|
||||||
|
|
||||||
if ($gzip) {
|
if ($gzip) {
|
||||||
$this->log('Using gzip output compression');
|
$this->log('Using gzip output compression');
|
||||||
$gzip = deflate_init(ZLIB_ENCODING_GZIP, ['level' => 9]);
|
$gzip = deflate_init(ZLIB_ENCODING_GZIP);
|
||||||
|
|
||||||
$fp = fopen('php://temp', 'wb');
|
$fp = fopen('php://temp', 'wb');
|
||||||
|
|
||||||
|
@ -1883,11 +1888,11 @@ RewriteRule ^.*$ /index.php [END]
|
||||||
$fp = fopen(__FILE__, 'r');
|
$fp = fopen(__FILE__, 'r');
|
||||||
|
|
||||||
if ($relative_uri == '.webdav/webdav.js') {
|
if ($relative_uri == '.webdav/webdav.js') {
|
||||||
fseek($fp, 50401, SEEK_SET);
|
fseek($fp, 50637, SEEK_SET);
|
||||||
echo fread($fp, 27769);
|
echo fread($fp, 27769);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fseek($fp, 50401 + 27769, SEEK_SET);
|
fseek($fp, 50637 + 27769, SEEK_SET);
|
||||||
echo fread($fp, 7004);
|
echo fread($fp, 7004);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue