* @category Community Framework
*/
final class HeaderUtil {
+ /**
+ * gzip compression
+ * @var boolean
+ */
+ protected static $enableGzipCompression = false;
+
/**
* output HTML
* @var string
self::sendNoCacheHeaders();
}
- ob_start(array('wcf\util\HeaderUtil', 'parseOutput'));
+ if (HTTP_ENABLE_GZIP && HTTP_GZIP_LEVEL > 0 && HTTP_GZIP_LEVEL < 10 && !defined('HTTP_DISABLE_GZIP')) {
+ if (function_exists('gzcompress') && !@ini_get('zlib.output_compression') && !@ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
+ self::$enableGzipCompression = true;
+
+ if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip')) {
+ @header('Content-Encoding: x-gzip');
+ }
+ else {
+ @header('Content-Encoding: gzip');
+ }
+ }
+ }
// send Internet Explorer compatibility mode
@header('X-UA-Compatible: IE=edge');
+
+ ob_start(array('wcf\util\HeaderUtil', 'parseOutput'));
}
/**
// class. Use HeaderUtil::$output to modify it.
if (!defined('NO_IMPORTS')) EventHandler::getInstance()->fireAction('wcf\util\HeaderUtil', 'parseOutput');
- // enable gzip compression
- if (HTTP_ENABLE_GZIP && HTTP_GZIP_LEVEL > 0 && HTTP_GZIP_LEVEL < 10 && !defined('HTTP_DISABLE_GZIP')) {
- if (function_exists('gzcompress') && !@ini_get('zlib.output_compression') && !@ini_get('output_handler') && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {
- if (strstr($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip')) {
- @header('Content-Encoding: x-gzip');
- }
- else {
- @header('Content-Encoding: gzip');
- }
-
- $size = strlen(self::$output);
- $crc = crc32(self::$output);
-
- $newOutput = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff";
- $newOutput .= substr(gzcompress(self::$output, HTTP_GZIP_LEVEL), 2, -4);
- $newOutput .= pack('V', $crc);
- $newOutput .= pack('V', $size);
-
- self::$output = $newOutput;
- }
+ // gzip compression
+ if (self::$enableGzipCompression) {
+ $size = strlen(self::$output);
+ $crc = crc32(self::$output);
+
+ $newOutput = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff";
+ $newOutput .= substr(gzcompress(self::$output, HTTP_GZIP_LEVEL), 2, -4);
+ $newOutput .= pack('V', $crc);
+ $newOutput .= pack('V', $size);
+
+ self::$output = $newOutput;
}
return self::$output;