Report curl errors
git-svn-id: https://develop.svn.wordpress.org/trunk@9185 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
f29e7feca4
commit
1bd22eb542
@ -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']));
|
||||
|
@ -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 = '';
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user