Various http fixes from santosj. see #4779

git-svn-id: https://develop.svn.wordpress.org/trunk@8522 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-08-01 21:24:03 +00:00
parent 2a1795ae26
commit b7d7804240
1 changed files with 8 additions and 9 deletions

View File

@ -536,7 +536,7 @@ class WP_Http_Fopen {
if ( 'http' != $arrURL['scheme'] || 'https' != $arrURL['scheme'] ) if ( 'http' != $arrURL['scheme'] || 'https' != $arrURL['scheme'] )
$url = str_replace($arrURL['scheme'], 'http', $url); $url = str_replace($arrURL['scheme'], 'http', $url);
$handle = fopen($url, 'rb'); $handle = fopen($url, 'r');
if (! $handle) if (! $handle)
return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url)); return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
@ -553,8 +553,6 @@ class WP_Http_Fopen {
while ( ! feof($handle) ) while ( ! feof($handle) )
$strResponse .= fread($handle, 4096); $strResponse .= fread($handle, 4096);
fclose($handle);
$theHeaders = ''; $theHeaders = '';
if ( function_exists('stream_get_meta_data') ) { if ( function_exists('stream_get_meta_data') ) {
$meta = stream_get_meta_data($handle); $meta = stream_get_meta_data($handle);
@ -564,6 +562,7 @@ class WP_Http_Fopen {
} }
$processedHeaders = WP_Http::processHeaders($theHeaders); $processedHeaders = WP_Http::processHeaders($theHeaders);
fclose($handle);
return array('headers' => $processedHeaders['headers'], 'body' => $strResponse, 'response' => $processedHeaders['response']); return array('headers' => $processedHeaders['headers'], 'body' => $strResponse, 'response' => $processedHeaders['response']);
} }
@ -635,9 +634,9 @@ class WP_Http_Streams {
$context = stream_context_create($arrContext); $context = stream_context_create($arrContext);
$handle = fopen($url, 'rb', false, $context); $handle = fopen($url, 'r', false, $context);
stream_set_timeout($handle, apply_filters('http_request_stream_timeout', $this->timeout) ); stream_set_timeout($handle, apply_filters('http_request_stream_timeout', $r['timeout']) );
if ( ! $handle) if ( ! $handle)
return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url)); return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
@ -747,7 +746,7 @@ class WP_Http_ExtHTTP {
'timeout' => $r['timeout'], 'timeout' => $r['timeout'],
'connecttimeout' => $r['timeout'], 'connecttimeout' => $r['timeout'],
'redirect' => $r['redirection'], 'redirect' => $r['redirection'],
'useragent' => $r['user_agent'], 'useragent' => $r['user-agent'],
'headers' => $headers, 'headers' => $headers,
); );
@ -849,9 +848,9 @@ class WP_Http_Curl {
curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers ); curl_setopt( $handle, CURLOPT_HTTPHEADER, $headers );
if ( $r['httpversion'] == '1.0' ) if ( $r['httpversion'] == '1.0' )
curl_setopt( $headle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 ); curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
else else
curl_setopt( $headle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 ); curl_setopt( $handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1 );
if ( ! $r['blocking'] ) { if ( ! $r['blocking'] ) {
curl_close( $handle ); curl_close( $handle );
@ -1084,4 +1083,4 @@ function wp_remote_retrieve_body(&$response) {
return $response['body']; return $response['body'];
} }
?> ?>