Use wp_remote_retrieve_* helper functions instead of the raw HTTP response array. props aaroncampbell, fixes #17416.

git-svn-id: http://svn.automattic.com/wordpress/trunk@17928 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
nacin 2011-05-14 19:45:07 +00:00
parent 57a5e26a27
commit da2732c7de
11 changed files with 44 additions and 54 deletions

View File

@ -1208,10 +1208,10 @@ function wp_check_browser_version() {
'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
);
$raw_response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.0/', $options );
$response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.0/', $options );
if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code'] )
return;
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
return false;
/**
* Response should be an array with:
@ -1224,7 +1224,7 @@ function wp_check_browser_version() {
* 'img_src' - string - An image representing the browser
* 'img_src_ssl' - string - An image (over SSL) representing the browser
*/
$response = unserialize( $raw_response['body'] );
$response = unserialize( wp_remote_retrieve_body( $response ) );
if ( ! $response )
return;

View File

@ -490,9 +490,9 @@ function download_url( $url, $timeout = 300 ) {
return $response;
}
if ( $response['response']['code'] != '200' ){
if ( 200 != wp_remote_retrieve_response_code( $response ) ){
unlink( $tmpfname );
return new WP_Error( 'http_404', trim( $response['response']['message'] ) );
return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
}
return $tmpfname;

View File

@ -45,9 +45,9 @@ function plugins_api($action, $args = null) {
if ( is_wp_error($request) ) {
$res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() );
} else {
$res = unserialize($request['body']);
$res = unserialize( wp_remote_retrieve_body( $request ) );
if ( false === $res )
$res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), $request['body']);
$res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body( $request ) );
}
} elseif ( !is_wp_error($res) ) {
$res->external = true;
@ -367,4 +367,3 @@ function install_plugin_information() {
exit;
}
add_action('install_plugins_pre_plugin-information', 'install_plugin_information');

View File

@ -762,7 +762,7 @@ Thanks!
$page = wp_remote_get( 'http://' . $hostname, array( 'timeout' => 5, 'httpversion' => '1.1' ) );
if ( is_wp_error( $page ) )
$errstr = $page->get_error_message();
elseif ( 200 == $page['response']['code'] )
elseif ( 200 == wp_remote_retrieve_response_code( $page ) )
$vhost_ok = true;
if ( ! $vhost_ok ) {

View File

@ -396,9 +396,9 @@ function themes_api($action, $args = null) {
if ( is_wp_error($request) ) {
$res = new WP_Error('themes_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() );
} else {
$res = unserialize($request['body']);
$res = unserialize( wp_remote_retrieve_body( $request ) );
if ( ! $res )
$res = new WP_Error('themes_api_failed', __('An unknown error occurred.'), $request['body']);
$res = new WP_Error('themes_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body( $request ) );
}
}
//var_dump(array($args, $res));

View File

@ -80,9 +80,9 @@ class WP_SimplePie_File extends SimplePie_File {
$this->error = 'WP HTTP Error: ' . $res->get_error_message();
$this->success = false;
} else {
$this->headers = $res['headers'];
$this->body = $res['body'];
$this->status_code = $res['response']['code'];
$this->headers = wp_remote_retrieve_headers( $res );
$this->body = wp_remote_retrieve_body( $res );
$this->status_code = wp_remote_retrieve_response_code( $res );
}
} else {
if ( ! $this->body = file_get_contents($url) ) {
@ -91,4 +91,4 @@ class WP_SimplePie_File extends SimplePie_File {
}
}
}
}
}

View File

@ -64,16 +64,16 @@ class WP_HTTP_IXR_Client extends IXR_Client {
return false;
}
if ( $response['response']['code'] != 200 ) {
$this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ({$response['response']['code']})");
if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
$this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')');
return false;
}
if ( $this->debug )
echo '<pre class="ixr_response">' . htmlspecialchars($response['body']) . "\n</pre>\n\n";
echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n";
// Now parse what we've got back
$this->message = new IXR_Message( $response['body'] );
$this->message = new IXR_Message( wp_remote_retrieve_body( $response ) );
if ( ! $this->message->parse() ) {
// XML error
$this->error = new IXR_Error(-32700, 'parse error. not well formed');
@ -90,4 +90,4 @@ class WP_HTTP_IXR_Client extends IXR_Client {
return true;
}
}
?>
?>

View File

@ -1619,11 +1619,11 @@ function discover_pingback_server_uri( $url, $deprecated = '' ) {
if ( is_wp_error( $response ) )
return false;
if ( isset( $response['headers']['x-pingback'] ) )
return $response['headers']['x-pingback'];
if ( wp_remote_retrieve_header( $response, 'x-pingback' ) )
return wp_remote_retrieve_header( $response, 'x-pingback' );
// Not an (x)html, sgml, or xml page, no use going further.
if ( isset( $response['headers']['content-type'] ) && preg_match('#(image|audio|video|model)/#is', $response['headers']['content-type']) )
if ( preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' )) )
return false;
// Now do a GET since we're going to look in the html headers (and we're sure its not a binary file)
@ -1632,7 +1632,7 @@ function discover_pingback_server_uri( $url, $deprecated = '' ) {
if ( is_wp_error( $response ) )
return false;
$contents = $response['body'];
$contents = wp_remote_retrieve_body( $response );
$pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
$pingback_link_offset_squote = strpos($contents, $pingback_str_squote);

View File

@ -600,7 +600,7 @@ function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' )
wp_protect_special_option( $option );
/*
/*
* FIXME the next two lines of code are not necessary and should be removed.
* @see http://core.trac.wordpress.org/ticket/13480
*/
@ -1305,7 +1305,7 @@ function wp_get_http( $url, $file_path = false, $red = 1 ) {
return false;
$headers = wp_remote_retrieve_headers( $response );
$headers['response'] = $response['response']['code'];
$headers['response'] = wp_remote_retrieve_response_code( $response );
// WP_HTTP no longer follows redirects for HEAD requests.
if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) {
@ -1320,7 +1320,7 @@ function wp_get_http( $url, $file_path = false, $red = 1 ) {
if ( !$out_fp )
return $headers;
fwrite( $out_fp, $response['body']);
fwrite( $out_fp, wp_remote_retrieve_body( $response ) );
fclose($out_fp);
clearstatcache();
@ -1556,7 +1556,7 @@ function wp_remote_fopen( $uri ) {
if ( is_wp_error( $response ) )
return false;
return $response['body'];
return wp_remote_retrieve_body( $response );
}
/**
@ -2876,26 +2876,26 @@ if ( 'rtl' == $text_direction ) : ?>
* @param string $title Error title.
* @param string|array $args Optional arguements to control behaviour.
*/
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
global $wp_xmlrpc_server;
$defaults = array( 'response' => 500 );
$r = wp_parse_args($args, $defaults);
if ( $wp_xmlrpc_server ) {
$error = new IXR_Error( $r['response'] , $message);
$wp_xmlrpc_server->output( $error->getXml() );
if ( $wp_xmlrpc_server ) {
$error = new IXR_Error( $r['response'] , $message);
$wp_xmlrpc_server->output( $error->getXml() );
}
die();
}
/**
* Filter to enable special wp_die handler for xmlrpc requests.
*
*
* @since 3.2.0
* @access private
*/
function _xmlrpc_wp_die_filter() {
function _xmlrpc_wp_die_filter() {
return '_xmlrpc_wp_die_handler';
}

View File

@ -555,7 +555,7 @@ function _fetch_remote_file($url, $headers = "" ) {
// Snoopy returns headers unprocessed.
// Also note, WP_HTTP lowercases all keys, Snoopy did not.
$return_headers = array();
foreach ( $resp['headers'] as $key => $value ) {
foreach ( wp_remote_retrieve_headers( $resp ) as $key => $value ) {
if ( !is_array($value) ) {
$return_headers[] = "$key: $value";
} else {
@ -565,10 +565,10 @@ function _fetch_remote_file($url, $headers = "" ) {
}
$response = new stdClass;
$response->status = $resp['response']['code'];
$response->response_code = $resp['response']['code'];
$response->status = wp_remote_retrieve_response_code( $resp );
$response->response_code = wp_remote_retrieve_response_code( $resp );
$response->headers = $return_headers;
$response->results = $resp['body'];
$response->results = wp_remote_retrieve_body( $resp );
return $response;
}

View File

@ -71,13 +71,10 @@ function wp_version_check() {
$response = wp_remote_get($url, $options);
if ( is_wp_error( $response ) )
if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
return false;
if ( 200 != $response['response']['code'] )
return false;
$body = trim( $response['body'] );
$body = trim( wp_remote_retrieve_body( $response ) );
$body = str_replace(array("\r\n", "\r"), "\n", $body);
$new_options = array();
foreach ( explode( "\n\n", $body ) as $entry ) {
@ -175,13 +172,10 @@ function wp_update_plugins() {
$raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', $options);
if ( is_wp_error( $raw_response ) )
if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
return false;
if ( 200 != $raw_response['response']['code'] )
return false;
$response = unserialize( $raw_response['body'] );
$response = unserialize( wp_remote_retrieve_body( $raw_response ) );
if ( false !== $response )
$new_option->response = $response;
@ -273,17 +267,14 @@ function wp_update_themes() {
$raw_response = wp_remote_post( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
if ( is_wp_error( $raw_response ) )
return false;
if ( 200 != $raw_response['response']['code'] )
if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
return false;
$new_update = new stdClass;
$new_update->last_checked = time( );
$new_update->checked = $checked;
$response = unserialize( $raw_response['body'] );
$response = unserialize( wp_remote_retrieve_body( $raw_response ) );
if ( false !== $response )
$new_update->response = $response;