mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-29 08:09:58 +09:00
Update composer dependencies
This commit is contained in:
parent
49cc39e507
commit
cbd324c35b
428 changed files with 17862 additions and 5885 deletions
255
vendor/rmccue/requests/library/Requests.php
vendored
Executable file → Normal file
255
vendor/rmccue/requests/library/Requests.php
vendored
Executable file → Normal file
|
|
@ -54,20 +54,41 @@ class Requests {
|
|||
*/
|
||||
const DELETE = 'DELETE';
|
||||
|
||||
/**
|
||||
* OPTIONS method
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const OPTIONS = 'OPTIONS';
|
||||
|
||||
/**
|
||||
* TRACE method
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const TRACE = 'TRACE';
|
||||
|
||||
/**
|
||||
* PATCH method
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc5789
|
||||
* @link https://tools.ietf.org/html/rfc5789
|
||||
* @var string
|
||||
*/
|
||||
const PATCH = 'PATCH';
|
||||
|
||||
/**
|
||||
* Default size of buffer size to read streams
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
const BUFFER_SIZE = 1160;
|
||||
|
||||
/**
|
||||
* Current version of Requests
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
const VERSION = '1.6.1';
|
||||
const VERSION = '1.7';
|
||||
|
||||
/**
|
||||
* Registered transport classes
|
||||
|
|
@ -81,9 +102,19 @@ class Requests {
|
|||
*
|
||||
* Use {@see get_transport()} instead
|
||||
*
|
||||
* @var string|null
|
||||
* @var array
|
||||
*/
|
||||
public static $transport = null;
|
||||
public static $transport = array();
|
||||
|
||||
/**
|
||||
* Default certificate path.
|
||||
*
|
||||
* @see Requests::get_certificate_path()
|
||||
* @see Requests::set_certificate_path()
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $certificate_path;
|
||||
|
||||
/**
|
||||
* This is a static class, do not instantiate it
|
||||
|
|
@ -147,11 +178,16 @@ class Requests {
|
|||
* @throws Requests_Exception If no valid transport is found (`notransport`)
|
||||
* @return Requests_Transport
|
||||
*/
|
||||
protected static function get_transport() {
|
||||
protected static function get_transport($capabilities = array()) {
|
||||
// Caching code, don't bother testing coverage
|
||||
// @codeCoverageIgnoreStart
|
||||
if (self::$transport !== null) {
|
||||
return new self::$transport();
|
||||
// array of capabilities as a string to be used as an array key
|
||||
ksort($capabilities);
|
||||
$cap_string = serialize($capabilities);
|
||||
|
||||
// Don't search for a transport if it's already been done for these $capabilities
|
||||
if (isset(self::$transport[$cap_string]) && self::$transport[$cap_string] !== null) {
|
||||
return new self::$transport[$cap_string]();
|
||||
}
|
||||
// @codeCoverageIgnoreEnd
|
||||
|
||||
|
|
@ -164,20 +200,21 @@ class Requests {
|
|||
|
||||
// Find us a working transport
|
||||
foreach (self::$transports as $class) {
|
||||
if (!class_exists($class))
|
||||
if (!class_exists($class)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$result = call_user_func(array($class, 'test'));
|
||||
$result = call_user_func(array($class, 'test'), $capabilities);
|
||||
if ($result) {
|
||||
self::$transport = $class;
|
||||
self::$transport[$cap_string] = $class;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (self::$transport === null) {
|
||||
if (self::$transport[$cap_string] === null) {
|
||||
throw new Requests_Exception('No working transports found', 'notransport', self::$transports);
|
||||
}
|
||||
|
||||
return new self::$transport();
|
||||
return new self::$transport[$cap_string]();
|
||||
}
|
||||
|
||||
/**#@+
|
||||
|
|
@ -207,6 +244,13 @@ class Requests {
|
|||
public static function delete($url, $headers = array(), $options = array()) {
|
||||
return self::request($url, $headers, null, self::DELETE, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a TRACE request
|
||||
*/
|
||||
public static function trace($url, $headers = array(), $options = array()) {
|
||||
return self::request($url, $headers, null, self::TRACE, $options);
|
||||
}
|
||||
/**#@-*/
|
||||
|
||||
/**#@+
|
||||
|
|
@ -230,13 +274,20 @@ class Requests {
|
|||
return self::request($url, $headers, $data, self::PUT, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send an OPTIONS request
|
||||
*/
|
||||
public static function options($url, $headers = array(), $data = array(), $options = array()) {
|
||||
return self::request($url, $headers, $data, self::OPTIONS, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a PATCH request
|
||||
*
|
||||
* Note: Unlike {@see post} and {@see put}, `$headers` is required, as the
|
||||
* specification recommends that should send an ETag
|
||||
*
|
||||
* @link http://tools.ietf.org/html/rfc5789
|
||||
* @link https://tools.ietf.org/html/rfc5789
|
||||
*/
|
||||
public static function patch($url, $headers, $data = array(), $options = array()) {
|
||||
return self::request($url, $headers, $data, self::PATCH, $options);
|
||||
|
|
@ -253,7 +304,11 @@ class Requests {
|
|||
* options:
|
||||
*
|
||||
* - `timeout`: How long should we wait for a response?
|
||||
* (integer, seconds, default: 10)
|
||||
* Note: for cURL, a minimum of 1 second applies, as DNS resolution
|
||||
* operates at second-resolution only.
|
||||
* (float, seconds with a millisecond precision, default: 10, example: 0.01)
|
||||
* - `connect_timeout`: How long should we wait while trying to connect?
|
||||
* (float, seconds with a millisecond precision, default: 10, example: 0.01)
|
||||
* - `useragent`: Useragent to send to the server
|
||||
* (string, default: php-requests/$version)
|
||||
* - `follow_redirects`: Should we follow 3xx redirects?
|
||||
|
|
@ -268,7 +323,9 @@ class Requests {
|
|||
* for Basic authentication
|
||||
* (Requests_Auth|array|boolean, default: false)
|
||||
* - `proxy`: Proxy details to use for proxy by-passing and authentication
|
||||
* (Requests_Proxy|array|boolean, default: false)
|
||||
* (Requests_Proxy|array|string|boolean, default: false)
|
||||
* - `max_bytes`: Limit for the response body size.
|
||||
* (integer|boolean, default: false)
|
||||
* - `idn`: Enable IDN parsing
|
||||
* (boolean, default: true)
|
||||
* - `transport`: Custom transport. Either a class name, or a
|
||||
|
|
@ -284,12 +341,15 @@ class Requests {
|
|||
* (string|boolean, default: library/Requests/Transport/cacert.pem)
|
||||
* - `verifyname`: Should we verify the common name in the SSL certificate?
|
||||
* (boolean: default, true)
|
||||
* - `data_format`: How should we send the `$data` parameter?
|
||||
* (string, one of 'query' or 'body', default: 'query' for
|
||||
* HEAD/GET/DELETE, 'body' for POST/PUT/OPTIONS/PATCH)
|
||||
*
|
||||
* @throws Requests_Exception On invalid URLs (`nonhttp`)
|
||||
*
|
||||
* @param string $url URL to request
|
||||
* @param array $headers Extra headers to send with the request
|
||||
* @param array $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param string $type HTTP request type (use Requests constants)
|
||||
* @param array $options Options for the request (see description for more information)
|
||||
* @return Requests_Response
|
||||
|
|
@ -312,7 +372,9 @@ class Requests {
|
|||
}
|
||||
}
|
||||
else {
|
||||
$transport = self::get_transport();
|
||||
$need_ssl = (0 === stripos($url, 'https://'));
|
||||
$capabilities = array('ssl' => $need_ssl);
|
||||
$transport = self::get_transport($capabilities);
|
||||
}
|
||||
$response = $transport->request($url, $headers, $data, $options);
|
||||
|
||||
|
|
@ -343,9 +405,6 @@ class Requests {
|
|||
* - `type`: HTTP request type (use Requests constants). Same as the `$type`
|
||||
* parameter to {@see Requests::request}
|
||||
* (string, default: `Requests::GET`)
|
||||
* - `data`: Associative array of options. Same as the `$options` parameter
|
||||
* to {@see Requests::request}
|
||||
* (array, default: see {@see Requests::request})
|
||||
* - `cookies`: Associative array of cookie name to value, or cookie jar.
|
||||
* (array|Requests_Cookie_Jar)
|
||||
*
|
||||
|
|
@ -443,7 +502,9 @@ class Requests {
|
|||
protected static function get_default_options($multirequest = false) {
|
||||
$defaults = array(
|
||||
'timeout' => 10,
|
||||
'connect_timeout' => 10,
|
||||
'useragent' => 'php-requests/' . self::VERSION,
|
||||
'protocol_version' => 1.1,
|
||||
'redirected' => 0,
|
||||
'redirects' => 10,
|
||||
'follow_redirects' => true,
|
||||
|
|
@ -453,10 +514,11 @@ class Requests {
|
|||
'auth' => false,
|
||||
'proxy' => false,
|
||||
'cookies' => false,
|
||||
'max_bytes' => false,
|
||||
'idn' => true,
|
||||
'hooks' => null,
|
||||
'transport' => null,
|
||||
'verify' => dirname( __FILE__ ) . '/Requests/Transport/cacert.pem',
|
||||
'verify' => Requests::get_certificate_path(),
|
||||
'verifyname' => true,
|
||||
);
|
||||
if ($multirequest !== false) {
|
||||
|
|
@ -465,19 +527,41 @@ class Requests {
|
|||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default certificate path.
|
||||
*
|
||||
* @return string Default certificate path.
|
||||
*/
|
||||
public static function get_certificate_path() {
|
||||
if ( ! empty( Requests::$certificate_path ) ) {
|
||||
return Requests::$certificate_path;
|
||||
}
|
||||
|
||||
return dirname(__FILE__) . '/Requests/Transport/cacert.pem';
|
||||
}
|
||||
|
||||
/**
|
||||
* Set default certificate path.
|
||||
*
|
||||
* @param string $path Certificate path, pointing to a PEM file.
|
||||
*/
|
||||
public static function set_certificate_path( $path ) {
|
||||
Requests::$certificate_path = $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default values
|
||||
*
|
||||
* @param string $url URL to request
|
||||
* @param array $headers Extra headers to send with the request
|
||||
* @param array $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param array|null $data Data to send either as a query string for GET/HEAD requests, or in the body for POST requests
|
||||
* @param string $type HTTP request type
|
||||
* @param array $options Options for the request
|
||||
* @return array $options
|
||||
*/
|
||||
protected static function set_defaults(&$url, &$headers, &$data, &$type, &$options) {
|
||||
if (!preg_match('/^http(s)?:\/\//i', $url)) {
|
||||
throw new Requests_Exception('Only HTTP requests are handled.', 'nonhttp', $url);
|
||||
if (!preg_match('/^http(s)?:\/\//i', $url, $matches)) {
|
||||
throw new Requests_Exception('Only HTTP(S) requests are handled.', 'nonhttp', $url);
|
||||
}
|
||||
|
||||
if (empty($options['hooks'])) {
|
||||
|
|
@ -491,7 +575,7 @@ class Requests {
|
|||
$options['auth']->register($options['hooks']);
|
||||
}
|
||||
|
||||
if (!empty($options['proxy'])) {
|
||||
if (is_string($options['proxy']) || is_array($options['proxy'])) {
|
||||
$options['proxy'] = new Requests_Proxy_HTTP($options['proxy']);
|
||||
}
|
||||
if ($options['proxy'] !== false) {
|
||||
|
|
@ -513,6 +597,18 @@ class Requests {
|
|||
$iri->host = Requests_IDNAEncoder::encode($iri->ihost);
|
||||
$url = $iri->uri;
|
||||
}
|
||||
|
||||
// Massage the type to ensure we support it.
|
||||
$type = strtoupper($type);
|
||||
|
||||
if (!isset($options['data_format'])) {
|
||||
if (in_array($type, array(self::HEAD, self::GET, self::DELETE))) {
|
||||
$options['data_format'] = 'query';
|
||||
}
|
||||
else {
|
||||
$options['data_format'] = 'body';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -555,11 +651,12 @@ class Requests {
|
|||
// Unfold headers (replace [CRLF] 1*( SP | HT ) with SP) as per RFC 2616 (section 2.2)
|
||||
$headers = preg_replace('/\n[ \t]/', ' ', $headers);
|
||||
$headers = explode("\n", $headers);
|
||||
preg_match('#^HTTP/1\.\d[ \t]+(\d+)#i', array_shift($headers), $matches);
|
||||
preg_match('#^HTTP/(1\.\d)[ \t]+(\d+)#i', array_shift($headers), $matches);
|
||||
if (empty($matches)) {
|
||||
throw new Requests_Exception('Response could not be parsed', 'noversion', $headers);
|
||||
}
|
||||
$return->status_code = (int) $matches[1];
|
||||
$return->protocol_version = (float) $matches[1];
|
||||
$return->status_code = (int) $matches[2];
|
||||
if ($return->status_code >= 200 && $return->status_code < 300) {
|
||||
$return->success = true;
|
||||
}
|
||||
|
|
@ -585,19 +682,28 @@ class Requests {
|
|||
|
||||
$options['hooks']->dispatch('requests.before_redirect_check', array(&$return, $req_headers, $req_data, $options));
|
||||
|
||||
if ((in_array($return->status_code, array(300, 301, 302, 303, 307)) || $return->status_code > 307 && $return->status_code < 400) && $options['follow_redirects'] === true) {
|
||||
if ($return->is_redirect() && $options['follow_redirects'] === true) {
|
||||
if (isset($return->headers['location']) && $options['redirected'] < $options['redirects']) {
|
||||
if ($return->status_code === 303) {
|
||||
$options['type'] = Requests::GET;
|
||||
$options['type'] = self::GET;
|
||||
}
|
||||
$options['redirected']++;
|
||||
$location = $return->headers['location'];
|
||||
if (strpos ($location, '/') === 0) {
|
||||
if (strpos($location, 'http://') !== 0 && strpos($location, 'https://') !== 0) {
|
||||
// relative redirect, for compatibility make it absolute
|
||||
$location = Requests_IRI::absolutize($url, $location);
|
||||
$location = $location->uri;
|
||||
}
|
||||
$redirected = self::request($location, $req_headers, $req_data, false, $options);
|
||||
|
||||
$hook_args = array(
|
||||
&$location,
|
||||
&$req_headers,
|
||||
&$req_data,
|
||||
&$options,
|
||||
$return
|
||||
);
|
||||
$options['hooks']->dispatch('requests.before_redirect', $hook_args);
|
||||
$redirected = self::request($location, $req_headers, $req_data, $options['type'], $options);
|
||||
$redirected->history[] = $return;
|
||||
return $redirected;
|
||||
}
|
||||
|
|
@ -618,13 +724,17 @@ class Requests {
|
|||
* Internal use only. Converts a raw HTTP response to a Requests_Response
|
||||
* while still executing a multiple request.
|
||||
*
|
||||
* @param string $headers Full response text including headers and body
|
||||
* @param string $response Full response text including headers and body (will be overwritten with Response instance)
|
||||
* @param array $request Request data as passed into {@see Requests::request_multiple()}
|
||||
* @return null `$response` is either set to a Requests_Response instance, or a Requests_Exception object
|
||||
*/
|
||||
public static function parse_multiple(&$response, $request) {
|
||||
try {
|
||||
$response = self::parse_response($response, $request['url'], $request['headers'], $request['data'], $request['options']);
|
||||
$url = $request['url'];
|
||||
$headers = $request['headers'];
|
||||
$data = $request['data'];
|
||||
$options = $request['options'];
|
||||
$response = self::parse_response($response, $url, $headers, $data, $options);
|
||||
}
|
||||
catch (Requests_Exception $e) {
|
||||
$response = $e;
|
||||
|
|
@ -634,20 +744,22 @@ class Requests {
|
|||
/**
|
||||
* Decoded a chunked body as per RFC 2616
|
||||
*
|
||||
* @see http://tools.ietf.org/html/rfc2616#section-3.6.1
|
||||
* @see https://tools.ietf.org/html/rfc2616#section-3.6.1
|
||||
* @param string $data Chunked body
|
||||
* @return string Decoded body
|
||||
*/
|
||||
protected static function decode_chunked($data) {
|
||||
if (!preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($data))) {
|
||||
if (!preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', trim($data))) {
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$decoded = '';
|
||||
$encoded = $data;
|
||||
|
||||
while (true) {
|
||||
$is_chunked = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches );
|
||||
$is_chunked = (bool) preg_match('/^([0-9a-f]+)(?:;(?:[\w-]*)(?:=(?:(?:[\w-]*)*|"(?:[^\r\n])*"))?)*\r\n/i', $encoded, $matches);
|
||||
if (!$is_chunked) {
|
||||
// Looks like it's not chunked after all
|
||||
return $data;
|
||||
|
|
@ -660,7 +772,7 @@ class Requests {
|
|||
}
|
||||
|
||||
$chunk_length = strlen($matches[0]);
|
||||
$decoded .= $part = substr($encoded, $chunk_length, $length);
|
||||
$decoded .= substr($encoded, $chunk_length, $length);
|
||||
$encoded = substr($encoded, $chunk_length + $length + 2);
|
||||
|
||||
if (trim($encoded) === '0' || empty($encoded)) {
|
||||
|
|
@ -682,7 +794,7 @@ class Requests {
|
|||
public static function flatten($array) {
|
||||
$return = array();
|
||||
foreach ($array as $key => $value) {
|
||||
$return[] = "$key: $value";
|
||||
$return[] = sprintf('%s: %s', $key, $value);
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
|
|
@ -690,6 +802,7 @@ class Requests {
|
|||
/**
|
||||
* Convert a key => value array to a 'key: value' array for headers
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @deprecated Misspelling of {@see Requests::flatten}
|
||||
* @param array $array Dictionary of header values
|
||||
* @return array List of headers
|
||||
|
|
@ -704,7 +817,6 @@ class Requests {
|
|||
* Implements gzip, compress and deflate. Guesses which it is by attempting
|
||||
* to decode.
|
||||
*
|
||||
* @todo Make this smarter by defaulting to whatever the headers say first
|
||||
* @param string $data Compressed data in one of the above formats
|
||||
* @return string Decompressed string
|
||||
*/
|
||||
|
|
@ -740,12 +852,12 @@ class Requests {
|
|||
* Warning: Magic numbers within. Due to the potential different formats that the compressed
|
||||
* data may be returned in, some "magic offsets" are needed to ensure proper decompression
|
||||
* takes place. For a simple progmatic way to determine the magic offset in use, see:
|
||||
* http://core.trac.wordpress.org/ticket/18273
|
||||
* https://core.trac.wordpress.org/ticket/18273
|
||||
*
|
||||
* @since 2.8.1
|
||||
* @link http://core.trac.wordpress.org/ticket/18273
|
||||
* @link http://au2.php.net/manual/en/function.gzinflate.php#70875
|
||||
* @link http://au2.php.net/manual/en/function.gzinflate.php#77336
|
||||
* @link https://core.trac.wordpress.org/ticket/18273
|
||||
* @link https://secure.php.net/manual/en/function.gzinflate.php#70875
|
||||
* @link https://secure.php.net/manual/en/function.gzinflate.php#77336
|
||||
*
|
||||
* @param string $gzData String to decompress.
|
||||
* @return string|bool False on failure.
|
||||
|
|
@ -753,23 +865,26 @@ class Requests {
|
|||
public static function compatible_gzinflate($gzData) {
|
||||
// Compressed data might contain a full zlib header, if so strip it for
|
||||
// gzinflate()
|
||||
if ( substr($gzData, 0, 3) == "\x1f\x8b\x08" ) {
|
||||
if (substr($gzData, 0, 3) == "\x1f\x8b\x08") {
|
||||
$i = 10;
|
||||
$flg = ord( substr($gzData, 3, 1) );
|
||||
if ( $flg > 0 ) {
|
||||
if ( $flg & 4 ) {
|
||||
list($xlen) = unpack('v', substr($gzData, $i, 2) );
|
||||
$flg = ord(substr($gzData, 3, 1));
|
||||
if ($flg > 0) {
|
||||
if ($flg & 4) {
|
||||
list($xlen) = unpack('v', substr($gzData, $i, 2));
|
||||
$i = $i + 2 + $xlen;
|
||||
}
|
||||
if ( $flg & 8 )
|
||||
if ($flg & 8) {
|
||||
$i = strpos($gzData, "\0", $i) + 1;
|
||||
if ( $flg & 16 )
|
||||
}
|
||||
if ($flg & 16) {
|
||||
$i = strpos($gzData, "\0", $i) + 1;
|
||||
if ( $flg & 2 )
|
||||
}
|
||||
if ($flg & 2) {
|
||||
$i = $i + 2;
|
||||
}
|
||||
}
|
||||
$decompressed = self::compatible_gzinflate( substr( $gzData, $i ) );
|
||||
if ( false !== $decompressed ) {
|
||||
$decompressed = self::compatible_gzinflate(substr($gzData, $i));
|
||||
if (false !== $decompressed) {
|
||||
return $decompressed;
|
||||
}
|
||||
}
|
||||
|
|
@ -780,60 +895,62 @@ class Requests {
|
|||
// java.util.zip.Deflater, Ruby’s Zlib::Deflate, and .NET's
|
||||
// System.IO.Compression.DeflateStream.
|
||||
//
|
||||
// See http://decompres.blogspot.com/ for a quick explanation of this
|
||||
// See https://decompres.blogspot.com/ for a quick explanation of this
|
||||
// data type
|
||||
$huffman_encoded = false;
|
||||
|
||||
// low nibble of first byte should be 0x08
|
||||
list( , $first_nibble ) = unpack( 'h', $gzData );
|
||||
list(, $first_nibble) = unpack('h', $gzData);
|
||||
|
||||
// First 2 bytes should be divisible by 0x1F
|
||||
list( , $first_two_bytes ) = unpack( 'n', $gzData );
|
||||
list(, $first_two_bytes) = unpack('n', $gzData);
|
||||
|
||||
if ( 0x08 == $first_nibble && 0 == ( $first_two_bytes % 0x1F ) )
|
||||
if (0x08 == $first_nibble && 0 == ($first_two_bytes % 0x1F)) {
|
||||
$huffman_encoded = true;
|
||||
|
||||
if ( $huffman_encoded ) {
|
||||
if ( false !== ( $decompressed = @gzinflate( substr( $gzData, 2 ) ) ) )
|
||||
return $decompressed;
|
||||
}
|
||||
|
||||
if ( "\x50\x4b\x03\x04" == substr( $gzData, 0, 4 ) ) {
|
||||
if ($huffman_encoded) {
|
||||
if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
|
||||
return $decompressed;
|
||||
}
|
||||
}
|
||||
|
||||
if ("\x50\x4b\x03\x04" == substr($gzData, 0, 4)) {
|
||||
// ZIP file format header
|
||||
// Offset 6: 2 bytes, General-purpose field
|
||||
// Offset 26: 2 bytes, filename length
|
||||
// Offset 28: 2 bytes, optional field length
|
||||
// Offset 30: Filename field, followed by optional field, followed
|
||||
// immediately by data
|
||||
list( , $general_purpose_flag ) = unpack( 'v', substr( $gzData, 6, 2 ) );
|
||||
list(, $general_purpose_flag) = unpack('v', substr($gzData, 6, 2));
|
||||
|
||||
// If the file has been compressed on the fly, 0x08 bit is set of
|
||||
// the general purpose field. We can use this to differentiate
|
||||
// between a compressed document, and a ZIP file
|
||||
$zip_compressed_on_the_fly = ( 0x08 == (0x08 & $general_purpose_flag ) );
|
||||
$zip_compressed_on_the_fly = (0x08 == (0x08 & $general_purpose_flag));
|
||||
|
||||
if ( ! $zip_compressed_on_the_fly ) {
|
||||
if (!$zip_compressed_on_the_fly) {
|
||||
// Don't attempt to decode a compressed zip file
|
||||
return $gzData;
|
||||
}
|
||||
|
||||
// Determine the first byte of data, based on the above ZIP header
|
||||
// offsets:
|
||||
$first_file_start = array_sum( unpack( 'v2', substr( $gzData, 26, 4 ) ) );
|
||||
if ( false !== ( $decompressed = @gzinflate( substr( $gzData, 30 + $first_file_start ) ) ) ) {
|
||||
$first_file_start = array_sum(unpack('v2', substr($gzData, 26, 4)));
|
||||
if (false !== ($decompressed = @gzinflate(substr($gzData, 30 + $first_file_start)))) {
|
||||
return $decompressed;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Finally fall back to straight gzinflate
|
||||
if ( false !== ( $decompressed = @gzinflate( $gzData ) ) ) {
|
||||
if (false !== ($decompressed = @gzinflate($gzData))) {
|
||||
return $decompressed;
|
||||
}
|
||||
|
||||
// Fallback for all above failing, not expected, but included for
|
||||
// debugging and preventing regressions and to track stats
|
||||
if ( false !== ( $decompressed = @gzinflate( substr( $gzData, 2 ) ) ) ) {
|
||||
if (false !== ($decompressed = @gzinflate(substr($gzData, 2)))) {
|
||||
return $decompressed;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue