WP_HTTP: Do not send a Accept-Encoding header when we're streaming to file, or decompression has been disabled by the caller, See #22913

git-svn-id: http://core.svn.wordpress.org/trunk@23601 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dion Hulse 2013-03-04 03:33:12 +00:00
parent 78e4b5afde
commit 2c70f1591b

View File

@ -166,8 +166,10 @@ class WP_Http {
// Construct Cookie: header if any cookies are set // Construct Cookie: header if any cookies are set
WP_Http::buildCookieHeader( $r ); WP_Http::buildCookieHeader( $r );
if ( ! isset( $r['headers']['Accept-Encoding'] ) && WP_Http_Encoding::is_available() ) if ( ! isset( $r['headers']['Accept-Encoding'] ) ) {
$r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding(); if ( $encoding = WP_Http_Encoding::accept_encoding( $url, $r ) )
$r['headers']['Accept-Encoding'] = $encoding;
}
if ( ( ! is_null( $r['body'] ) && '' != $r['body'] ) || 'POST' == $r['method'] || 'PUT' == $r['method'] ) { if ( ( ! is_null( $r['body'] ) && '' != $r['body'] ) || 'POST' == $r['method'] || 'PUT' == $r['method'] ) {
if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) { if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
@ -1730,8 +1732,16 @@ class WP_Http_Encoding {
* *
* @return string Types of encoding to accept. * @return string Types of encoding to accept.
*/ */
public static function accept_encoding() { public static function accept_encoding( $url, $args ) {
$type = array(); $type = array();
$compression_enabled = WP_Http_Encoding::is_available();
if ( ! $args['decompress'] ) // decompression specifically disabled
$compression_enabled = false;
elseif ( $args['stream'] ) // disable when streaming to file
$compression_enabled = false;
if ( $compression_enabled ) {
if ( function_exists( 'gzinflate' ) ) if ( function_exists( 'gzinflate' ) )
$type[] = 'deflate;q=1.0'; $type[] = 'deflate;q=1.0';
@ -1740,6 +1750,9 @@ class WP_Http_Encoding {
if ( function_exists( 'gzdecode' ) ) if ( function_exists( 'gzdecode' ) )
$type[] = 'gzip;q=0.5'; $type[] = 'gzip;q=0.5';
}
$type = apply_filters( 'wp_http_accept_encoding', $type, $url, $args );
return implode(', ', $type); return implode(', ', $type);
} }