Make WordPress Core


Ignore:
Timestamp:
11/25/2021 01:10:30 AM (5 years ago)
Author:
SergeyBiryukov
Message:

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 ​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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-http.php

    r52026 r52244  
    88 */
    99
    10 if ( ! class_exists( 'Requests' ) ) {
    11         require ABSPATH . WPINC . '/class-requests.php';
    12 
    13         Requests::register_autoloader();
    14         Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' );
     10if ( ! class_exists( 'WpOrg\Requests\Autoload' ) ) {
     11        require ABSPATH . WPINC . '/Requests/Autoload.php';
     12
     13        WpOrg\Requests\Autoload::register();
     14        WpOrg\Requests\Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' );
    1515}
    1616
    … …  
    275275                        $response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) );
    276276                        /** This action is documented in wp-includes/class-wp-http.php */
    277                         do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
     277                        do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
    278278                        return $response;
    279279                }
    … …  
    282282                        $response = new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) );
    283283                        /** This action is documented in wp-includes/class-wp-http.php */
    284                         do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
     284                        do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
    285285                        return $response;
    286286                }
    … …  
    299299                                $response = new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) );
    300300                                /** This action is documented in wp-includes/class-wp-http.php */
    301                                 do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
     301                                do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
    302302                                return $response;
    303303                        }
    … …  
    347347                }
    348348
    349                 // If we've got cookies, use and convert them to Requests_Cookie.
     349                // If we've got cookies, use and convert them to WpOrg\Requests\Cookie.
    350350                if ( ! empty( $parsed_args['cookies'] ) ) {
    351351                        $options['cookies'] = WP_Http::normalize_cookies( $parsed_args['cookies'] );
    … …  
    379379                $proxy = new WP_HTTP_Proxy();
    380380                if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
    381                         $options['proxy'] = new Requests_Proxy_HTTP( $proxy->host() . ':' . $proxy->port() );
     381                        $options['proxy'] = new WpOrg\Requests\Proxy\HTTP( $proxy->host() . ':' . $proxy->port() );
    382382
    383383                        if ( $proxy->use_authentication() ) {
    … …  
    392392
    393393                try {
    394                         $requests_response = Requests::request( $url, $headers, $data, $type, $options );
     394                        $requests_response = WpOrg\Requests\Requests::request( $url, $headers, $data, $type, $options );
    395395
    396396                        // Convert the response into an array.
    … …  
    400400                        // Add the original object to the array.
    401401                        $response['http_response'] = $http_response;
    402                 } catch ( Requests_Exception $e ) {
     402                } catch ( WpOrg\Requests\Exception $e ) {
    403403                        $response = new WP_Error( 'http_request_failed', $e->getMessage() );
    404404                }
    … …  
    417417                 * @param string         $url         The request URL.
    418418                 */
    419                 do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
     419                do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
    420420                if ( is_wp_error( $response ) ) {
    421421                        return $response;
    … …  
    453453         *
    454454         * @param array $cookies Array of cookies to send with the request.
    455          * @return Requests_Cookie_Jar Cookie holder object.
     455         * @return WpOrg\Requests\Cookie\Jar Cookie holder object.
    456456         */
    457457        public static function normalize_cookies( $cookies ) {
    458                 $cookie_jar = new Requests_Cookie_Jar();
     458                $cookie_jar = new WpOrg\Requests\Cookie\Jar();
    459459
    460460                foreach ( $cookies as $name => $value ) {
    … …  
    466466                                        }
    467467                                );
    468                                 $cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) );
     468                                $cookie_jar[ $value->name ] = new WpOrg\Requests\Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) );
    469469                        } elseif ( is_scalar( $value ) ) {
    470                                 $cookie_jar[ $name ] = new Requests_Cookie( $name, $value );
     470                                $cookie_jar[ $name ] = new WpOrg\Requests\Cookie( $name, (string) $value );
    471471                        }
    472472                }
    … …  
    484484         * @since 4.6.0
    485485         *
    486          * @param string            $location URL to redirect to.
    487          * @param array             $headers  Headers for the redirect.
    488          * @param string|array      $data     Body to send with the request.
    489          * @param array             $options  Redirect request options.
    490          * @param Requests_Response $original Response object.
     486         * @param string                  $location URL to redirect to.
     487         * @param array                   $headers  Headers for the redirect.
     488         * @param string|array            $data     Body to send with the request.
     489         * @param array                   $options  Redirect request options.
     490         * @param WpOrg\Requests\Response $original Response object.
    491491         */
    492492        public static function browser_redirect_compatibility( $location, $headers, $data, &$options, $original ) {
    493493                // Browser compatibility.
    494494                if ( 302 === $original->status_code ) {
    495                         $options['type'] = Requests::GET;
     495                        $options['type'] = WpOrg\Requests\Requests::GET;
    496496                }
    497497        }
    … …  
    502502         * @since 4.7.5
    503503         *
    504          * @throws Requests_Exception On unsuccessful URL validation.
     504         * @throws WpOrg\Requests\Exception On unsuccessful URL validation.
    505505         * @param string $location URL to redirect to.
    506506         */
    507507        public static function validate_redirects( $location ) {
    508508                if ( ! wp_http_validate_url( $location ) ) {
    509                         throw new Requests_Exception( __( 'A valid URL was not provided.' ), 'wp_http.redirect_failed_validation' );
     509                        throw new WpOrg\Requests\Exception( __( 'A valid URL was not provided.' ), 'wp_http.redirect_failed_validation' );
    510510                }
    511511        }
Note: See TracChangeset for help on using the changeset viewer.