WordPress.org

Make WordPress Core

Ticket #8702: 8702.2.diff

File 8702.2.diff, 5.1 KB (added by sivel, 9 years ago)

Straight update of the code for the current trunk revision (r10374)

  • http.php

     
    7878         * Tests all of the objects and returns the object that passes. Also caches
    7979         * that object to be used later.
    8080         *
    81          * The order for the GET/HEAD requests are Streams, HTTP Extension, Fopen,
    82          * and finally Fsockopen. fsockopen() is used last, because it has the most
    83          * overhead in its implementation. There isn't any real way around it, since
    84          * redirects have to be supported, much the same way the other transports
    85          * also handle redirects.
     81         * The order for the GET/HEAD requests are HTTP Extension, cURL, Streams,
     82         * Fopen, and finally Fsockopen. fsockopen() is used last, because it has
     83         * the most overhead in its implementation. There isn't any real way around
     84         * it, since redirects have to be supported, much the same way the other
     85         * transports also handle redirects.     
    8686         *
    8787         * There are currently issues with "localhost" not resolving correctly with
    8888         * DNS. This may cause an error "failed to open stream: A connection attempt
     
    141141         * to send content, but the streams transport can. This is a limitation that
    142142         * is addressed here, by just not including that transport.
    143143         *
     144         * The order for the POST requests are HTTP Extension, cURL, Streams and
     145         * finally Fsockopen. fsockopen() is used last, because it has the most
     146         * overhead in its implementation. There isn't any real way around it,
     147         * since redirects have to be supported, much the same way the other
     148         * transports also handle redirects.
     149         *
    144150         * @since 2.7.0
    145151         * @access private
    146152         *
     
    154160                        if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) ) {
    155161                                $working_transport['exthttp'] = new WP_Http_ExtHttp();
    156162                                $blocking_transport[] = &$working_transport['exthttp'];
     163                        } else if ( true === WP_Http_Curl::test() && apply_filters('use_curl_transport', true) ) {
     164                                $working_transport['curl'] = new WP_Http_Curl();
     165                                $blocking_transport[] = &$working_transport['curl'];
    157166                        } else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) ) {
    158167                                $working_transport['streams'] = new WP_Http_Streams();
    159168                                $blocking_transport[] = &$working_transport['streams'];
     
    230239                        'timeout' => apply_filters( 'http_request_timeout', 5),
    231240                        'redirection' => apply_filters( 'http_request_redirection_count', 5),
    232241                        'httpversion' => apply_filters( 'http_request_version', '1.0'),
    233                         'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version ),
     242                        'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ),
    234243                        'blocking' => true,
    235244                        'headers' => array(), 'body' => null
    236245                );
     
    787796                                'max_redirects' => $r['redirection'],
    788797                                'protocol_version' => (float) $r['httpversion'],
    789798                                'header' => $strHeaders,
    790                                 'timeout' => $r['timeout']
     799                                'timeout' => $r['timeout'],
     800                                'verify_peer' => false
    791801                        )
    792802                );
    793803
     
    917927                        'redirect' => $r['redirection'],
    918928                        'useragent' => $r['user-agent'],
    919929                        'headers' => $r['headers'],
     930                        'ssl' => array( 'verifypeer' => false, 'verifyhost' => false )
    920931                );
    921932
    922933                if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) //Emits warning level notices for max redirects and timeouts
     
    10071018                        $r['timeout'] = 1;
    10081019
    10091020                $handle = curl_init();
     1021
    10101022                curl_setopt( $handle, CURLOPT_URL, $url);
     1023                curl_setopt( $handle, CURLOPT_RETURNTRANSFER, true );
     1024                curl_setopt( $handle, CURLOPT_SSL_VERIFYHOST, false );
     1025                curl_setopt( $handle, CURLOPT_SSL_VERIFYPEER, false );
     1026                curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
     1027                curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, $r['timeout'] );
     1028                curl_setopt( $handle, CURLOPT_TIMEOUT, $r['timeout'] );
     1029                curl_setopt( $handle, CURLOPT_MAXREDIRS, $r['redirection'] );
    10111030
    1012                 // The cURL extension requires that the option be set for the HEAD to
    1013                 // work properly.
    1014                 if ( 'HEAD' === $r['method'] ) {
    1015                         curl_setopt( $handle, CURLOPT_NOBODY, true );
     1031                switch ( $r['method'] ) {
     1032                        case 'HEAD':
     1033                                curl_setopt( $handle, CURLOPT_NOBODY, true );
     1034                                break;
     1035                        case 'POST':
     1036                                curl_setopt( $handle, CURLOPT_POST, true );
     1037                                curl_setopt( $handle, CURLOPT_POSTFIELDS, $r['body'] );
     1038                                break;
    10161039                }
    10171040
    1018                 if ( true === $r['blocking'] ) {
     1041                if ( true === $r['blocking'] )
    10191042                        curl_setopt( $handle, CURLOPT_HEADER, true );
    1020                         curl_setopt( $handle, CURLOPT_RETURNTRANSFER, 1 );
    1021                 } else {
     1043                else
    10221044                        curl_setopt( $handle, CURLOPT_HEADER, false );
    1023                         curl_setopt( $handle, CURLOPT_NOBODY, true );
    1024                         curl_setopt( $handle, CURLOPT_RETURNTRANSFER, 0 );
    1025                 }
    10261045
    1027                 curl_setopt( $handle, CURLOPT_USERAGENT, $r['user-agent'] );
    1028                 curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 1 );
    1029                 curl_setopt( $handle, CURLOPT_TIMEOUT, $r['timeout'] );
    1030                 curl_setopt( $handle, CURLOPT_MAXREDIRS, $r['redirection'] );
    1031 
    10321046                // The option doesn't work with safe mode or when open_basedir is set.
    10331047                if ( !ini_get('safe_mode') && !ini_get('open_basedir') )
    10341048                        curl_setopt( $handle, CURLOPT_FOLLOWLOCATION, true );