mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
External Libraries: Update the Requests library to version 2.0.0.
This is a major release and contains breaking changes. Most important changes to be aware of for this release: * All code is now namespaced. Though there is a full backward compatibility layer available and the old class names are still supported, using them will generate a deprecation notice (which can be silenced by plugins if they'd need to support multiple WP versions). See the [https://requests.ryanmccue.info/docs/upgrading.html upgrade guide] for more details. * A lot of classes have been marked `final`. This should generally not affect userland code as care has been taken to not apply the `final` keyword to classes which are known to be extended in userland code. * Extensive input validation has been added to Requests. When Requests is used as documented though, this will be unnoticable. * A new `WpOrg\Requests\Requests::has_capabilities()` method has been introduced which can be used to address #37708. * A new `WpOrg\Requests\Response::decode_body()` method has been introduced which may be usable to simplify some of the WP native wrapper code. * Remaining PHP 8.0 compatibility fixed (support for named parameters). * PHP 8.1 compatibility. Release notes: https://github.com/WordPress/Requests/releases/tag/v2.0.0 For a full list of changes in this update, see the Requests GitHub: https://github.com/WordPress/Requests/compare/v1.8.1...v2.0.0 Follow-up to [50842], [51078]. Props jrf, schlessera, datagutten, wojsmol, dd32, dustinrue, soulseekah, costdev, szepeviktor. Fixes #54504. git-svn-id: https://develop.svn.wordpress.org/trunk@52244 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -7,11 +7,11 @@
|
||||
* @since 2.7.0
|
||||
*/
|
||||
|
||||
if ( ! class_exists( 'Requests' ) ) {
|
||||
require ABSPATH . WPINC . '/class-requests.php';
|
||||
if ( ! class_exists( 'WpOrg\Requests\Autoload' ) ) {
|
||||
require ABSPATH . WPINC . '/Requests/Autoload.php';
|
||||
|
||||
Requests::register_autoloader();
|
||||
Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' );
|
||||
WpOrg\Requests\Autoload::register();
|
||||
WpOrg\Requests\Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,14 +274,14 @@ class WP_Http {
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ class WP_Http {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -346,7 +346,7 @@ class WP_Http {
|
||||
$options['max_bytes'] = $parsed_args['limit_response_size'];
|
||||
}
|
||||
|
||||
// If we've got cookies, use and convert them to Requests_Cookie.
|
||||
// If we've got cookies, use and convert them to WpOrg\Requests\Cookie.
|
||||
if ( ! empty( $parsed_args['cookies'] ) ) {
|
||||
$options['cookies'] = WP_Http::normalize_cookies( $parsed_args['cookies'] );
|
||||
}
|
||||
@@ -378,7 +378,7 @@ class WP_Http {
|
||||
// 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;
|
||||
@@ -391,7 +391,7 @@ class WP_Http {
|
||||
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'] );
|
||||
@@ -399,7 +399,7 @@ class WP_Http {
|
||||
|
||||
// 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() );
|
||||
}
|
||||
|
||||
@@ -416,7 +416,7 @@ class WP_Http {
|
||||
* @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;
|
||||
}
|
||||
@@ -452,10 +452,10 @@ class WP_Http {
|
||||
* @since 4.6.0
|
||||
*
|
||||
* @param array $cookies Array of cookies to send with the request.
|
||||
* @return Requests_Cookie_Jar Cookie holder object.
|
||||
* @return WpOrg\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 ) {
|
||||
@@ -465,9 +465,9 @@ class WP_Http {
|
||||
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, $value );
|
||||
$cookie_jar[ $name ] = new WpOrg\Requests\Cookie( $name, (string) $value );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -483,16 +483,16 @@ class WP_Http {
|
||||
*
|
||||
* @since 4.6.0
|
||||
*
|
||||
* @param string $location URL to redirect to.
|
||||
* @param array $headers Headers for the redirect.
|
||||
* @param string|array $data Body to send with the request.
|
||||
* @param array $options Redirect request options.
|
||||
* @param Requests_Response $original Response object.
|
||||
* @param string $location URL to redirect to.
|
||||
* @param array $headers Headers for the redirect.
|
||||
* @param string|array $data Body to send with the request.
|
||||
* @param array $options Redirect request options.
|
||||
* @param WpOrg\Requests\Response $original Response object.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -501,12 +501,12 @@ class WP_Http {
|
||||
*
|
||||
* @since 4.7.5
|
||||
*
|
||||
* @throws Requests_Exception On unsuccessful URL validation.
|
||||
* @throws WpOrg\Requests\Exception On unsuccessful URL validation.
|
||||
* @param string $location URL to redirect to.
|
||||
*/
|
||||
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' );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user