Ticket #25747: 25747.2.diff
File 25747.2.diff, 4.7 KB (added by , 9 years ago) |
---|
-
src/wp-includes/class-http.php
176 176 * @param string $url The request URL. 177 177 */ 178 178 $pre = apply_filters( 'pre_http_request', false, $r, $url ); 179 if ( false !== $pre ) 180 return $pre; 179 if ( false !== $pre ) { 180 return self::log_response( $pre, false, $r, $url ); 181 } 181 182 182 183 if ( function_exists( 'wp_kses_bad_protocol' ) ) { 183 184 if ( $r['reject_unsafe_urls'] ) … … 189 190 190 191 $arrURL = @parse_url( $url ); 191 192 192 if ( empty( $url ) || empty( $arrURL['scheme'] ) ) 193 return new WP_Error('http_request_failed', __('A valid URL was not provided.')); 193 if ( empty( $url ) || empty( $arrURL['scheme'] ) ) { 194 $response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) ); 195 return self::log_response( $response, false, $r, $url ); 196 } 194 197 195 if ( $this->block_request( $url ) ) 196 return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) ); 198 if ( $this->block_request( $url ) ) { 199 $response = new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) ); 200 return self::log_response( $response, false, $r, $url ); 201 } 197 202 198 203 /* 199 204 * Determine if this is a https call and pass that on to the transport functions … … 220 225 */ 221 226 if ( $r['stream'] ) { 222 227 $r['blocking'] = true; 223 if ( ! wp_is_writable( dirname( $r['filename'] ) ) ) 224 return new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) ); 228 if ( ! wp_is_writable( dirname( $r['filename'] ) ) ) { 229 $response = new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) ); 230 return self::log_response( $response, false, $r, $url ); 231 } 225 232 } 226 233 227 234 if ( is_null( $r['headers'] ) ) … … 349 356 static $transports = array(); 350 357 351 358 $class = $this->_get_first_available_transport( $args, $url ); 352 if ( !$class ) 353 return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) ); 359 if ( !$class ) { 360 $response = new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) ); 361 return self::log_response( $response, $class, $args, $url ); 362 } 354 363 355 364 // Transport claims to support request, instantiate it and give it a whirl. 356 365 if ( empty( $transports[$class] ) ) 357 366 $transports[$class] = new $class; 358 367 359 368 $response = $transports[$class]->request( $url, $args ); 360 361 /** 362 * Fires after an HTTP API response is received and before the response is returned. 363 * 364 * @since 2.8.0 365 * 366 * @param array|WP_Error $response HTTP response or WP_Error object. 367 * @param string $context Context under which the hook is fired. 368 * @param string $class HTTP transport used. 369 * @param array $args HTTP request arguments. 370 * @param string $url The request URL. 371 */ 372 do_action( 'http_api_debug', $response, 'response', $class, $args, $url ); 369 $response = self::log_response( $response, $class, $args, $url ); 373 370 374 371 if ( is_wp_error( $response ) ) 375 372 return $response; … … 387 384 } 388 385 389 386 /** 387 * Log an HTTP API response via the `http_api_debug` action. 388 * 389 * @since 4.2.0 390 * 391 * @param array|WP_Error $response HTTP response or WP_Error object. 392 * @param string|false $class HTTP transport used, if any. 393 * @param array $args HTTP request arguments. 394 * @param string $url The request URL. 395 * @return array|WP_Error HTTP response or WP_Error object. 396 */ 397 public static function log_response( $response, $class, $args, $url ) { 398 /** 399 * Fires after an HTTP API response is received and before the response is returned. 400 * 401 * @since 2.8.0 402 * @since 3.3.0 Added `$args` and `$url` parameters. 403 * 404 * @param array|WP_Error $response HTTP response or WP_Error object. 405 * @param string $context Context under which the hook is fired. 406 * @param string|false $class HTTP transport used, if any. 407 * @param array $args HTTP request arguments. 408 * @param string $url The request URL. 409 */ 410 do_action( 'http_api_debug', $response, 'response', $class, $args, $url ); 411 412 return $response; 413 } 414 415 /** 390 416 * Uses the POST HTTP method. 391 417 * 392 418 * Used for sending data that is expected to be in the body. … … 834 860 } 835 861 } 836 862 863 $response = self::log_response( $response, false, $args, $url ); 864 837 865 return wp_remote_request( $redirect_location, $args ); 838 866 } 839 867