WordPress.org

Make WordPress Core

Changeset 9185


Ignore:
Timestamp:
10/15/2008 04:35:35 PM (13 years ago)
Author:
ryan
Message:

Report curl errors

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/file.php

    r9165 r9185  
    424424function download_url( $url ) {
    425425    //WARNING: The file is not automatically deleted, The script must unlink() the file.
    426     if( ! $url )
     426    if ( ! $url )
    427427        return new WP_Error('http_no_url', __('Invalid URL Provided'));
    428428
    429429    $tmpfname = wp_tempnam($url);
    430     if( ! $tmpfname )
     430    if ( ! $tmpfname )
    431431        return new WP_Error('http_no_file', __('Could not create Temporary file'));
    432432
    433433    $handle = @fopen($tmpfname, 'w');
    434     if( ! $handle )
     434    if ( ! $handle )
    435435        return new WP_Error('http_no_file', __('Could not create Temporary file'));
    436436
    437437    $response = wp_remote_get($url);
    438438
    439     if( $response['response']['code'] != '200' ){
     439    if ( is_wp_error($response) ) {
     440        fclose($handle);
     441        unlink($tmpfname);
     442        return $response;
     443    }
     444
     445    if ( $response['response']['code'] != '200' ){
    440446        fclose($handle);
    441447        unlink($tmpfname);
  • trunk/wp-includes/http.php

    r9091 r9185  
    978978        $theResponse = curl_exec( $handle );
    979979
    980         if ( $theResponse ) {
     980        if ( !empty($theResponse) ) {
    981981            $headerLength = curl_getinfo($handle, CURLINFO_HEADER_SIZE);
    982982            $theHeaders = trim( substr($theResponse, 0, $headerLength) );
     
    988988            $theHeaders = WP_Http::processHeaders($theHeaders);
    989989        } else {
     990            if ( $curl_error = curl_error($handle) )
     991                return new WP_Error('http_request_failed', $curl_error);
    990992            if ( in_array( curl_getinfo( $handle, CURLINFO_HTTP_CODE ), array(301, 302) ) )
    991993                return new WP_Error('http_request_failed', __('Too many redirects.'));
     994           
    992995            $theHeaders = array( 'headers' => array() );
    993996            $theBody = '';
Note: See TracChangeset for help on using the changeset viewer.