WP_Http_Encoding

Core class used to implement deflate and gzip transfer encoding support for HTTP requests.

Defined (1)

The class is defined in the following location(s).

/bp-forums/bbpress/bb-includes/backpress/class.wp-http.php  
  1. class WP_Http_Encoding { 
  2.  
  3. /** 
  4. * Compress raw string using the deflate format. 
  5. * Supports the RFC 1951 standard. 
  6. * @since 2.8 
  7. * @param string $raw String to compress. 
  8. * @param int $level Optional, default is 9. Compression level, 9 is highest. 
  9. * @param string $supports Optional, not used. When implemented it will choose the right compression based on what the server supports. 
  10. * @return string|bool False on failure. 
  11. */ 
  12. function compress( $raw, $level = 9, $supports = null ) { 
  13. return gzdeflate( $raw, $level ); 
  14.  
  15. /** 
  16. * Decompression of deflated string. 
  17. * Will attempt to decompress using the RFC 1950 standard, and if that fails 
  18. * then the RFC 1951 standard deflate will be attempted. Finally, the RFC 
  19. * 1952 standard gzip decode will be attempted. If all fail, then the 
  20. * original compressed string will be returned. 
  21. * @since 2.8 
  22. * @param string $compressed String to decompress. 
  23. * @param int $length The optional length of the compressed data. 
  24. * @return string|bool False on failure. 
  25. */ 
  26. function decompress( $compressed, $length = null ) { 
  27. $decompressed = gzinflate( $compressed ); 
  28.  
  29. if ( false !== $decompressed ) 
  30. return $decompressed; 
  31.  
  32. $decompressed = gzuncompress( $compressed ); 
  33.  
  34. if ( false !== $decompressed ) 
  35. return $decompressed; 
  36.  
  37. if ( function_exists('gzdecode') ) { 
  38. $decompressed = gzdecode( $compressed ); 
  39.  
  40. if ( false !== $decompressed ) 
  41. return $decompressed; 
  42.  
  43. return $compressed; 
  44.  
  45. /** 
  46. * What encoding types to accept and their priority values. 
  47. * @since 2.8 
  48. * @return string Types of encoding to accept. 
  49. */ 
  50. function accept_encoding() { 
  51. $type = array(); 
  52. if ( function_exists( 'gzinflate' ) ) 
  53. $type[] = 'deflate;q=1.0'; 
  54.  
  55. if ( function_exists( 'gzuncompress' ) ) 
  56. $type[] = 'compress;q=0.5'; 
  57.  
  58. if ( function_exists( 'gzdecode' ) ) 
  59. $type[] = 'gzip;q=0.5'; 
  60.  
  61. return implode(', ', $type); 
  62.  
  63. /** 
  64. * What enconding the content used when it was compressed to send in the headers. 
  65. * @since 2.8 
  66. * @return string Content-Encoding string to send in the header. 
  67. */ 
  68. function content_encoding() { 
  69. return 'deflate'; 
  70.  
  71. /** 
  72. * Whether the content be decoded based on the headers. 
  73. * @since 2.8 
  74. * @param array|string $headers All of the available headers. 
  75. * @return bool 
  76. */ 
  77. function should_decode($headers) { 
  78. if ( is_array( $headers ) ) { 
  79. if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) ) 
  80. return true; 
  81. } else if( is_string( $headers ) ) { 
  82. return ( stripos($headers, 'content-encoding:') !== false ); 
  83.  
  84. return false; 
  85.  
  86. /** 
  87. * Whether decompression and compression are supported by the PHP version. 
  88. * Each function is tested instead of checking for the zlib extension, to 
  89. * ensure that the functions all exist in the PHP version and aren't 
  90. * disabled. 
  91. * @since 2.8 
  92. * @return bool 
  93. */ 
  94. function is_available() { 
  95. return ( function_exists('gzuncompress') || function_exists('gzdeflate') || function_exists('gzinflate') );