WordPress.org

Make WordPress Core

Ticket #4779: 4779.r8522.2.diff

File 4779.r8522.2.diff, 3.9 KB (added by santosj, 6 years ago)

Fixes process headers for fopen header return, fixes HTTP extension response array. Also adds Curl implementation and allows for it to be used when using headers.

  • http.php

     
    8888                static $working_transport; 
    8989 
    9090                if ( is_null($working_transport) ) { 
    91                         if ( true === WP_Http_Streams::test() ) 
    92                                 $working_transport = new WP_Http_Streams(); 
    93                         else if ( true === WP_Http_ExtHttp::test() ) 
     91                        if ( true === WP_Http_ExtHttp::test() ) 
    9492                                $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(); 
    9597                        else if ( true === WP_Http_Fopen::test() ) 
    9698                                $working_transport = new WP_Http_Fopen(); 
    9799                        else if ( true === WP_Http_Fsockopen::test() ) 
     
    119121                static $working_transport; 
    120122 
    121123                if ( is_null($working_transport) ) { 
    122                         if ( true === WP_Http_Streams::test() ) 
    123                                 $working_transport = new WP_Http_Streams(); 
    124                         else if ( true === WP_Http_ExtHttp::test() ) 
     124                        if ( true === WP_Http_ExtHttp::test() ) 
    125125                                $working_transport = new WP_Http_ExtHttp(); 
     126                        else if ( true === WP_Http_Streams::test() ) 
     127                                $working_transport = new WP_Http_Streams(); 
    126128                        else if ( true === WP_Http_Fsockopen::test() ) 
    127129                                $working_transport = new WP_Http_Fsockopen(); 
    128130                } 
     
    193195                if ( ! isset($headers['user-agent']) || ! isset($headers['User-Agent']) ) 
    194196                        $headers['user-agent'] = $r['user-agent']; 
    195197 
    196                 if ( is_null($body) || count($headers) > 1 ) 
     198                if ( is_null($body) ) 
    197199                        $transport = WP_Http::_getTransport(); 
    198200                else 
    199201                        $transport = WP_Http::_postTransport(); 
     
    313315        /** 
    314316         * Transform header string into an array. 
    315317         * 
    316          * If an array is given, then it will be immediately passed through with no 
    317          * changes. This is to prevent overhead in processing headers that don't 
    318          * need to be processed. That and it is unknown what kind of effect 
    319          * processing the array will have since there is no checking done on whether 
    320          * ':' does not exist within the array string. 
     318         * If an array is given then it is assumed to be raw header data with 
     319         * numeric keys with the headers as the values. No headers must be passed 
     320         * that were already processed. 
    321321         * 
    322          * Checking could be added, but it is easier and faster to just passed the 
    323          * array through and assume that it has already been processed. 
    324          * 
    325322         * @access public 
    326323         * @static 
    327324         * @since 2.7 
     
    330327         * @return array Processed string headers  
    331328         */ 
    332329        function processHeaders($headers) { 
    333                 if ( is_array($headers) ) 
    334                         return $headers; 
     330                if ( is_string($headers) ) 
     331                        $headers = explode("\n", str_replace(array("\r\n", "\r"), "\n", $headers) ); 
    335332 
    336                 $headers = explode("\n", str_replace(array("\r\n", "\r"), "\n", $headers) ); 
    337  
    338333                $response = array('code' => 0, 'message' => ''); 
    339334 
    340335                $newheaders = array(); 
     
    342337                        if ( empty($tempheader) ) 
    343338                                continue; 
    344339 
     340                         
    345341                        if ( false === strpos($tempheader, ':') ) { 
    346342                                list( , $iResponseCode, $strResponseMsg) = explode(' ', $tempheader, 3); 
    347343                                $response['code'] = $iResponseCode; 
     
    560556                } else { 
    561557                        $theHeaders = $http_response_header; 
    562558                } 
    563                 $processedHeaders = WP_Http::processHeaders($theHeaders); 
    564559 
    565560                fclose($handle); 
     561 
     562                $processedHeaders = WP_Http::processHeaders($theHeaders); 
     563 
    566564                return array('headers' => $processedHeaders['headers'], 'body' => $strResponse, 'response' => $processedHeaders['response']); 
    567565        } 
    568566 
     
    762760                $theHeaders = WP_Http::processHeaders($theHeaders); 
    763761 
    764762                $theResponse = array(); 
    765                 $theResponse['response']['code'] = $info['response_code']; 
    766                 $theResponse['response']['message'] = get_status_header_desc($info['response_code']); 
     763                $theResponse['code'] = $info['response_code']; 
     764                $theResponse['message'] = get_status_header_desc($info['response_code']); 
    767765 
    768766                return array('headers' => $theHeaders['headers'], 'body' => $theBody, 'response' => $theResponse); 
    769767        }