home/wwgoat/public_html/blog/wp-includes/class-wp-http-encoding.php 0000644 00000015041 14720636577 0021510 0 ustar 00 0 ) {
if ( $flg & 4 ) {
list($xlen) = unpack( 'v', substr( $gz_data, $i, 2 ) );
$i = $i + 2 + $xlen;
}
if ( $flg & 8 ) {
$i = strpos( $gz_data, "\0", $i ) + 1;
}
if ( $flg & 16 ) {
$i = strpos( $gz_data, "\0", $i ) + 1;
}
if ( $flg & 2 ) {
$i = $i + 2;
}
}
$decompressed = @gzinflate( substr( $gz_data, $i, -8 ) );
if ( false !== $decompressed ) {
return $decompressed;
}
}
// Compressed data from java.util.zip.Deflater amongst others.
$decompressed = @gzinflate( substr( $gz_data, 2 ) );
if ( false !== $decompressed ) {
return $decompressed;
}
return false;
}
/**
* What encoding types to accept and their priority values.
*
* @since 2.8.0
*
* @param string $url
* @param array $args
* @return string Types of encoding to accept.
*/
public static function accept_encoding( $url, $args ) {
$type = array();
$compression_enabled = self::is_available();
if ( ! $args['decompress'] ) { // Decompression specifically disabled.
$compression_enabled = false;
} elseif ( $args['stream'] ) { // Disable when streaming to file.
$compression_enabled = false;
} elseif ( isset( $args['limit_response_size'] ) ) { // If only partial content is being requested, we won't be able to decompress it.
$compression_enabled = false;
}
if ( $compression_enabled ) {
if ( function_exists( 'gzinflate' ) ) {
$type[] = 'deflate;q=1.0';
}
if ( function_exists( 'gzuncompress' ) ) {
$type[] = 'compress;q=0.5';
}
if ( function_exists( 'gzdecode' ) ) {
$type[] = 'gzip;q=0.5';
}
}
/**
* Filters the allowed encoding types.
*
* @since 3.6.0
*
* @param string[] $type Array of what encoding types to accept and their priority values.
* @param string $url URL of the HTTP request.
* @param array $args HTTP request arguments.
*/
$type = apply_filters( 'wp_http_accept_encoding', $type, $url, $args );
return implode( ', ', $type );
}
/**
* What encoding the content used when it was compressed to send in the headers.
*
* @since 2.8.0
*
* @return string Content-Encoding string to send in the header.
*/
public static function content_encoding() {
return 'deflate';
}
/**
* Whether the content be decoded based on the headers.
*
* @since 2.8.0
*
* @param array|string $headers All of the available headers.
* @return bool
*/
public static function should_decode( $headers ) {
if ( is_array( $headers ) ) {
if ( array_key_exists( 'content-encoding', $headers ) && ! empty( $headers['content-encoding'] ) ) {
return true;
}
} elseif ( is_string( $headers ) ) {
return ( stripos( $headers, 'content-encoding:' ) !== false );
}
return false;
}
/**
* Whether decompression and compression are supported by the PHP version.
*
* Each function is tested instead of checking for the zlib extension, to
* ensure that the functions all exist in the PHP version and aren't
* disabled.
*
* @since 2.8.0
*
* @return bool
*/
public static function is_available() {
return ( function_exists( 'gzuncompress' ) || function_exists( 'gzdeflate' ) || function_exists( 'gzinflate' ) );
}
}