wp/wp-includes/class-http.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
--- a/wp/wp-includes/class-http.php	Tue Oct 22 16:11:46 2019 +0200
+++ b/wp/wp-includes/class-http.php	Tue Dec 15 13:49:49 2020 +0100
@@ -8,7 +8,7 @@
  */
 
 if ( ! class_exists( 'Requests' ) ) {
-	require( ABSPATH . WPINC . '/class-requests.php' );
+	require ABSPATH . WPINC . '/class-requests.php';
 
 	Requests::register_autoloader();
 	Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' );
@@ -109,7 +109,7 @@
 	 *                                             'TRACE', 'OPTIONS', or 'PATCH'.
 	 *                                             Some transports technically allow others, but should not be
 	 *                                             assumed. Default 'GET'.
-	 *     @type int          $timeout             How long the connection should stay open in seconds. Default 5.
+	 *     @type float        $timeout             How long the connection should stay open in seconds. Default 5.
 	 *     @type int          $redirection         Number of allowed redirects. Not supported by all transports
 	 *                                             Default 5.
 	 *     @type string       $httpversion         Version of the HTTP protocol to use. Accepts '1.0' and '1.1'.
@@ -133,7 +133,7 @@
 	 *                                             compressed content is returned in the response anyway, it will
 	 *                                             need to be separately decompressed. Default true.
 	 *     @type bool         $sslverify           Whether to verify SSL for the request. Default true.
-	 *     @type string       sslcertificates      Absolute path to an SSL certificate .crt file.
+	 *     @type string       $sslcertificates     Absolute path to an SSL certificate .crt file.
 	 *                                             Default ABSPATH . WPINC . '/certificates/ca-bundle.crt'.
 	 *     @type bool         $stream              Whether to stream to a file. If set to true and no filename was
 	 *                                             given, it will be droped it in the WP temp dir and its name will
@@ -155,7 +155,7 @@
 			 * @since 2.7.0
 			 * @since 5.1.0 The `$url` parameter was added.
 			 *
-			 * @param int    $timeout_value Time in seconds until a request times out. Default 5.
+			 * @param float  $timeout_value Time in seconds until a request times out. Default 5.
 			 * @param string $url           The request URL.
 			 */
 			'timeout'             => apply_filters( 'http_request_timeout', 5, $url ),
@@ -215,53 +215,53 @@
 		// Pre-parse for the HEAD checks.
 		$args = wp_parse_args( $args );
 
-		// By default, Head requests do not cause redirections.
-		if ( isset( $args['method'] ) && 'HEAD' == $args['method'] ) {
+		// By default, HEAD requests do not cause redirections.
+		if ( isset( $args['method'] ) && 'HEAD' === $args['method'] ) {
 			$defaults['redirection'] = 0;
 		}
 
-		$r = wp_parse_args( $args, $defaults );
+		$parsed_args = wp_parse_args( $args, $defaults );
 		/**
 		 * Filters the arguments used in an HTTP request.
 		 *
 		 * @since 2.7.0
 		 *
-		 * @param array  $r   An array of HTTP request arguments.
-		 * @param string $url The request URL.
+		 * @param array  $parsed_args An array of HTTP request arguments.
+		 * @param string $url         The request URL.
 		 */
-		$r = apply_filters( 'http_request_args', $r, $url );
+		$parsed_args = apply_filters( 'http_request_args', $parsed_args, $url );
 
 		// The transports decrement this, store a copy of the original value for loop purposes.
-		if ( ! isset( $r['_redirection'] ) ) {
-			$r['_redirection'] = $r['redirection'];
+		if ( ! isset( $parsed_args['_redirection'] ) ) {
+			$parsed_args['_redirection'] = $parsed_args['redirection'];
 		}
 
 		/**
-		 * Filters whether to preempt an HTTP request's return value.
+		 * Filters the preemptive return value of an HTTP request.
 		 *
 		 * Returning a non-false value from the filter will short-circuit the HTTP request and return
-		 * early with that value. A filter should return either:
+		 * early with that value. A filter should return one of:
 		 *
 		 *  - An array containing 'headers', 'body', 'response', 'cookies', and 'filename' elements
 		 *  - A WP_Error instance
-		 *  - boolean false (to avoid short-circuiting the response)
+		 *  - boolean false to avoid short-circuiting the response
 		 *
 		 * Returning any other value may result in unexpected behaviour.
 		 *
 		 * @since 2.9.0
 		 *
-		 * @param false|array|WP_Error $preempt Whether to preempt an HTTP request's return value. Default false.
-		 * @param array               $r        HTTP request arguments.
-		 * @param string              $url      The request URL.
+		 * @param false|array|WP_Error $preempt     A preemptive return value of an HTTP request. Default false.
+		 * @param array                $parsed_args HTTP request arguments.
+		 * @param string               $url         The request URL.
 		 */
-		$pre = apply_filters( 'pre_http_request', false, $r, $url );
+		$pre = apply_filters( 'pre_http_request', false, $parsed_args, $url );
 
 		if ( false !== $pre ) {
 			return $pre;
 		}
 
 		if ( function_exists( 'wp_kses_bad_protocol' ) ) {
-			if ( $r['reject_unsafe_urls'] ) {
+			if ( $parsed_args['reject_unsafe_urls'] ) {
 				$url = wp_http_validate_url( $url );
 			}
 			if ( $url ) {
@@ -269,84 +269,94 @@
 			}
 		}
 
-		$arrURL = @parse_url( $url );
+		$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', $parsed_args, $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', $parsed_args, $url );
+			return $response;
 		}
 
 		// If we are streaming to a file but no filename was given drop it in the WP temp dir
-		// and pick its name using the basename of the $url
-		if ( $r['stream'] ) {
-			if ( empty( $r['filename'] ) ) {
-				$r['filename'] = get_temp_dir() . basename( $url );
+		// and pick its name using the basename of the $url.
+		if ( $parsed_args['stream'] ) {
+			if ( empty( $parsed_args['filename'] ) ) {
+				$parsed_args['filename'] = get_temp_dir() . basename( $url );
 			}
 
-			// 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.' ) );
+			// Force some settings if we are streaming to a file and check for existence
+			// and perms of destination directory.
+			$parsed_args['blocking'] = true;
+			if ( ! wp_is_writable( dirname( $parsed_args['filename'] ) ) ) {
+				$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', $parsed_args, $url );
+				return $response;
 			}
 		}
 
-		if ( is_null( $r['headers'] ) ) {
-			$r['headers'] = array();
+		if ( is_null( $parsed_args['headers'] ) ) {
+			$parsed_args['headers'] = array();
 		}
 
 		// WP allows passing in headers as a string, weirdly.
-		if ( ! is_array( $r['headers'] ) ) {
-			$processedHeaders = WP_Http::processHeaders( $r['headers'] );
-			$r['headers']     = $processedHeaders['headers'];
+		if ( ! is_array( $parsed_args['headers'] ) ) {
+			$processedHeaders       = WP_Http::processHeaders( $parsed_args['headers'] );
+			$parsed_args['headers'] = $processedHeaders['headers'];
 		}
 
-		// Setup arguments
-		$headers = $r['headers'];
-		$data    = $r['body'];
-		$type    = $r['method'];
+		// Setup arguments.
+		$headers = $parsed_args['headers'];
+		$data    = $parsed_args['body'];
+		$type    = $parsed_args['method'];
 		$options = array(
-			'timeout'   => $r['timeout'],
-			'useragent' => $r['user-agent'],
-			'blocking'  => $r['blocking'],
-			'hooks'     => new WP_HTTP_Requests_Hooks( $url, $r ),
+			'timeout'   => $parsed_args['timeout'],
+			'useragent' => $parsed_args['user-agent'],
+			'blocking'  => $parsed_args['blocking'],
+			'hooks'     => new WP_HTTP_Requests_Hooks( $url, $parsed_args ),
 		);
 
 		// Ensure redirects follow browser behaviour.
 		$options['hooks']->register( 'requests.before_redirect', array( get_class(), 'browser_redirect_compatibility' ) );
 
 		// Validate redirected URLs.
-		if ( function_exists( 'wp_kses_bad_protocol' ) && $r['reject_unsafe_urls'] ) {
+		if ( function_exists( 'wp_kses_bad_protocol' ) && $parsed_args['reject_unsafe_urls'] ) {
 			$options['hooks']->register( 'requests.before_redirect', array( get_class(), 'validate_redirects' ) );
 		}
 
-		if ( $r['stream'] ) {
-			$options['filename'] = $r['filename'];
+		if ( $parsed_args['stream'] ) {
+			$options['filename'] = $parsed_args['filename'];
 		}
-		if ( empty( $r['redirection'] ) ) {
+		if ( empty( $parsed_args['redirection'] ) ) {
 			$options['follow_redirects'] = false;
 		} else {
-			$options['redirects'] = $r['redirection'];
+			$options['redirects'] = $parsed_args['redirection'];
 		}
 
-		// Use byte limit, if we can
-		if ( isset( $r['limit_response_size'] ) ) {
-			$options['max_bytes'] = $r['limit_response_size'];
+		// Use byte limit, if we can.
+		if ( isset( $parsed_args['limit_response_size'] ) ) {
+			$options['max_bytes'] = $parsed_args['limit_response_size'];
 		}
 
 		// If we've got cookies, use and convert them to Requests_Cookie.
-		if ( ! empty( $r['cookies'] ) ) {
-			$options['cookies'] = WP_Http::normalize_cookies( $r['cookies'] );
+		if ( ! empty( $parsed_args['cookies'] ) ) {
+			$options['cookies'] = WP_Http::normalize_cookies( $parsed_args['cookies'] );
 		}
 
-		// SSL certificate handling
-		if ( ! $r['sslverify'] ) {
+		// SSL certificate handling.
+		if ( ! $parsed_args['sslverify'] ) {
 			$options['verify']     = false;
 			$options['verifyname'] = false;
 		} else {
-			$options['verify'] = $r['sslcertificates'];
+			$options['verify'] = $parsed_args['sslcertificates'];
 		}
 
 		// All non-GET/HEAD requests should put the arguments in the form body.
@@ -377,14 +387,14 @@
 			}
 		}
 
-		// Avoid issues where mbstring.func_overload is enabled
+		// Avoid issues where mbstring.func_overload is enabled.
 		mbstring_binary_safe_encoding();
 
 		try {
 			$requests_response = Requests::request( $url, $headers, $data, $type, $options );
 
-			// Convert the response into an array
-			$http_response = new WP_HTTP_Requests_Response( $requests_response, $r['filename'] );
+			// Convert the response into an array.
+			$http_response = new WP_HTTP_Requests_Response( $requests_response, $parsed_args['filename'] );
 			$response      = $http_response->to_array();
 
 			// Add the original object to the array.
@@ -400,18 +410,18 @@
 		 *
 		 * @since 2.8.0
 		 *
-		 * @param array|WP_Error $response HTTP response or WP_Error object.
-		 * @param string         $context  Context under which the hook is fired.
-		 * @param string         $class    HTTP transport used.
-		 * @param array          $r        HTTP request arguments.
-		 * @param string         $url      The request URL.
+		 * @param array|WP_Error $response    HTTP response or WP_Error object.
+		 * @param string         $context     Context under which the hook is fired.
+		 * @param string         $class       HTTP transport used.
+		 * @param array          $parsed_args HTTP request arguments.
+		 * @param string         $url         The request URL.
 		 */
-		do_action( 'http_api_debug', $response, 'response', 'Requests', $r, $url );
+		do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
 		if ( is_wp_error( $response ) ) {
 			return $response;
 		}
 
-		if ( ! $r['blocking'] ) {
+		if ( ! $parsed_args['blocking'] ) {
 			return array(
 				'headers'       => array(),
 				'body'          => '',
@@ -429,11 +439,11 @@
 		 *
 		 * @since 2.9.0
 		 *
-		 * @param array  $response HTTP response.
-		 * @param array  $r        HTTP request arguments.
-		 * @param string $url      The request URL.
+		 * @param array  $response    HTTP response.
+		 * @param array  $parsed_args HTTP request arguments.
+		 * @param string $url         The request URL.
 		 */
-		return apply_filters( 'http_response', $response, $r, $url );
+		return apply_filters( 'http_response', $response, $parsed_args, $url );
 	}
 
 	/**
@@ -474,8 +484,8 @@
 	 * @param Requests_Response $original Response object.
 	 */
 	public static function browser_redirect_compatibility( $location, $headers, $data, &$options, $original ) {
-		// Browser compat
-		if ( $original->status_code === 302 ) {
+		// Browser compatibility.
+		if ( 302 === $original->status_code ) {
 			$options['type'] = Requests::GET;
 		}
 	}
@@ -485,7 +495,7 @@
 	 *
 	 * @since 4.7.5
 	 *
-	 * @throws Requests_Exception On unsuccessful URL validation
+	 * @throws Requests_Exception On unsuccessful URL validation.
 	 * @param string $location URL to redirect to.
 	 */
 	public static function validate_redirects( $location ) {
@@ -499,10 +509,10 @@
 	 *
 	 * @since 3.2.0
 	 *
-	 * @param array $args Request arguments
-	 * @param string $url URL to Request
-	 *
-	 * @return string|false Class name for the first transport that claims to support the request. False if no transport claims to support the request.
+	 * @param array  $args Request arguments.
+	 * @param string $url  URL to request.
+	 * @return string|false Class name for the first transport that claims to support the request.
+	 *                      False if no transport claims to support the request.
 	 */
 	public function _get_first_available_transport( $args, $url = null ) {
 		$transports = array( 'curl', 'streams' );
@@ -512,16 +522,16 @@
 		 *
 		 * @since 3.7.0
 		 *
-		 * @param array  $transports Array of HTTP transports to check. Default array contains
-		 *                           'curl', and 'streams', in that order.
-		 * @param array  $args       HTTP request arguments.
-		 * @param string $url        The URL to request.
+		 * @param string[] $transports Array of HTTP transports to check. Default array contains
+		 *                             'curl' and 'streams', in that order.
+		 * @param array    $args       HTTP request arguments.
+		 * @param string   $url        The URL to request.
 		 */
 		$request_order = apply_filters( 'http_api_transports', $transports, $args, $url );
 
 		// Loop over each transport on each HTTP request looking for one which will serve this request's needs.
 		foreach ( $request_order as $transport ) {
-			if ( in_array( $transport, $transports ) ) {
+			if ( in_array( $transport, $transports, true ) ) {
 				$transport = ucfirst( $transport );
 			}
 			$class = 'WP_Http_' . $transport;
@@ -549,9 +559,10 @@
 	 * @deprecated 5.1.0 Use WP_Http::request()
 	 * @see WP_Http::request()
 	 *
-	 * @param string $url URL to Request
-	 * @param array $args Request arguments
-	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
+	 * @param string $url  URL to request.
+	 * @param array  $args Request arguments.
+	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'.
+	 *                        A WP_Error instance upon error.
 	 */
 	private function _dispatch_request( $url, $args ) {
 		static $transports = array();
@@ -588,12 +599,13 @@
 	 *
 	 * @param string       $url  The request URL.
 	 * @param string|array $args Optional. Override the defaults.
-	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
+	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'.
+	 *                        A WP_Error instance upon error.
 	 */
 	public function post( $url, $args = array() ) {
-		$defaults = array( 'method' => 'POST' );
-		$r        = wp_parse_args( $args, $defaults );
-		return $this->request( $url, $r );
+		$defaults    = array( 'method' => 'POST' );
+		$parsed_args = wp_parse_args( $args, $defaults );
+		return $this->request( $url, $parsed_args );
 	}
 
 	/**
@@ -603,14 +615,15 @@
 	 *
 	 * @since 2.7.0
 	 *
-	 * @param string $url The request URL.
+	 * @param string       $url  The request URL.
 	 * @param string|array $args Optional. Override the defaults.
-	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
+	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'.
+	 *                        A WP_Error instance upon error.
 	 */
 	public function get( $url, $args = array() ) {
-		$defaults = array( 'method' => 'GET' );
-		$r        = wp_parse_args( $args, $defaults );
-		return $this->request( $url, $r );
+		$defaults    = array( 'method' => 'GET' );
+		$parsed_args = wp_parse_args( $args, $defaults );
+		return $this->request( $url, $parsed_args );
 	}
 
 	/**
@@ -620,14 +633,15 @@
 	 *
 	 * @since 2.7.0
 	 *
-	 * @param string $url The request URL.
+	 * @param string       $url  The request URL.
 	 * @param string|array $args Optional. Override the defaults.
-	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
+	 * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'.
+	 *                        A WP_Error instance upon error.
 	 */
 	public function head( $url, $args = array() ) {
-		$defaults = array( 'method' => 'HEAD' );
-		$r        = wp_parse_args( $args, $defaults );
-		return $this->request( $url, $r );
+		$defaults    = array( 'method' => 'HEAD' );
+		$parsed_args = wp_parse_args( $args, $defaults );
+		return $this->request( $url, $parsed_args );
 	}
 
 	/**
@@ -635,10 +649,15 @@
 	 *
 	 * @since 2.7.0
 	 *
-	 * @param string $strResponse The full response string
-	 * @return array Array with 'headers' and 'body' keys.
+	 * @param string $strResponse The full response string.
+	 * @return array {
+	 *     Array with response headers and body.
+	 *
+	 *     @type string $headers HTTP response headers.
+	 *     @type string $body    HTTP response body.
+	 * }
 	 */
-	public static function processResponse( $strResponse ) {
+	public static function processResponse( $strResponse ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
 		$res = explode( "\r\n\r\n", $strResponse, 2 );
 
 		return array(
@@ -648,19 +667,29 @@
 	}
 
 	/**
-	 * Transform header string into an array.
-	 *
-	 * If an array is given then it is assumed to be raw header data with numeric keys with the
-	 * headers as the values. No headers must be passed that were already processed.
+	 * Transforms header string into an array.
 	 *
 	 * @since 2.7.0
 	 *
-	 * @param string|array $headers
-	 * @param string $url The URL that was requested
-	 * @return array Processed string headers. If duplicate headers are encountered,
-	 *                  Then a numbered array is returned as the value of that header-key.
+	 * @param string|array $headers The original headers. If a string is passed, it will be converted
+	 *                              to an array. If an array is passed, then it is assumed to be
+	 *                              raw header data with numeric keys with the headers as the values.
+	 *                              No headers must be passed that were already processed.
+	 * @param string       $url     Optional. The URL that was requested. Default empty.
+	 * @return array {
+	 *     Processed string headers. If duplicate headers are encountered,
+	 *     then a numbered array is returned as the value of that header-key.
+	 *
+	 *     @type array            $response {
+	 *          @type int    $code    The response status code. Default 0.
+	 *          @type string $message The response message. Default empty.
+	 *     }
+	 *     @type array            $newheaders The processed header data as a multidimensional array.
+	 *     @type WP_Http_Cookie[] $cookies    If the original headers contain the 'Set-Cookie' key,
+	 *                                        an array containing `WP_Http_Cookie` objects is returned.
+	 * }
 	 */
-	public static function processHeaders( $headers, $url = '' ) {
+	public static function processHeaders( $headers, $url = '' ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
 		// Split headers, one per array element.
 		if ( is_string( $headers ) ) {
 			// Tolerate line terminator: CRLF = LF (RFC 2616 19.3).
@@ -717,12 +746,12 @@
 			} else {
 				$newheaders[ $key ] = $value;
 			}
-			if ( 'set-cookie' == $key ) {
+			if ( 'set-cookie' === $key ) {
 				$cookies[] = new WP_Http_Cookie( $value, $url );
 			}
 		}
 
-		// Cast the Response Code to an int
+		// Cast the Response Code to an int.
 		$response['code'] = intval( $response['code'] );
 
 		return array(
@@ -743,7 +772,7 @@
 	 *
 	 * @param array $r Full array of args passed into ::request()
 	 */
-	public static function buildCookieHeader( &$r ) {
+	public static function buildCookieHeader( &$r ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
 		if ( ! empty( $r['cookies'] ) ) {
 			// Upgrade any name => value cookie pairs to WP_HTTP_Cookie instances.
 			foreach ( $r['cookies'] as $name => $value ) {
@@ -776,10 +805,10 @@
 	 *
 	 * @since 2.7.0
 	 *
-	 * @param string $body Body content
+	 * @param string $body Body content.
 	 * @return string Chunked decoded body on success or raw body on failure.
 	 */
-	public static function chunkTransferDecode( $body ) {
+	public static function chunkTransferDecode( $body ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
 		// The body is not chunked encoded or is malformed.
 		if ( ! preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', trim( $body ) ) ) {
 			return $body;
@@ -813,24 +842,22 @@
 	}
 
 	/**
-	 * Block requests through the proxy.
+	 * Determines whether an HTTP API request to the given URL should be blocked.
 	 *
 	 * Those who are behind a proxy and want to prevent access to certain hosts may do so. This will
-	 * prevent plugins from working and core functionality, if you don't include api.wordpress.org.
+	 * prevent plugins from working and core functionality, if you don't include `api.wordpress.org`.
 	 *
-	 * You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL as true in your wp-config.php
+	 * You block external URL requests by defining `WP_HTTP_BLOCK_EXTERNAL` as true in your `wp-config.php`
 	 * file and this will only allow localhost and your site to make requests. The constant
-	 * WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the
-	 * WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow, wildcard domains
-	 * are supported, eg *.wordpress.org will allow for all subdomains of wordpress.org to be contacted.
+	 * `WP_ACCESSIBLE_HOSTS` will allow additional hosts to go through for requests. The format of the
+	 * `WP_ACCESSIBLE_HOSTS` constant is a comma separated list of hostnames to allow, wildcard domains
+	 * are supported, eg `*.wordpress.org` will allow for all subdomains of `wordpress.org` to be contacted.
 	 *
 	 * @since 2.8.0
+	 *
 	 * @link https://core.trac.wordpress.org/ticket/8927 Allow preventing external requests.
 	 * @link https://core.trac.wordpress.org/ticket/14636 Allow wildcard domains in WP_ACCESSIBLE_HOSTS
 	 *
-	 * @staticvar array|null $accessible_hosts
-	 * @staticvar array      $wildcard_regex
-	 *
 	 * @param string $uri URI of url.
 	 * @return bool True to block, false to allow.
 	 */
@@ -848,14 +875,15 @@
 		$home = parse_url( get_option( 'siteurl' ) );
 
 		// Don't block requests back to ourselves by default.
-		if ( 'localhost' == $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) {
+		if ( 'localhost' === $check['host'] || ( isset( $home['host'] ) && $home['host'] == $check['host'] ) ) {
 			/**
-			 * Filters whether to block local requests through the proxy.
+			 * Filters whether to block local HTTP API requests.
+			 *
+			 * A local request is one to `localhost` or to the same host as the site itself.
 			 *
 			 * @since 2.8.0
 			 *
-			 * @param bool $block Whether to block local requests through proxy.
-			 *                    Default false.
+			 * @param bool $block Whether to block local requests. Default false.
 			 */
 			return apply_filters( 'block_local_requests', false );
 		}
@@ -881,7 +909,7 @@
 		if ( ! empty( $wildcard_regex ) ) {
 			return ! preg_match( $wildcard_regex, $check['host'] );
 		} else {
-			return ! in_array( $check['host'], $accessible_hosts ); //Inverse logic, If it's in the array, then we can't access it.
+			return ! in_array( $check['host'], $accessible_hosts, true ); // Inverse logic, if it's in the array, then don't block it.
 		}
 
 	}
@@ -908,8 +936,8 @@
 	 *
 	 * @since 3.4.0
 	 *
-	 * @param string $maybe_relative_path The URL which might be relative
-	 * @param string $url                 The URL which $maybe_relative_path is relative to
+	 * @param string $maybe_relative_path The URL which might be relative.
+	 * @param string $url                 The URL which $maybe_relative_path is relative to.
 	 * @return string An Absolute URL, in a failure condition where the URL cannot be parsed, the relative URL will be returned.
 	 */
 	public static function make_absolute_url( $maybe_relative_path, $url ) {
@@ -917,22 +945,25 @@
 			return $maybe_relative_path;
 		}
 
-		if ( ! $url_parts = wp_parse_url( $url ) ) {
+		$url_parts = wp_parse_url( $url );
+		if ( ! $url_parts ) {
 			return $maybe_relative_path;
 		}
 
-		if ( ! $relative_url_parts = wp_parse_url( $maybe_relative_path ) ) {
+		$relative_url_parts = wp_parse_url( $maybe_relative_path );
+		if ( ! $relative_url_parts ) {
 			return $maybe_relative_path;
 		}
 
-		// Check for a scheme on the 'relative' url
+		// Check for a scheme on the 'relative' URL.
 		if ( ! empty( $relative_url_parts['scheme'] ) ) {
 			return $maybe_relative_path;
 		}
 
 		$absolute_path = $url_parts['scheme'] . '://';
 
-		// Schemeless URL's will make it this far, so we check for a host in the relative url and convert it to a protocol-url
+		// Schemeless URLs will make it this far, so we check for a host in the relative URL
+		// and convert it to a protocol-URL.
 		if ( isset( $relative_url_parts['host'] ) ) {
 			$absolute_path .= $relative_url_parts['host'];
 			if ( isset( $relative_url_parts['port'] ) ) {
@@ -945,11 +976,11 @@
 			}
 		}
 
-		// Start off with the Absolute URL path.
+		// Start off with the absolute URL path.
 		$path = ! empty( $url_parts['path'] ) ? $url_parts['path'] : '/';
 
 		// If it's a root-relative path, then great.
-		if ( ! empty( $relative_url_parts['path'] ) && '/' == $relative_url_parts['path'][0] ) {
+		if ( ! empty( $relative_url_parts['path'] ) && '/' === $relative_url_parts['path'][0] ) {
 			$path = $relative_url_parts['path'];
 
 			// Else it's a relative path.
@@ -969,7 +1000,7 @@
 			$path = preg_replace( '!^/(\.\./)+!', '', $path );
 		}
 
-		// Add the Query string.
+		// Add the query string.
 		if ( ! empty( $relative_url_parts['query'] ) ) {
 			$path .= '?' . $relative_url_parts['query'];
 		}
@@ -978,14 +1009,15 @@
 	}
 
 	/**
-	 * Handles HTTP Redirects and follows them if appropriate.
+	 * Handles an HTTP redirect and follows it if appropriate.
 	 *
 	 * @since 3.7.0
 	 *
-	 * @param string $url The URL which was requested.
-	 * @param array $args The Arguments which were used to make the request.
-	 * @param array $response The Response of the HTTP request.
-	 * @return false|object False if no redirect is present, a WP_HTTP or WP_Error result otherwise.
+	 * @param string $url      The URL which was requested.
+	 * @param array  $args     The arguments which were used to make the request.
+	 * @param array  $response The response of the HTTP request.
+	 * @return array|false|WP_Error An HTTP API response array if the redirect is successfully followed,
+	 *                              false if no redirect is present, or a WP_Error object if there's an error.
 	 */
 	public static function handle_redirects( $url, $args, $response ) {
 		// If no redirects are present, or, redirects were not requested, perform no action.
@@ -1013,8 +1045,8 @@
 		$redirect_location = WP_Http::make_absolute_url( $redirect_location, $url );
 
 		// POST requests should not POST to a redirected location.
-		if ( 'POST' == $args['method'] ) {
-			if ( in_array( $response['response']['code'], array( 302, 303 ) ) ) {
+		if ( 'POST' === $args['method'] ) {
+			if ( in_array( $response['response']['code'], array( 302, 303 ), true ) ) {
 				$args['method'] = 'GET';
 			}
 		}
@@ -1039,11 +1071,11 @@
 	 * This does not verify if the IP is a valid IP, only that it appears to be
 	 * an IP address.
 	 *
-	 * @link http://home.deds.nl/~aeron/regex/ for IPv6 regex
+	 * @link http://home.deds.nl/~aeron/regex/ for IPv6 regex.
 	 *
 	 * @since 3.7.0
 	 *
-	 * @param string $maybe_ip A suspected IP address
+	 * @param string $maybe_ip A suspected IP address.
 	 * @return integer|bool Upon success, '4' or '6' to represent a IPv4 or IPv6 address, false upon failure
 	 */
 	public static function is_ip_address( $maybe_ip ) {