HTTP API: Ensure the http_api_debug hook is fired for all responses.

This means that logging and debugging functionality can access the error code and error message for erroneous responses under all conditions. The hook is not fired when a request is short-circuited with the `pre_http_request` filter, because this filter itself can be used in that situation.

Fixes #25747

Built from https://develop.svn.wordpress.org/trunk@45504


git-svn-id: http://core.svn.wordpress.org/trunk@45315 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
John Blackbourn 2019-06-08 17:10:52 +00:00
parent 935c35fe34
commit eeba1c1244
2 changed files with 13 additions and 4 deletions

View File

@ -272,11 +272,17 @@ class WP_Http {
$arrURL = @parse_url( $url );
if ( empty( $url ) || empty( $arrURL['scheme'] ) ) {
return new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) );
$response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) );
/** This action is documented in wp-includes/class-http.php */
do_action( 'http_api_debug', $response, 'response', 'Requests', $r, $url );
return $response;
}
if ( $this->block_request( $url ) ) {
return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) );
$response = new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) );
/** This action is documented in wp-includes/class-http.php */
do_action( 'http_api_debug', $response, 'response', 'Requests', $r, $url );
return $response;
}
// If we are streaming to a file but no filename was given drop it in the WP temp dir
@ -289,7 +295,10 @@ class WP_Http {
// Force some settings if we are streaming to a file and check for existence and perms of destination directory
$r['blocking'] = true;
if ( ! wp_is_writable( dirname( $r['filename'] ) ) ) {
return new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) );
$response = new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) );
/** This action is documented in wp-includes/class-http.php */
do_action( 'http_api_debug', $response, 'response', 'Requests', $r, $url );
return $response;
}
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-45503';
$wp_version = '5.3-alpha-45504';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.