From 0f838df1b9898b1ac22e424c8e0ea2f6bc33b720 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Mon, 19 Mar 2012 08:35:47 +0000 Subject: [PATCH] switch zlib.output_compression off, as we cant calculate Content-Length header, if its on, doing our own Content-Encoding: gzip now (wont be necessary for Apache2.2 which fixes false Content-Length headers silently, but eg. Lighttpd cuts off content, if wrong Content-Length header specified using md5 of real content for instance specific translations, cant use lang_ctimes for them --- phpgwapi/config.php | 17 ++++++++++++++--- phpgwapi/images.php | 19 +++++++++++++++---- phpgwapi/lang.php | 38 ++++++++++++++++++++++++++++++++------ 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/phpgwapi/config.php b/phpgwapi/config.php index 8a05efb378..92290bcb9f 100644 --- a/phpgwapi/config.php +++ b/phpgwapi/config.php @@ -11,6 +11,9 @@ * @version $Id$ */ +// switch evtl. set output-compression off, as we cant calculate a Content-Length header with transparent compression +ini_set('zlib.output_compression', 0); + $GLOBALS['egw_info'] = array( 'flags' => array( 'currentapp' => 'home', @@ -39,8 +42,16 @@ if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $ common::egw_exit(); } -echo 'egw.set_configs('.json_encode($config).");\n"; -echo 'egw.set_link_registry('.$link_registry.");\n"; +$content = 'egw.set_configs('.json_encode($config).");\n"; +$content .= 'egw.set_link_registry('.$link_registry.");\n"; + +// we run our own gzip compression, to set a correct Content-Length of the encoded content +if (in_array('gzip', explode(',',$_SERVER['HTTP_ACCEPT_ENCODING'])) && function_exists('gzencode')) +{ + $content = gzencode($content); + header('Content-Encoding: gzip'); +} // Content-Lenght header is important, otherwise browsers dont cache! -Header('Content-Length: '.ob_get_length()); \ No newline at end of file +Header('Content-Length: '.bytes($content)); +echo $content; diff --git a/phpgwapi/images.php b/phpgwapi/images.php index 7f221d88fd..2b2c0ccf9a 100644 --- a/phpgwapi/images.php +++ b/phpgwapi/images.php @@ -11,6 +11,9 @@ * @version $Id$ */ +// switch evtl. set output-compression off, as we cant calculate a Content-Length header with transparent compression +ini_set('zlib.output_compression', 0); + $GLOBALS['egw_info'] = array( 'flags' => array( 'currentapp' => 'home', @@ -21,10 +24,10 @@ $GLOBALS['egw_info'] = array( include '../header.inc.php'; -$image_map = common::image_map(preg_match('/^[a-z0-9_-]+$/i',$_GET['template']) ? $_GET['template'] : null); +$content = common::image_map(preg_match('/^[a-z0-9_-]+$/i',$_GET['template']) ? $_GET['template'] : null); // use an etag over the image mapp -$etag = '"'.md5(serialize($image_map)).'"'; +$etag = '"'.md5(serialize($content)).'"'; // headers to allow caching Header('Content-Type: text/javascript; charset=utf-8'); @@ -39,7 +42,15 @@ if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $ common::egw_exit(); } -echo 'egw.set_images('.json_encode($image_map).");\n"; +$content = 'egw.set_images('.json_encode($content).");\n"; + +// we run our own gzip compression, to set a correct Content-Length of the encoded content +if (in_array('gzip', explode(',',$_SERVER['HTTP_ACCEPT_ENCODING'])) && function_exists('gzencode')) +{ + $content = gzencode($content); + header('Content-Encoding: gzip'); +} // Content-Lenght header is important, otherwise browsers dont cache! -Header('Content-Length: '.ob_get_length()); \ No newline at end of file +Header('Content-Length: '.bytes($content)); +echo $content; \ No newline at end of file diff --git a/phpgwapi/lang.php b/phpgwapi/lang.php index 2cb8b6c3ea..844115102a 100644 --- a/phpgwapi/lang.php +++ b/phpgwapi/lang.php @@ -15,6 +15,9 @@ if (!preg_match('/^[a-z0-9_]+$/i', $_GET['app'])) die('No valid application-name given!'); if (!preg_match('/^[a-z]{2}(-[a-z]{2})?$/i', $_GET['lang'])) die('No valid lang-name given!'); +// switch evtl. set output-compression off, as we cant calculate a Content-Length header with transparent compression +ini_set('zlib.output_compression', 0); + $GLOBALS['egw_info'] = array( 'flags' => array( 'currentapp' => in_array($_GET['app'],array('etemplate','common','custom')) ? 'home' : $_GET['app'], @@ -27,7 +30,19 @@ $GLOBALS['egw_info'] = array( include '../header.inc.php'; // use an etag with app, lang and a hash over the creation-times of all lang-files -$etag = '"'.$_GET['app'].'-'.$_GET['lang'].'-'.md5(serialize($GLOBALS['egw_info']['server']['lang_ctimes'])).'"'; +if (!in_array($_GET['app'], translation::$instance_specific_translations)) +{ + $etag = '"'.$_GET['app'].'-'.$_GET['lang'].'-'.md5(serialize($GLOBALS['egw_info']['server']['lang_ctimes'])).'"'; +} +else +{ + translation::add_app($_GET['app'], $_GET['lang']); + if (!count(translation::$lang_arr)) + { + translation::add_app($_GET['app'], 'en'); + } + $etag = '"'.$_GET['app'].'-'.$_GET['lang'].'-'.md5(serialize(translation::$lang_arr)); +} // headers to allow caching of one month Header('Content-Type: text/javascript; charset=utf-8'); @@ -42,13 +57,24 @@ if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && $_SERVER['HTTP_IF_NONE_MATCH'] == $ common::egw_exit(); } -translation::add_app($_GET['app'], $_GET['lang']); -if (!count(translation::$lang_arr)) +if (!in_array($_GET['app'], translation::$instance_specific_translations)) { - translation::add_app($_GET['app'], 'en'); + translation::add_app($_GET['app'], $_GET['lang']); + if (!count(translation::$lang_arr)) + { + translation::add_app($_GET['app'], 'en'); + } } -echo 'egw.set_lang_arr("'.$_GET['app'].'", '.json_encode(translation::$lang_arr).');'; +$content = 'egw.set_lang_arr("'.$_GET['app'].'", '.json_encode(translation::$lang_arr).');'; + +// we run our own gzip compression, to set a correct Content-Length of the encoded content +if (in_array('gzip', explode(',',$_SERVER['HTTP_ACCEPT_ENCODING'])) && function_exists('gzencode')) +{ + $content = gzencode($content); + header('Content-Encoding: gzip'); +} // Content-Lenght header is important, otherwise browsers dont cache! -Header('Content-Length: '.ob_get_length()); \ No newline at end of file +Header('Content-Length: '.bytes($content)); +echo $content;