WordPress.org

Make WordPress Core

Changeset 8533


Ignore:
Timestamp:
08/04/2008 04:28:12 PM (10 years ago)
Author:
ryan
Message:

Cycle through available transports trying each one. Props jacobsantos. see #4779

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/http.php

    r8528 r8533  
    8989
    9090        if ( is_null($working_transport) ) {
    91             if ( true === WP_Http_ExtHttp::test() )
    92                 $working_transport = new WP_Http_ExtHttp();
    93             else if ( true === WP_Http_Curl::test() )
    94                 $working_transport = new WP_Http_Curl();
    95             else if ( true === WP_Http_Streams::test() )
    96                 $working_transport = new WP_Http_Streams();
    97             else if ( true === WP_Http_Fopen::test() )
    98                 $working_transport = new WP_Http_Fopen();
    99             else if ( true === WP_Http_Fsockopen::test() )
    100                 $working_transport = new WP_Http_Fsockopen();
     91            if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) )
     92                $working_transport[] = new WP_Http_ExtHttp();
     93            else if ( true === WP_Http_Curl::test() && apply_filters('use_curl_transport', true) )
     94                $working_transport[] = new WP_Http_Curl();
     95            else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) )
     96                $working_transport[] = new WP_Http_Streams();
     97            else if ( true === WP_Http_Fopen::test() && apply_filters('use_fopen_transport', true) )
     98                $working_transport[] = new WP_Http_Fopen();
     99            else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) )
     100                $working_transport[] = new WP_Http_Fsockopen();
    101101        }
    102102
     
    122122
    123123        if ( is_null($working_transport) ) {
    124             if ( true === WP_Http_ExtHttp::test() )
    125                 $working_transport = new WP_Http_ExtHttp();
    126             else if ( true === WP_Http_Streams::test() )
    127                 $working_transport = new WP_Http_Streams();
    128             else if ( true === WP_Http_Fsockopen::test() )
    129                 $working_transport = new WP_Http_Fsockopen();
     124            if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) )
     125                $working_transport[] = new WP_Http_ExtHttp();
     126            else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) )
     127                $working_transport[] = new WP_Http_Streams();
     128            else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) )
     129                $working_transport[] = new WP_Http_Fsockopen();
    130130        }
    131131
     
    171171     * @param str|array $args Optional. Override the defaults.
    172172     * @param string|array $headers Optional. Either the header string or array of Header name and value pairs. Expects sanitized.
    173      * @param string $body Optional. The body that should be sent. Expected to be already processed.
     173     * @param string $body Optional. The body that should be sent. Will be automatically escaped and processed.
    174174     * @return boolean
    175175     */
     
    178178
    179179        $defaults = array(
    180             'method' => 'GET', 'timeout' => 3,
     180            'method' => 'GET', 'timeout' => apply_filters('http_request_timeout', 3),
    181181            'redirection' => 5, 'httpversion' => '1.0',
    182182            'user-agent' => apply_filters('http_headers_useragent', 'WordPress/' . $wp_version ),
     
    196196            $headers['user-agent'] = $r['user-agent'];
    197197
    198         if ( is_null($body) )
    199             $transport = WP_Http::_getTransport();
    200         else
    201             $transport = WP_Http::_postTransport();
    202 
    203         return $transport->request($url, $r, $headers, $body);
     198        if ( is_null($body) ) {
     199            if ( ! is_string($body) )
     200                $body = http_build_query($body);
     201
     202            $transports = WP_Http::_getTransport();
     203        } else
     204            $transports = WP_Http::_postTransport();
     205
     206        $response = array( 'headers' => array(), 'body' => '', 'response' => array('code', 'message') );
     207        foreach( (array) $transports as $transport ) {
     208            $response = $transport->request($url, $r, $headers, $body);
     209
     210            if( !is_wp_error($response) )
     211                break;
     212        }
     213
     214        return $response;
    204215    }
    205216
     
    415426            $error_reporting = error_reporting(0);
    416427
    417         $handle = fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, apply_filters('http_request_timeout', absint($r['timeout']) ) );
     428        $handle = fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] );
    418429
    419430        if ( false === $handle )
     
    539550
    540551        if ( function_exists('stream_set_timeout') )
    541             stream_set_timeout($handle, apply_filters('http_request_timeout', $r['timeout']) );
     552            stream_set_timeout($handle, $r['timeout'] );
    542553
    543554        if ( ! $r['blocking'] ) {
     
    613624        $r = wp_parse_args( $args, $defaults );
    614625
     626        if ( isset($headers['User-Agent']) ) {
     627            $r['user-agent'] = $headers['User-Agent'];
     628            unset($headers['User-Agent']);
     629        } else if( isset($headers['user-agent']) ) {
     630            $r['user-agent'] = $headers['user-agent'];
     631            unset($headers['user-agent']);
     632        } else {
     633            $r['user-agent'] = apply_filters('http_headers_useragent', 'WordPress/' . $wp_version );
     634        }
     635
    615636        $arrURL = parse_url($url);
    616637
     
    621642            array(
    622643                'method' => strtoupper($r['method']),
    623                 'user-agent' => $headers['User-Agent'],
     644                'user-agent' => $r['user-agent'],
    624645                'max_redirects' => $r['redirection'],
    625646                'protocol_version' => (float) $r['httpversion'],
     
    629650        );
    630651
     652        var_dump($arrContext);
    631653        if ( ! is_null($body) )
    632654            $arrContext['http']['content'] = $body;
     
    639661            return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
    640662
    641         stream_set_timeout($handle, apply_filters('http_request_stream_timeout', $r['timeout']) );
     663        stream_set_timeout($handle, $r['timeout'] );
    642664
    643665        if ( ! $r['blocking'] ) {
Note: See TracChangeset for help on using the changeset viewer.