Error checking for HTTP requests. Props jacobsantos. see #7793

git-svn-id: http://svn.automattic.com/wordpress/trunk@9051 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-10-02 00:32:21 +00:00
parent a5f7935d8b
commit 33bcf4ec87
3 changed files with 18 additions and 4 deletions

View File

@ -38,6 +38,9 @@ $options['headers'] = array(
$response = wp_remote_get('http://api.pingomatic.com/updated-batch/', $options); $response = wp_remote_get('http://api.pingomatic.com/updated-batch/', $options);
if ( is_wp_error( $response ) )
wp_die(__('Request Failed.'));
if ( $response['response']['code'] != 200 ) if ( $response['response']['code'] != 200 )
wp_die(__('Request Failed.')); wp_die(__('Request Failed.'));

View File

@ -1316,7 +1316,10 @@ function trackback($trackback_url, $title, $excerpt, $ID) {
'excerpt' => urlencode($excerpt) 'excerpt' => urlencode($excerpt)
); );
wp_remote_post($trackback_url, $options); $response = wp_remote_post($trackback_url, $options);
if ( is_wp_error( $response ) )
return;
$tb_url = addslashes( $trackback_url ); $tb_url = addslashes( $trackback_url );
$wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = %d", $ID) ); $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = %d", $ID) );

View File

@ -1039,6 +1039,9 @@ function wp_get_http( $url, $file_path = false, $deprecated = false ) {
$response = wp_remote_request($url, $options); $response = wp_remote_request($url, $options);
if ( is_wp_error( $response ) )
return false;
$headers = wp_remote_retrieve_headers( $response ); $headers = wp_remote_retrieve_headers( $response );
if ( false == $file_path ) if ( false == $file_path )
return $headers; return $headers;
@ -1072,6 +1075,10 @@ function wp_get_http( $url, $file_path = false, $deprecated = false ) {
*/ */
function wp_get_http_headers( $url, $deprecated = false ) { function wp_get_http_headers( $url, $deprecated = false ) {
$response = wp_remote_head( $url ); $response = wp_remote_head( $url );
if ( is_wp_error( $response ) )
return false;
return wp_remote_retrieve_headers( $response ); return wp_remote_retrieve_headers( $response );
} }
@ -1240,11 +1247,9 @@ function add_magic_quotes( $array ) {
* @uses wp_remote_get() * @uses wp_remote_get()
* *
* @param string $uri URI/URL of web page to retrieve. * @param string $uri URI/URL of web page to retrieve.
* @return string HTTP content. * @return bool|string HTTP content. False on failure.
*/ */
function wp_remote_fopen( $uri ) { function wp_remote_fopen( $uri ) {
// parse url() should not be used for validation of URLs.
// Keeping anyway, since the Filter extension is not available on all servers.
$parsed_url = @parse_url( $uri ); $parsed_url = @parse_url( $uri );
if ( !$parsed_url || !is_array( $parsed_url ) ) if ( !$parsed_url || !is_array( $parsed_url ) )
@ -1255,6 +1260,9 @@ function wp_remote_fopen( $uri ) {
$response = wp_remote_get( $uri, $options ); $response = wp_remote_get( $uri, $options );
if ( is_wp_error( $response ) )
return false;
return $response['body']; return $response['body'];
} }