From ea0a34c6491e505f5d91f87c15441bafe03c5e15 Mon Sep 17 00:00:00 2001 From: johnbillion Date: Sat, 8 Jun 2019 17:09:02 +0000 Subject: [PATCH] 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 --- src/wp-includes/class-http.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-http.php b/src/wp-includes/class-http.php index 2a458eb705..4167d78d7b 100644 --- a/src/wp-includes/class-http.php +++ b/src/wp-includes/class-http.php @@ -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; } }