Changeset 42343 for trunk/src/wp-includes/class-wp-http-encoding.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-http-encoding.php
r37674 r42343 53 53 public static function decompress( $compressed, $length = null ) { 54 54 55 if ( empty( $compressed) )55 if ( empty( $compressed ) ) { 56 56 return $compressed; 57 58 if ( false !== ( $decompressed = @gzinflate( $compressed ) ) ) 59 return $decompressed; 60 61 if ( false !== ( $decompressed = self::compatible_gzinflate( $compressed ) ) ) 62 return $decompressed; 63 64 if ( false !== ( $decompressed = @gzuncompress( $compressed ) ) ) 65 return $decompressed; 66 67 if ( function_exists('gzdecode') ) { 57 } 58 59 if ( false !== ( $decompressed = @gzinflate( $compressed ) ) ) { 60 return $decompressed; 61 } 62 63 if ( false !== ( $decompressed = self::compatible_gzinflate( $compressed ) ) ) { 64 return $decompressed; 65 } 66 67 if ( false !== ( $decompressed = @gzuncompress( $compressed ) ) ) { 68 return $decompressed; 69 } 70 71 if ( function_exists( 'gzdecode' ) ) { 68 72 $decompressed = @gzdecode( $compressed ); 69 73 70 if ( false !== $decompressed ) 74 if ( false !== $decompressed ) { 71 75 return $decompressed; 76 } 72 77 } 73 78 … … 97 102 * @return string|bool False on failure. 98 103 */ 99 public static function compatible_gzinflate( $gzData) {104 public static function compatible_gzinflate( $gzData ) { 100 105 101 106 // Compressed data might contain a full header, if so strip it for gzinflate(). 102 if ( substr( $gzData, 0, 3) == "\x1f\x8b\x08" ) {103 $i = 10;104 $flg = ord( substr( $gzData, 3, 1) );107 if ( substr( $gzData, 0, 3 ) == "\x1f\x8b\x08" ) { 108 $i = 10; 109 $flg = ord( substr( $gzData, 3, 1 ) ); 105 110 if ( $flg > 0 ) { 106 111 if ( $flg & 4 ) { 107 list($xlen) = unpack('v', substr($gzData, $i, 2) ); 108 $i = $i + 2 + $xlen; 109 } 110 if ( $flg & 8 ) 111 $i = strpos($gzData, "\0", $i) + 1; 112 if ( $flg & 16 ) 113 $i = strpos($gzData, "\0", $i) + 1; 114 if ( $flg & 2 ) 112 list($xlen) = unpack( 'v', substr( $gzData, $i, 2 ) ); 113 $i = $i + 2 + $xlen; 114 } 115 if ( $flg & 8 ) { 116 $i = strpos( $gzData, "\0", $i ) + 1; 117 } 118 if ( $flg & 16 ) { 119 $i = strpos( $gzData, "\0", $i ) + 1; 120 } 121 if ( $flg & 2 ) { 115 122 $i = $i + 2; 116 } 117 $decompressed = @gzinflate( substr($gzData, $i, -8) ); 118 if ( false !== $decompressed ) 123 } 124 } 125 $decompressed = @gzinflate( substr( $gzData, $i, -8 ) ); 126 if ( false !== $decompressed ) { 119 127 return $decompressed; 128 } 120 129 } 121 130 122 131 // Compressed data from java.util.zip.Deflater amongst others. 123 $decompressed = @gzinflate( substr($gzData, 2) ); 124 if ( false !== $decompressed ) 125 return $decompressed; 132 $decompressed = @gzinflate( substr( $gzData, 2 ) ); 133 if ( false !== $decompressed ) { 134 return $decompressed; 135 } 126 136 127 137 return false; … … 140 150 */ 141 151 public static function accept_encoding( $url, $args ) { 142 $type = array();152 $type = array(); 143 153 $compression_enabled = self::is_available(); 144 154 145 if ( ! $args['decompress'] ) // Decompression specifically disabled.155 if ( ! $args['decompress'] ) { // Decompression specifically disabled. 146 156 $compression_enabled = false; 147 elseif ( $args['stream'] )// Disable when streaming to file.157 } elseif ( $args['stream'] ) { // Disable when streaming to file. 148 158 $compression_enabled = false; 149 elseif ( isset( $args['limit_response_size'] ) )// If only partial content is being requested, we won't be able to decompress it.159 } elseif ( isset( $args['limit_response_size'] ) ) { // If only partial content is being requested, we won't be able to decompress it. 150 160 $compression_enabled = false; 161 } 151 162 152 163 if ( $compression_enabled ) { 153 if ( function_exists( 'gzinflate' ) ) 164 if ( function_exists( 'gzinflate' ) ) { 154 165 $type[] = 'deflate;q=1.0'; 155 156 if ( function_exists( 'gzuncompress' ) ) 166 } 167 168 if ( function_exists( 'gzuncompress' ) ) { 157 169 $type[] = 'compress;q=0.5'; 158 159 if ( function_exists( 'gzdecode' ) ) 170 } 171 172 if ( function_exists( 'gzdecode' ) ) { 160 173 $type[] = 'gzip;q=0.5'; 174 } 161 175 } 162 176 … … 173 187 $type = apply_filters( 'wp_http_accept_encoding', $type, $url, $args ); 174 188 175 return implode( ', ', $type);189 return implode( ', ', $type ); 176 190 } 177 191 … … 199 213 * @return bool 200 214 */ 201 public static function should_decode( $headers) {215 public static function should_decode( $headers ) { 202 216 if ( is_array( $headers ) ) { 203 if ( array_key_exists( 'content-encoding', $headers) && ! empty( $headers['content-encoding'] ) )217 if ( array_key_exists( 'content-encoding', $headers ) && ! empty( $headers['content-encoding'] ) ) { 204 218 return true; 219 } 205 220 } elseif ( is_string( $headers ) ) { 206 return ( stripos( $headers, 'content-encoding:') !== false );221 return ( stripos( $headers, 'content-encoding:' ) !== false ); 207 222 } 208 223 … … 224 239 */ 225 240 public static function is_available() { 226 return ( function_exists( 'gzuncompress') || function_exists('gzdeflate') || function_exists('gzinflate') );241 return ( function_exists( 'gzuncompress' ) || function_exists( 'gzdeflate' ) || function_exists( 'gzinflate' ) ); 227 242 } 228 243 }
Note: See TracChangeset
for help on using the changeset viewer.