1
0
Fork 0

Fix gzip decoding after a redirect

pull/473/head
Jordi Boggiano 2012-03-18 22:12:48 +01:00
parent e4cce193cf
commit 22149d3a70
1 changed files with 16 additions and 9 deletions

View File

@ -110,15 +110,22 @@ class RemoteFilesystem
// decode gzip // decode gzip
if (false !== $result && extension_loaded('zlib') && substr($fileUrl, 0, 4) === 'http') { if (false !== $result && extension_loaded('zlib') && substr($fileUrl, 0, 4) === 'http') {
$decode = false;
foreach ($http_response_header as $header) { foreach ($http_response_header as $header) {
if (preg_match('{^content-encoding: *gzip *$}i', $header)) { if (preg_match('{^content-encoding: *gzip *$}i', $header)) {
if (version_compare(PHP_VERSION, '5.4.0', '>=')) { $decode = true;
$result = zlib_decode($result); continue;
} else { } elseif (preg_match('{^HTTP/}i', $header)) {
// work around issue with gzuncompress & co that do not work with all gzip checksums $decode = false;
$result = file_get_contents('compress.zlib://data:application/octet-stream;base64,'.base64_encode($result)); }
} }
break;
if ($decode) {
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
$result = zlib_decode($result);
} else {
// work around issue with gzuncompress & co that do not work with all gzip checksums
$result = file_get_contents('compress.zlib://data:application/octet-stream;base64,'.base64_encode($result));
} }
} }
} }
@ -138,7 +145,7 @@ class RemoteFilesystem
} }
if (false === $this->result) { if (false === $this->result) {
throw new TransportException("The '$fileUrl' file could not be downloaded"); throw new TransportException('The "'.$fileUrl.'" file could not be downloaded');
} }
} }
@ -156,7 +163,7 @@ class RemoteFilesystem
{ {
switch ($notificationCode) { switch ($notificationCode) {
case STREAM_NOTIFY_FAILURE: case STREAM_NOTIFY_FAILURE:
throw new TransportException(trim($message), $messageCode); throw new TransportException('The "'.$this->fileUrl.'" file could not be downloaded ('.trim($message).')', $messageCode);
break; break;
case STREAM_NOTIFY_AUTH_REQUIRED: case STREAM_NOTIFY_AUTH_REQUIRED: