Report curl errors

git-svn-id: http://svn.automattic.com/wordpress/trunk@9185 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-10-15 16:35:35 +00:00
parent 3d41b4e4bb
commit 97f11e8f42
2 changed files with 14 additions and 5 deletions

View File

@ -423,20 +423,26 @@ function wp_handle_sideload( &$file, $overrides = false ) {
*/
function download_url( $url ) {
//WARNING: The file is not automatically deleted, The script must unlink() the file.
if( ! $url )
if ( ! $url )
return new WP_Error('http_no_url', __('Invalid URL Provided'));
$tmpfname = wp_tempnam($url);
if( ! $tmpfname )
if ( ! $tmpfname )
return new WP_Error('http_no_file', __('Could not create Temporary file'));
$handle = @fopen($tmpfname, 'w');
if( ! $handle )
if ( ! $handle )
return new WP_Error('http_no_file', __('Could not create Temporary file'));
$response = wp_remote_get($url);
if( $response['response']['code'] != '200' ){
if ( is_wp_error($response) ) {
fclose($handle);
unlink($tmpfname);
return $response;
}
if ( $response['response']['code'] != '200' ){
fclose($handle);
unlink($tmpfname);
return new WP_Error('http_404', trim($response['response']['message']));

View File

@ -977,7 +977,7 @@ class WP_Http_Curl {
$theResponse = curl_exec( $handle );
if ( $theResponse ) {
if ( !empty($theResponse) ) {
$headerLength = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
$theHeaders = trim( substr($theResponse, 0, $headerLength) );
$theBody = substr( $theResponse, $headerLength );
@ -987,8 +987,11 @@ class WP_Http_Curl {
}
$theHeaders = WP_Http::processHeaders($theHeaders);
} else {
if ( $curl_error = curl_error($handle) )
return new WP_Error('http_request_failed', $curl_error);
if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array(301, 302) ) )
return new WP_Error('http_request_failed', __('Too many redirects.'));
$theHeaders = array( 'headers' => array() );
$theBody = '';
}