Ticket #7770: 7770.2.diff
| File 7770.2.diff, 5.7 KB (added by , 17 years ago) |
|---|
-
wp-includes/http.php
530 530 if ( (int) $arrHeaders['response']['code'] >= 400 && (int) $arrHeaders['response']['code'] < 500 ) 531 531 return new WP_Error('http_request_failed', $arrHeaders['response']['code'] . ': ' . $arrHeaders['response']['message']); 532 532 533 // If the body was chunk encoded, then decode it.534 if ( ! empty( $process['body'] ) && isset( $arrHeaders['headers']['transfer-encoding'] ) && 'chunked' == $arrHeaders['headers']['transfer-encoding'] )535 $process['body'] = WP_Http::chunkTransferDecode($process['body']);536 537 533 // If location is found, then assume redirect and redirect to location. 538 534 if ( isset($arrHeaders['headers']['location']) ) { 539 535 if ( $r['redirection']-- > 0 ) { 540 536 return $this->request($arrHeaders['headers']['location'], $r); 537 } else { 538 return new WP_Error('http_request_failed', __('Too many redirects.')); 541 539 } 542 else543 return new WP_Error('http_request_failed', __('Too many redirects.'));544 540 } 545 541 542 // If the body was chunk encoded, then decode it. 543 if ( ! empty( $process['body'] ) && isset( $arrHeaders['headers']['transfer-encoding'] ) && 'chunked' == $arrHeaders['headers']['transfer-encoding'] ) 544 $process['body'] = WP_Http::chunkTransferDecode($process['body']); 545 546 546 return array('headers' => $arrHeaders['headers'], 'body' => $process['body'], 'response' => $arrHeaders['response']); 547 547 } 548 548 … … 646 646 647 647 $processedHeaders = WP_Http::processHeaders($theHeaders); 648 648 649 // If location is found, then assume redirect and redirect to location. 650 if ( isset($processedHeaders['headers']['location']) ) { 651 if ( $r['redirection']-- > 0 ) { 652 return $this->request($processedHeaders['headers']['location'], $r); 653 } else { 654 return new WP_Error('http_request_failed', __('Too many redirects.')); 655 } 656 } 657 649 658 if ( ! empty( $strResponse ) && isset( $processedHeaders['headers']['transfer-encoding'] ) && 'chunked' == $processedHeaders['headers']['transfer-encoding'] ) 650 659 $strResponse = WP_Http::chunkTransferDecode($strResponse); 651 660 … … 760 769 $meta = stream_get_meta_data($handle); 761 770 $processedHeaders = WP_Http::processHeaders($meta['wrapper_data']); 762 771 772 // If location is found, then assume redirect and redirect to location. 773 if ( isset($processedHeaders['headers']['location']) ) { 774 if ( $r['redirection']-- > 0 ) { 775 return $this->request($processedHeaders['headers']['location'], $r); 776 } else { 777 return new WP_Error('http_request_failed', __('Too many redirects.')); 778 } 779 } 780 763 781 if ( ! empty( $strResponse ) && isset( $processedHeaders['headers']['transfer-encoding'] ) && 'chunked' == $processedHeaders['headers']['transfer-encoding'] ) 764 782 $strResponse = WP_Http::chunkTransferDecode($strResponse); 765 783 … … 858 876 'headers' => $r['headers'], 859 877 ); 860 878 861 $strResponse = http_request($r['method'], $url, $r['body'], $options, $info); 879 if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) //Emits warning level notices for max redirects and timeouts 880 $strResponse = @http_request($r['method'], $url, $r['body'], $options, $info); 881 else 882 $strResponse = http_request($r['method'], $url, $r['body'], $options, $info); //Emits warning level notices for max redirects and timeouts 862 883 863 if ( false === $strResponse )884 if ( false === $strResponse || ! empty($info['error']) ) //Error may still be set, Response may return headers or partial document, and error contains a reason the request was aborted, eg, timeout expired or max-redirects reached 864 885 return new WP_Error('http_request_failed', $info['response_code'] . ': ' . $info['error']); 865 886 866 887 if ( ! $r['blocking'] ) … … 869 890 list($theHeaders, $theBody) = explode("\r\n\r\n", $strResponse, 2); 870 891 $theHeaders = WP_Http::processHeaders($theHeaders); 871 892 872 if ( ! empty( $theBody ) && isset( $theHeaders['headers']['transfer-encoding'] ) && 'chunked' == $theHeaders['headers']['transfer-encoding'] ) 873 $theBody = http_chunked_decode($theBody); 893 if ( ! empty( $theBody ) && isset( $theHeaders['headers']['transfer-encoding'] ) && 'chunked' == $theHeaders['headers']['transfer-encoding'] ) { 894 if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) 895 $theBody = @http_chunked_decode($theBody); 896 else 897 $theBody = http_chunked_decode($theBody); 898 } 874 899 875 900 $theResponse = array(); 876 901 $theResponse['code'] = $info['response_code']; … … 970 995 971 996 $theResponse = curl_exec( $handle ); 972 997 973 list($theHeaders, $theBody) = explode("\r\n\r\n", $theResponse, 2); 974 $theHeaders = WP_Http::processHeaders($theHeaders); 975 976 if ( ! empty( $theBody ) && isset( $theHeaders['headers']['transfer-encoding'] ) && 'chunked' == $theHeaders['headers']['transfer-encoding'] ) 977 $theBody = WP_Http::chunkTransferDecode($theBody); 978 998 if ( $theResponse ) { 999 $headerLength = curl_getinfo($handle, CURLINFO_HEADER_SIZE); 1000 $theHeaders = trim( substr($theResponse, 0, $headerLength) ); 1001 $theBody = substr( $theResponse, $headerLength ); 1002 if ( false !== strrpos($theHeaders, "\r\n\r\n") ) { 1003 $headerParts = explode("\r\n\r\n", $theHeaders); 1004 $theHeaders = $headerParts[ count($headerParts) -1 ]; 1005 } 1006 $theHeaders = WP_Http::processHeaders($theHeaders); 1007 } else { 1008 if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array(301, 302) ) ) 1009 return new WP_Error('http_request_failed', __('Too many redirects.')); 1010 $theHeaders = array( 'headers' => array() ); 1011 $theBody = ''; 1012 } 979 1013 $response = array(); 980 1014 $response['code'] = curl_getinfo( $handle, CURLINFO_HTTP_CODE ); 981 1015 $response['message'] = get_status_header_desc($response['code']);