Index: src/wp-includes/class-http.php
===================================================================
--- src/wp-includes/class-http.php	(revision 30384)
+++ src/wp-includes/class-http.php	(working copy)
@@ -2092,33 +2092,30 @@
 	 * then the RFC 1951 standard deflate will be attempted. Finally, the RFC
 	 * 1952 standard gzip decode will be attempted. If all fail, then the
 	 * original compressed string will be returned.
 	 *
 	 * @since 2.8.0
 	 *
 	 * @param string $compressed String to decompress.
 	 * @param int $length The optional length of the compressed data.
 	 * @return string|bool False on failure.
 	 */
 	public static function decompress( $compressed, $length = null ) {
 
 		if ( empty($compressed) )
 			return $compressed;
 
-		if ( false !== ( $decompressed = @gzinflate( $compressed ) ) )
-			return $decompressed;
-
 		if ( false !== ( $decompressed = WP_Http_Encoding::compatible_gzinflate( $compressed ) ) )
 			return $decompressed;
 
 		if ( false !== ( $decompressed = @gzuncompress( $compressed ) ) )
 			return $decompressed;
 
 		if ( function_exists('gzdecode') ) {
 			$decompressed = @gzdecode( $compressed );
 
 			if ( false !== $decompressed )
 				return $decompressed;
 		}
 
 		return $compressed;
 	}
@@ -2149,39 +2146,86 @@
 		if ( substr($gzData, 0, 3) == "\x1f\x8b\x08" ) {
 			$i = 10;
 			$flg = ord( substr($gzData, 3, 1) );
 			if ( $flg > 0 ) {
 				if ( $flg & 4 ) {
 					list($xlen) = unpack('v', substr($gzData, $i, 2) );
 					$i = $i + 2 + $xlen;
 				}
 				if ( $flg & 8 )
 					$i = strpos($gzData, "\0", $i) + 1;
 				if ( $flg & 16 )
 					$i = strpos($gzData, "\0", $i) + 1;
 				if ( $flg & 2 )
 					$i = $i + 2;
 			}
-			$decompressed = @gzinflate( substr($gzData, $i, -8) );
-			if ( false !== $decompressed )
+
+			$decompressed = WP_Http_Encoding::compatible_gzinflate( substr( $gzData, $i ) );
+			if ( false !== $decompressed ) {
 				return $decompressed;
+			}
 		}
 
-		// Compressed data from java.util.zip.Deflater amongst others.
-		$decompressed = @gzinflate( substr($gzData, 2) );
-		if ( false !== $decompressed )
+		// If the data is Huffman Encoded, we must first strip the leading 2 byte Huffman marker for gzinflate()
+		// The Response is Huffman coded by many compressors such as java.util.zip.Deflater,
+		// Ruby’s Zlib::Deflate, and .NET's System.IO.Compression.DeflateStream.
+		// See http://decompres.blogspot.com/ for a quick explanation of this data type
+		$huffman_encoded = false;
+		list( , $first_nibble ) = unpack( 'h', $gzData ); // low nibble of first byte should be 0x08
+		list( , $first_two_bytes ) = unpack( 'n', $gzData ); // First 2 bytes should be divisible by 0x1F
+		if ( 0x08 == $first_nibble && 0 == ( $first_two_bytes % 0x1F ) )
+			$huffman_encoded = true;
+
+		if ( $huffman_encoded ) {
+			if ( false !== ( $decompressed = @gzinflate( substr( $gzData, 2 ) ) ) )
+				return $decompressed;
+		}
+
+		if ( "\x50\x4b\x03\x04" == substr( $gzData, 0, 4 ) ) {
+			// ZIP file format header
+			// Offset  6: 2 bytes, General-purpose field
+			// Offset 26: 2 bytes, filename length
+			// Offset 28: 2 bytes, optional field length
+			// Offset 30: Filename field, followed by optional field, followed immediately by data
+			list( , $general_purpose_flag ) = unpack( 'v', substr( $gzData, 6, 2 ) );
+
+			// If the file has been compressed on the fly, 0x08 bit is set of the general purpose field
+			// We can use this to differentiate between a compressed document, and a ZIP file
+			$zip_compressed_on_the_fly = ( 0x08 == (0x08 & $general_purpose_flag ) );
+
+			if ( ! $zip_compressed_on_the_fly ) {
+				return $gzData; // Don't attempt to decode a compressed zip file from the server
+			}
+
+			// Determine the first byte of data, based on the above ZIP header offsets:
+			$first_file_start = array_sum( unpack( 'v2', substr( $gzData, 26, 4 ) ) );
+			if ( false !== ( $decompressed = @gzinflate( substr( $gzData, 30 + $first_file_start ) ) ) ) {
+				return $decompressed;
+			}
+
+			return false;
+		}
+
+		// Finally fall back to straight gzinflate
+		if ( false !== ( $decompressed = @gzinflate( $gzData ) ) ) {
 			return $decompressed;
+		}
+
+		// Fallback for all above failing, not expected, but included for debugging and preventing regressions
+		if ( false !== ( $decompressed = @gzinflate( substr( $gzData, 2 ) ) ) ) {
+			return $decompressed;
+		}
 
 		return false;
 	}
 
 	/**
 	 * What encoding types to accept and their priority values.
 	 *
 	 * @since 2.8.0
 	 *
 	 * @return string Types of encoding to accept.
 	 */
 	public static function accept_encoding( $url, $args ) {
 		$type = array();
 		$compression_enabled = WP_Http_Encoding::is_available();
 
