]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-http.php
Wordpress 3.3.1
[autoinstalls/wordpress.git] / wp-includes / class-http.php
index 1cf44041b9c9198121c6ae31019fb788d5275300..a68711c8cd95fa1f8a4b96482c45d9fcf6716eaa 100644 (file)
@@ -180,7 +180,8 @@ class WP_Http {
                } else {
                        if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
                                $r['body'] = http_build_query( $r['body'], null, '&' );
-                               $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' );
+                               if ( ! isset( $r['headers']['Content-Type'] ) )
+                                       $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' );
                                $r['headers']['Content-Length'] = strlen( $r['body'] );
                        }
 
@@ -222,7 +223,7 @@ class WP_Http {
        /**
         * Dispatches a HTTP request to a supporting transport.
         *
-        * Tests each transport in order to find a transport which matches the request arguements.
+        * Tests each transport in order to find a transport which matches the request arguments.
         * Also caches the transport instance to be used later.
         *
         * The order for blocking requests is cURL, Streams, and finally Fsockopen.
@@ -253,7 +254,7 @@ class WP_Http {
 
                $response = $transports[$class]->request( $url, $args );
 
-               do_action( 'http_api_debug', $response, 'response', $class );
+               do_action( 'http_api_debug', $response, 'response', $class, $args, $url );
 
                if ( is_wp_error( $response ) )
                        return $response;
@@ -345,7 +346,7 @@ class WP_Http {
         * @return array Processed string headers. If duplicate headers are encountered,
         *                                      Then a numbered array is returned as the value of that header-key.
         */
-       function processHeaders($headers) {
+       public static function processHeaders($headers) {
                // split headers, one per array element
                if ( is_string($headers) ) {
                        // tolerate line terminator: CRLF = LF (RFC 2616 19.3)
@@ -412,7 +413,7 @@ class WP_Http {
         *
         * @param array $r Full array of args passed into ::request()
         */
-       function buildCookieHeader( &$r ) {
+       public static function buildCookieHeader( &$r ) {
                if ( ! empty($r['cookies']) ) {
                        $cookies_header = '';
                        foreach ( (array) $r['cookies'] as $cookie ) {
@@ -631,7 +632,7 @@ class WP_Http_Fsockopen {
 
                $endDelay = time();
 
-               // If the delay is greater than the timeout then fsockopen should't be used, because it will
+               // If the delay is greater than the timeout then fsockopen shouldn't be used, because it will
                // cause a long delay.
                $elapseDelay = ($endDelay-$startDelay) > $r['timeout'];
                if ( true === $elapseDelay )
@@ -755,7 +756,7 @@ class WP_Http_Fsockopen {
         * @static
         * @return boolean False means this class can not be used, true means it can.
         */
-       function test( $args = array() ) {
+       public static function test( $args = array() ) {
                if ( ! function_exists( 'fsockopen' ) )
                        return false;
 
@@ -915,7 +916,7 @@ class WP_Http_Streams {
                else
                        $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']);
 
-               // Streams does not provide an error code which we can use to see why the request stream stoped.
+               // Streams does not provide an error code which we can use to see why the request stream stopped.
                // We can however test to see if a location header is present and return based on that.
                if ( isset($processedHeaders['headers']['location']) && 0 !== $args['_redirection'] )
                        return new WP_Error('http_request_failed', __('Too many redirects.'));
@@ -938,7 +939,7 @@ class WP_Http_Streams {
         *
         * @return boolean False means this class can not be used, true means it can.
         */
-       function test( $args = array() ) {
+       public static function test( $args = array() ) {
                if ( ! function_exists( 'fopen' ) )
                        return false;
 
@@ -1031,7 +1032,7 @@ class WP_Http_Curl {
 
 
                // CURLOPT_TIMEOUT and CURLOPT_CONNECTTIMEOUT expect integers.  Have to use ceil since
-               // a value of 0 will allow an ulimited timeout.
+               // a value of 0 will allow an unlimited timeout.
                $timeout = (int) ceil( $r['timeout'] );
                curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $timeout );
                curl_setopt( $handle, CURLOPT_TIMEOUT, $timeout );
@@ -1117,7 +1118,7 @@ class WP_Http_Curl {
                                return new WP_Error('http_request_failed', __('Too many redirects.'));
                }
 
-               unset( $this->headers );
+               $this->headers = '';
 
                $response = array();
                $response['code'] = curl_getinfo( $handle, CURLINFO_HTTP_CODE );
@@ -1165,7 +1166,7 @@ class WP_Http_Curl {
         *
         * @return boolean False means this class can not be used, true means it can.
         */
-       function test( $args = array() ) {
+       public static function test( $args = array() ) {
                if ( ! function_exists( 'curl_init' ) || ! function_exists( 'curl_exec' ) )
                        return false;
 
@@ -1579,7 +1580,7 @@ class WP_Http_Encoding {
         * @param string $supports Optional, not used. When implemented it will choose the right compression based on what the server supports.
         * @return string|bool False on failure.
         */
-       function compress( $raw, $level = 9, $supports = null ) {
+       public static function compress( $raw, $level = 9, $supports = null ) {
                return gzdeflate( $raw, $level );
        }
 
@@ -1597,7 +1598,7 @@ class WP_Http_Encoding {
         * @param int $length The optional length of the compressed data.
         * @return string|bool False on failure.
         */
-       function decompress( $compressed, $length = null ) {
+       public static function decompress( $compressed, $length = null ) {
 
                if ( empty($compressed) )
                        return $compressed;
@@ -1625,17 +1626,25 @@ class WP_Http_Encoding {
         * Decompression of deflated string while staying compatible with the majority of servers.
         *
         * Certain Servers will return deflated data with headers which PHP's gziniflate()
-        * function cannot handle out of the box. The following function lifted from
-        * http://au2.php.net/manual/en/function.gzinflate.php#77336 will attempt to deflate
-        * the various return forms used.
+        * function cannot handle out of the box. The following function has been created from
+        * various snippets on the gzinflate() PHP documentation.
+        *
+        * Warning: Magic numbers within. Due to the potential different formats that the compressed
+        * data may be returned in, some "magic offsets" are needed to ensure proper decompression
+        * takes place. For a simple progmatic way to determine the magic offset in use, see:
+        * http://core.trac.wordpress.org/ticket/18273
         *
         * @since 2.8.1
+        * @link http://core.trac.wordpress.org/ticket/18273
+        * @link http://au2.php.net/manual/en/function.gzinflate.php#70875
         * @link http://au2.php.net/manual/en/function.gzinflate.php#77336
         *
         * @param string $gzData String to decompress.
         * @return string|bool False on failure.
         */
-       function compatible_gzinflate($gzData) {
+       public static function compatible_gzinflate($gzData) {
+
+               // Compressed data might contain a full header, if so strip it for gzinflate()
                if ( substr($gzData, 0, 3) == "\x1f\x8b\x08" ) {
                        $i = 10;
                        $flg = ord( substr($gzData, 3, 1) );
@@ -1651,10 +1660,17 @@ class WP_Http_Encoding {
                                if ( $flg & 2 )
                                        $i = $i + 2;
                        }
-                       return gzinflate( substr($gzData, $i, -8) );
-               } else {
-                       return false;
+                       $decompressed = @gzinflate( substr($gzData, $i, -8) );
+                       if ( false !== $decompressed )
+                               return $decompressed;
                }
+
+               // Compressed data from java.util.zip.Deflater amongst others.
+               $decompressed = @gzinflate( substr($gzData, 2) );
+               if ( false !== $decompressed )
+                       return $decompressed;
+
+               return false;
        }
 
        /**
@@ -1664,7 +1680,7 @@ class WP_Http_Encoding {
         *
         * @return string Types of encoding to accept.
         */
-       function accept_encoding() {
+       public static function accept_encoding() {
                $type = array();
                if ( function_exists( 'gzinflate' ) )
                        $type[] = 'deflate;q=1.0';
@@ -1679,13 +1695,13 @@ class WP_Http_Encoding {
        }
 
        /**
-        * What enconding the content used when it was compressed to send in the headers.
+        * What encoding the content used when it was compressed to send in the headers.
         *
         * @since 2.8
         *
         * @return string Content-Encoding string to send in the header.
         */
-       function content_encoding() {
+       public static function content_encoding() {
                return 'deflate';
        }
 
@@ -1697,7 +1713,7 @@ class WP_Http_Encoding {
         * @param array|string $headers All of the available headers.
         * @return bool
         */
-       function should_decode($headers) {
+       public static function should_decode($headers) {
                if ( is_array( $headers ) ) {
                        if ( array_key_exists('content-encoding', $headers) && ! empty( $headers['content-encoding'] ) )
                                return true;
@@ -1719,7 +1735,7 @@ class WP_Http_Encoding {
         *
         * @return bool
         */
-       function is_available() {
+       public static function is_available() {
                return ( function_exists('gzuncompress') || function_exists('gzdeflate') || function_exists('gzinflate') );
        }
 }