From aa0f9ab0890b75bd6210338d1a4cd7d45c00eabf Mon Sep 17 00:00:00 2001
From: Fil <fil@rezo.net>
Date: Mon, 16 May 2005 11:19:08 +0000
Subject: [PATCH] Retour de la compression automatique, qui se trouvait
 desactivee a cause d'un code mort :-(

Gestion de la compression gzip dans inc_sites.php3 (permet de syndiquer "plus vite", en chargeant moins la bande passante)
---
 ecrire/inc_sites.php3   | 12 +++++++++++-
 ecrire/inc_version.php3 |  5 +++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/ecrire/inc_sites.php3 b/ecrire/inc_sites.php3
index 165beee454..74bd954d14 100644
--- a/ecrire/inc_sites.php3
+++ b/ecrire/inc_sites.php3
@@ -116,6 +116,10 @@ function init_http($get, $url) {
 		if ($referer = lire_meta("adresse_site"))
 			fputs($f, "Referer: $referer/\r\n");
 
+		// On sait lire du gzip
+		if ($GLOBALS['flag_gz'])
+			fputs($f, "Accept-Encoding: gzip\r\n");
+
 	}
 	// fallback : fopen
 	else if (!$GLOBALS['tester_proxy']) {
@@ -172,6 +176,8 @@ function recuperer_page($url, $munge_charset=false, $get_headers=false, $taille_
 					$location = suivre_lien($url, $r[1]);
 					spip_log("Location: $location");
 				}
+				if (preg_match(",^Content-Encoding: .*gzip,i", $s))
+					$gz = true;
 			}
 			if ($status >= 300 AND $status < 400 AND $location)
 				$url = $location;
@@ -185,15 +191,19 @@ function recuperer_page($url, $munge_charset=false, $get_headers=false, $taille_
 	}
 
 	// Contenu de la page
+	$result = '';
 	if (!$f) {
 		spip_log("ECHEC chargement $url");
-		$result = '';
 	} else {
 		while (!feof($f) AND strlen($result)<$taille_max)
 			$result .= fread($f, 16384);
 		fclose($f);
 	}
 
+	// Decompresser le flux
+	if ($gz)
+		$result = gzinflate(substr($result,10));
+
 	// Faut-il l'importer dans notre charset local ?
 	if ($munge_charset) {
 		include_ecrire('inc_charsets.php3');
diff --git a/ecrire/inc_version.php3 b/ecrire/inc_version.php3
index 4d8095ae76..b4dde2fe5b 100644
--- a/ecrire/inc_version.php3
+++ b/ecrire/inc_version.php3
@@ -652,7 +652,6 @@ function test_obgz () {
 	&& $GLOBALS['flag_ob']
 	&& (phpversion()<>'4.0.4')
 	&& function_exists("ob_gzhandler")
-	&& $GLOBALS['flag_obgz']
 	// special bug de proxy
 	&& !eregi("NetCache|Hasd_proxy", $GLOBALS['HTTP_VIA'])
 	// special bug Netscape Win 4.0x
@@ -664,11 +663,13 @@ function test_obgz () {
 	&& !@ini_get("zlib.output_compression")
 	&& !@ini_get("output_handler");
 }
+
 // si un buffer est deja ouvert, stop
 if ($flag_ob AND !headers_sent()) {
 	@header("Vary: Cookie, Accept-Encoding");
-	if (test_obgz())
+	if (test_obgz()) {
 		ob_start('ob_gzhandler');
+	}
 }
 
 
-- 
GitLab