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


git-svn-id: https://develop.svn.wordpress.org/trunk@45504 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
johnbillion 2019-06-08 17:09:02 +00:00
parent c14ea1630f
commit ea0a34c649
1 changed files with 12 additions and 3 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;
}
}