WordPress.org

Make WordPress Core

Ticket #8702: 8702.diff

File 8702.diff, 5.0 KB (added by sivel, 9 years ago)
  • wp-includes/http.php

     
    6969         * Tests all of the objects and returns the object that passes. Also caches
    7070         * that object to be used later.
    7171         *
    72          * The order for the GET/HEAD requests are Streams, HTTP Extension, Fopen,
    73          * and finally Fsockopen. fsockopen() is used last, because it has the most
    74          * overhead in its implementation. There isn't any real way around it, since
    75          * redirects have to be supported, much the same way the other transports
    76          * also handle redirects.
     72         * The order for the GET/HEAD requests are HTTP Extension, cURL, Streams,
     73         * Fopen, and finally Fsockopen. fsockopen() is used last, because it has
     74         * the most overhead in its implementation. There isn't any real way around
     75         * it, since redirects have to be supported, much the same way the other
     76         * transports also handle redirects.
    7777         *
    7878         * There are currently issues with "localhost" not resolving correctly with
    7979         * DNS. This may cause an error "failed to open stream: A connection attempt
     
    129129         * to send content, but the streams transport can. This is a limitation that
    130130         * is addressed here, by just not including that transport.
    131131         *
     132         * The order for the POST requests are HTTP Extension, cURL, Streams and
     133         * finally Fsockopen. fsockopen() is used last, because it has the most
     134         * overhead in its implementation. There isn't any real way around it,
     135         * since redirects have to be supported, much the same way the other
     136         * transports also handle redirects.
     137         *
    132138         * @since 2.7
    133139         * @access private
    134140         *
     
    142148                        if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) ) {
    143149                                $working_transport['exthttp'] = new WP_Http_ExtHttp();
    144150                                $blocking_transport[] = &$working_transport['exthttp'];
     151                        } else if ( true === WP_Http_Curl::test() && apply_filters('use_curl_transport', true) ) {
     152                                $working_transport['curl'] = new WP_Http_Curl();
     153                                $blocking_transport[] = &$working_transport['curl'];
    145154                        } else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) ) {
    146155                                $working_transport['streams'] = new WP_Http_Streams();
    147156                                $blocking_transport[] = &$working_transport['streams'];
     
    215224                        'timeout' => apply_filters( 'http_request_timeout', 5),
    216225                        'redirection' => apply_filters( 'http_request_redirection_count', 5),
    217226                        'httpversion' => apply_filters( 'http_request_version', '1.0'),
    218                         'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version ),
     227                        'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ),
    219228                        'blocking' => true,
    220229                        'headers' => array(), 'body' => null
    221230                );
     
    769778                                'max_redirects' => $r['redirection'],
    770779                                'protocol_version' => (float) $r['httpversion'],
    771780                                'header' => $strHeaders,
    772                                 'timeout' => $r['timeout']
     781                                'timeout' => $r['timeout'],
     782                                'verify_peer' => false
    773783                        )
    774784                );
    775785
     
    899909                        'redirect' => $r['redirection'],
    900910                        'useragent' => $r['user-agent'],
    901911                        'headers' => $r['headers'],
     912                        'ssl' => array( 'verifypeer' => false, 'verifyhost' => false )
    902913                );
    903914
    904915                if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) //Emits warning level notices for max redirects and timeouts
     
    988999                        $r['timeout'] = 1;
    9891000
    9901001                $handle = curl_init();
     1002
    9911003                curl_setopt( $handle, CURLOPT_URL, $url);
     1004                curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true );
     1005                curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, false );
     1006                curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, false );
     1007                curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
     1008                curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $r['timeout'] );
     1009                curl_setopt( $handle, CURLOPT_TIMEOUT, $r['timeout'] );
     1010                curl_setopt( $handle, CURLOPT_MAXREDIRS, $r['redirection'] );
    9921011
    993                 if ( 'HEAD' === $r['method'] ) {
    994                         curl_setopt( $handle, CURLOPT_NOBODY, true );
     1012                switch ( $r['method'] ) {
     1013                        case 'HEAD':
     1014                                curl_setopt( $handle, CURLOPT_NOBODY, true );
     1015                                break;
     1016                        case 'POST':
     1017                                curl_setopt( $handle, CURLOPT_POST, true );
     1018                                curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] );
     1019                                break;
    9951020                }
    9961021
    997                 if ( true === $r['blocking'] ) {
     1022                if ( true === $r['blocking'] )
    9981023                        curl_setopt( $handle, CURLOPT_HEADER, true );
    999                         curl_setopt( $handle, CURLOPT_RETURNTRANSFER, 1 );
    1000                 } else {
     1024                else
    10011025                        curl_setopt( $handle, CURLOPT_HEADER, false );
    1002                         curl_setopt( $handle, CURLOPT_NOBODY, true );
    1003                         curl_setopt( $handle, CURLOPT_RETURNTRANSFER, 0 );
    1004                 }
    10051026
    1006                 curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
    1007                 curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 1 );
    1008                 curl_setopt( $handle, CURLOPT_TIMEOUT, $r['timeout'] );
    1009                 curl_setopt( $handle, CURLOPT_MAXREDIRS, $r['redirection'] );
    1010 
    10111027                if ( !ini_get('safe_mode') && !ini_get('open_basedir') )
    10121028                        curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, true );
    10131029