Skip to content

Commit

Permalink
Disable compression when a compressed sitemap might be delivered FS#2576
Browse files Browse the repository at this point in the history
Compressing a gzip file again for transport is standards compliant, but
some clients assume that the file is only compressed once then and don't
remove the outer compression layer. This could disable compression in
too many cases theses cases should be rare and shouldn't cause any
problems.
  • Loading branch information
michitux committed Aug 24, 2012
1 parent 6427333 commit 65f6e7d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
12 changes: 11 additions & 1 deletion inc/Sitemapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,23 @@ public static function getFilePath() {
global $conf;

$sitemap = $conf['cachedir'].'/sitemap.xml';
if($conf['compression'] === 'bz2' || $conf['compression'] === 'gz'){
if (self::sitemapIsCompressed()) {
$sitemap .= '.gz';
}

return $sitemap;
}

/**
* Helper function for checking if the sitemap is compressed
*
* @return bool If the sitemap file is compressed
*/
public static function sitemapIsCompressed() {
global $conf;
return $conf['compression'] === 'bz2' || $conf['compression'] === 'gz';
}

/**
* Pings search engines with the sitemap url. Plugins can add or remove
* urls to ping using the SITEMAP_PING event.
Expand Down
2 changes: 1 addition & 1 deletion inc/actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ function act_sitemap($act) {
}

$sitemap = Sitemapper::getFilePath();
if(strrchr($sitemap, '.') === '.gz'){
if (Sitemapper::sitemapIsCompressed()) {
$mime = 'application/x-gzip';
}else{
$mime = 'application/xml; charset=utf-8';
Expand Down
6 changes: 5 additions & 1 deletion inc/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,13 @@ function delta_time($start=0) {

// enable gzip compression if supported
$conf['gzip_output'] &= (strpos($_SERVER['HTTP_ACCEPT_ENCODING'],'gzip') !== false);
global $ACT;
if ($conf['gzip_output'] &&
!defined('DOKU_DISABLE_GZIP_OUTPUT') &&
function_exists('ob_gzhandler')) {
function_exists('ob_gzhandler') &&
// Disable compression when a compressed sitemap might be delivered
// See https://bugs.dokuwiki.org/index.php?do=details&task_id=2576
!($ACT == 'sitemap' && Sitemapper::sitemapIsCompressed())) {
ob_start('ob_gzhandler');
}

Expand Down

0 comments on commit 65f6e7d

Please sign in to comment.