From 425ff83bdafe9cd60299e9381ee762cf51800c3e Mon Sep 17 00:00:00 2001 From: yarroslav Date: Tue, 22 Apr 2014 10:43:01 +0400 Subject: [PATCH 1/2] Add option not to use zip compression --- UAS/Parser.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/UAS/Parser.php b/UAS/Parser.php index 393724a..895463b 100755 --- a/UAS/Parser.php +++ b/UAS/Parser.php @@ -47,7 +47,12 @@ class Parser * @type bool */ protected $doDownloads = true; - + /** + * Should this instance use zip compression while downloads + * Useful if use mbstring.func_overload + * @type bool + */ + protected $useZipDownloads = true; /** * URL to fetch the full data file from. * @type string @@ -460,7 +465,7 @@ protected function getContents($url, $timeout = 300) array( 'http' => array( 'timeout' => $timeout, - 'header' => "Accept-Encoding: gzip\r\n" + 'header' => ($this->useZipDownloads ? "Accept-Encoding: gzip\r\n" : "") ) ) ) @@ -506,9 +511,15 @@ protected function getContents($url, $timeout = 300) CURLOPT_TIMEOUT => $timeout, CURLOPT_CONNECTTIMEOUT => $timeout, CURLOPT_RETURNTRANSFER => true, - CURLOPT_ENCODING => 'gzip' ) ); + if ($this->useZipDownloads) { + curl_setopt( + $ch, + CURLOPT_ENCODING, + 'gzip' + ); + } $data = curl_exec($ch); if ($data !== false and curl_errno($ch) == 0) { $this->debug( @@ -552,6 +563,14 @@ public function setCacheDir($cache_dir) return true; } + /** + * Set use zip compression while downloading updates. + * @param bool $use + */ + public function setUseZipDownloads($use) { + $this->useZipDownloads = (bool)$use; + } + /** * Get the cache directory * @return string From f436caa9cbce951a8309f27436ab574e55885017 Mon Sep 17 00:00:00 2001 From: yarroslav Date: Tue, 22 Apr 2014 12:26:46 +0400 Subject: [PATCH 2/2] Don't send empty header if don't using zip compression --- UAS/Parser.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/UAS/Parser.php b/UAS/Parser.php index 895463b..20c9145 100755 --- a/UAS/Parser.php +++ b/UAS/Parser.php @@ -457,18 +457,19 @@ protected function getContents($url, $timeout = 300) $starttime = microtime(true); // use fopen if (ini_get('allow_url_fopen')) { + $stream_options = array( + 'http' => array( + 'timeout' => $timeout + ) + ); + if ($this->useZipDownloads) { + $stream_options['http']['header'] = "Accept-Encoding: gzip\r\n"; + } $fp = @fopen( $url, 'rb', false, - stream_context_create( - array( - 'http' => array( - 'timeout' => $timeout, - 'header' => ($this->useZipDownloads ? "Accept-Encoding: gzip\r\n" : "") - ) - ) - ) + stream_context_create($stream_options) ); if (is_resource($fp)) { $data = stream_get_contents($fp);