Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Upgrade to Requests 2.0: code updates only
  • Loading branch information
jrfnl committed Nov 23, 2022
commit 5df43680d6249e71fc5af9b5acd95ecf99d9e6e0
2 changes: 1 addition & 1 deletion src/wp-includes/class-wp-http-requests-hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @see Requests_Hooks
*/
#[AllowDynamicProperties]
class WP_HTTP_Requests_Hooks extends Requests_Hooks {
class WP_HTTP_Requests_Hooks extends WpOrg\Requests\Hooks {
/**
* Requested URL.
*
Expand Down
6 changes: 3 additions & 3 deletions src/wp-includes/class-wp-http-requests-response.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class WP_HTTP_Requests_Response extends WP_HTTP_Response {
* @param Requests_Response $response HTTP response.
* @param string $filename Optional. File name. Default empty.
*/
public function __construct( Requests_Response $response, $filename = '' ) {
public function __construct( WpOrg\Requests\Response $response, $filename = '' ) {
$this->response = $response;
$this->filename = $filename;
}
Expand All @@ -64,7 +64,7 @@ public function get_response_object() {
*/
public function get_headers() {
// Ensure headers remain case-insensitive.
$converted = new Requests_Utility_CaseInsensitiveDictionary();
$converted = new WpOrg\Requests\Utility\CaseInsensitiveDictionary();

foreach ( $this->response->headers->getAll() as $key => $value ) {
if ( count( $value ) === 1 ) {
Expand All @@ -85,7 +85,7 @@ public function get_headers() {
* @param array $headers Map of header name to header value.
*/
public function set_headers( $headers ) {
$this->response->headers = new Requests_Response_Headers( $headers );
$this->response->headers = new WpOrg\Requests\Response\Headers( $headers );
}

/**
Expand Down
39 changes: 16 additions & 23 deletions src/wp-includes/class-wp-http.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,11 @@
* @since 2.7.0
*/

if ( ! class_exists( 'Requests' ) ) {
if (!defined('REQUESTS_SILENCE_PSR0_DEPRECATIONS')) {
define('REQUESTS_SILENCE_PSR0_DEPRECATIONS', true);
}

require ABSPATH . WPINC . '/class-requests.php';

Requests::register_autoloader();
Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' );
if ( ! class_exists( 'WpOrg\Requests\Autoload' ) ) {
require ABSPATH . WPINC . '/Requests/Autoload.php';

// Ensure a certain class alias gets created for a class used in type declarations by WP.
class_exists( 'Requests_Response' );
WpOrg\Requests\Autoload::register();
WpOrg\Requests\Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' );
}

/**
Expand Down Expand Up @@ -282,14 +275,14 @@ public function request( $url, $args = array() ) {
if ( empty( $url ) || empty( $parsed_url['scheme'] ) ) {
$response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) );
/** This action is documented in wp-includes/class-wp-http.php */
do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
return $response;
}

if ( $this->block_request( $url ) ) {
$response = new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) );
/** This action is documented in wp-includes/class-wp-http.php */
do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
return $response;
}

Expand All @@ -306,7 +299,7 @@ public function request( $url, $args = array() ) {
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-wp-http.php */
do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
return $response;
}
}
Expand Down Expand Up @@ -386,7 +379,7 @@ public function request( $url, $args = array() ) {
// Check for proxies.
$proxy = new WP_HTTP_Proxy();
if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
$options['proxy'] = new Requests_Proxy_HTTP( $proxy->host() . ':' . $proxy->port() );
$options['proxy'] = new WpOrg\Requests\Proxy\HTTP( $proxy->host() . ':' . $proxy->port() );

if ( $proxy->use_authentication() ) {
$options['proxy']->use_authentication = true;
Expand All @@ -399,15 +392,15 @@ public function request( $url, $args = array() ) {
mbstring_binary_safe_encoding();

try {
$requests_response = Requests::request( $url, $headers, $data, $type, $options );
$requests_response = WpOrg\Requests\Requests::request( $url, $headers, $data, $type, $options );

// 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.
$response['http_response'] = $http_response;
} catch ( Requests_Exception $e ) {
} catch ( WpOrg\Requests\Exception $e ) {
$response = new WP_Error( 'http_request_failed', $e->getMessage() );
}

Expand All @@ -424,7 +417,7 @@ public function request( $url, $args = array() ) {
* @param array $parsed_args HTTP request arguments.
* @param string $url The request URL.
*/
do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
if ( is_wp_error( $response ) ) {
return $response;
}
Expand Down Expand Up @@ -463,7 +456,7 @@ public function request( $url, $args = array() ) {
* @return Requests_Cookie_Jar Cookie holder object.
*/
public static function normalize_cookies( $cookies ) {
$cookie_jar = new Requests_Cookie_Jar();
$cookie_jar = new WpOrg\Requests\Cookie\Jar();

foreach ( $cookies as $name => $value ) {
if ( $value instanceof WP_Http_Cookie ) {
Expand All @@ -473,9 +466,9 @@ static function( $attr ) {
return null !== $attr;
}
);
$cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) );
$cookie_jar[ $value->name ] = new WpOrg\Requests\Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) );
} elseif ( is_scalar( $value ) ) {
$cookie_jar[ $name ] = new Requests_Cookie( $name, (string) $value );
$cookie_jar[ $name ] = new WpOrg\Requests\Cookie( $name, (string) $value );
}
}

Expand All @@ -500,7 +493,7 @@ static function( $attr ) {
public static function browser_redirect_compatibility( $location, $headers, $data, &$options, $original ) {
// Browser compatibility.
if ( 302 === $original->status_code ) {
$options['type'] = Requests::GET;
$options['type'] = WpOrg\Requests\Requests::GET;
}
}

Expand All @@ -514,7 +507,7 @@ public static function browser_redirect_compatibility( $location, $headers, $dat
*/
public static function validate_redirects( $location ) {
if ( ! wp_http_validate_url( $location ) ) {
throw new Requests_Exception( __( 'A valid URL was not provided.' ), 'wp_http.redirect_failed_validation' );
throw new WpOrg\Requests\Exception( __( 'A valid URL was not provided.' ), 'wp_http.redirect_failed_validation' );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,7 @@ function rest_parse_request_arg( $value, $request, $param ) {
function rest_is_ip_address( $ip ) {
$ipv4_pattern = '/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/';

if ( ! preg_match( $ipv4_pattern, $ip ) && ! Requests_IPv6::check_ipv6( $ip ) ) {
if ( ! preg_match( $ipv4_pattern, $ip ) && ! WpOrg\Requests\Ipv6::check_ipv6( $ip ) ) {
return false;
}

Expand Down