From 2c70f1591b22241c74352af6417902cac437a394 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Mon, 4 Mar 2013 03:33:12 +0000 Subject: [PATCH] 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 --- wp-includes/class-http.php | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index 7f838a6c8b..2cf4a73b3f 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -166,8 +166,10 @@ class WP_Http { // Construct Cookie: header if any cookies are set WP_Http::buildCookieHeader( $r ); - if ( ! isset( $r['headers']['Accept-Encoding'] ) && WP_Http_Encoding::is_available() ) - $r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding(); + if ( ! isset( $r['headers']['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_array( $r['body'] ) || is_object( $r['body'] ) ) { @@ -1730,16 +1732,27 @@ class WP_Http_Encoding { * * @return string Types of encoding to accept. */ - public static function accept_encoding() { + public static function accept_encoding( $url, $args ) { $type = array(); - if ( function_exists( 'gzinflate' ) ) - $type[] = 'deflate;q=1.0'; + $compression_enabled = WP_Http_Encoding::is_available(); - if ( function_exists( 'gzuncompress' ) ) - $type[] = 'compress;q=0.5'; + if ( ! $args['decompress'] ) // decompression specifically disabled + $compression_enabled = false; + elseif ( $args['stream'] ) // disable when streaming to file + $compression_enabled = false; - if ( function_exists( 'gzdecode' ) ) - $type[] = 'gzip;q=0.5'; + 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'; + } + + $type = apply_filters( 'wp_http_accept_encoding', $type, $url, $args ); return implode(', ', $type); }