Make WordPress Core


Ignore:
Timestamp:
12/15/2022 09:30:26 PM (2 years ago)
Author:
hellofromTonya
Message:

External Libraries: Update 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

This commit also resolves 2 blocking issues which previously caused the revert of [52244]:

  • New Requests files are loaded into wp-includes/Requests/src/, matching the location of the library. In doing so, filesystems that are case-insensitive are not impacted (see #54582).
  • Preload: During a Core update, the old Requests files are preloaded into memory before the update deletes the files. Preloading avoids fatal errors noted in #54562.

Follow-up to [50842], [51078], [52244], [52315], [52327], [52328].

Props jrf, schlessera, datagutten, wojsmol, dustinrue, soulseekah, szepeviktor. costdev, sergeybiryukov, peterwilsoncc, ironprogrammer, antonvlasenko, hellofromTonya, swissspidy, dd32, azaozz, TobiasBg, audrasjb.
Fixes #54504.
See #54582, #54562.

File:
1 edited

Legend:

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

    r54891 r54997  
    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/src/Autoload.php';
     12
     13    WpOrg\Requests\Autoload::register();
     14    WpOrg\Requests\Requests::set_certificate_path( ABSPATH . WPINC . '/certificates/ca-bundle.crt' );
    1515}
    1616
     
    276276            $response = new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) );
    277277            /** This action is documented in wp-includes/class-wp-http.php */
    278             do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
     278            do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
    279279            return $response;
    280280        }
     
    283283            $response = new WP_Error( 'http_request_not_executed', __( 'User has blocked requests through HTTP.' ) );
    284284            /** This action is documented in wp-includes/class-wp-http.php */
    285             do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
     285            do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
    286286            return $response;
    287287        }
     
    300300                $response = new WP_Error( 'http_request_failed', __( 'Destination directory for file streaming does not exist or is not writable.' ) );
    301301                /** This action is documented in wp-includes/class-wp-http.php */
    302                 do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
     302                do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
    303303                return $response;
    304304            }
     
    348348        }
    349349
    350         // If we've got cookies, use and convert them to Requests_Cookie.
     350        // If we've got cookies, use and convert them to WpOrg\Requests\Cookie.
    351351        if ( ! empty( $parsed_args['cookies'] ) ) {
    352352            $options['cookies'] = WP_Http::normalize_cookies( $parsed_args['cookies'] );
     
    380380        $proxy = new WP_HTTP_Proxy();
    381381        if ( $proxy->is_enabled() && $proxy->send_through_proxy( $url ) ) {
    382             $options['proxy'] = new Requests_Proxy_HTTP( $proxy->host() . ':' . $proxy->port() );
     382            $options['proxy'] = new WpOrg\Requests\Proxy\HTTP( $proxy->host() . ':' . $proxy->port() );
    383383
    384384            if ( $proxy->use_authentication() ) {
     
    393393
    394394        try {
    395             $requests_response = Requests::request( $url, $headers, $data, $type, $options );
     395            $requests_response = WpOrg\Requests\Requests::request( $url, $headers, $data, $type, $options );
    396396
    397397            // Convert the response into an array.
     
    401401            // Add the original object to the array.
    402402            $response['http_response'] = $http_response;
    403         } catch ( Requests_Exception $e ) {
     403        } catch ( WpOrg\Requests\Exception $e ) {
    404404            $response = new WP_Error( 'http_request_failed', $e->getMessage() );
    405405        }
     
    418418         * @param string         $url         The request URL.
    419419         */
    420         do_action( 'http_api_debug', $response, 'response', 'Requests', $parsed_args, $url );
     420        do_action( 'http_api_debug', $response, 'response', 'WpOrg\Requests\Requests', $parsed_args, $url );
    421421        if ( is_wp_error( $response ) ) {
    422422            return $response;
     
    454454     *
    455455     * @param array $cookies Array of cookies to send with the request.
    456      * @return Requests_Cookie_Jar Cookie holder object.
     456     * @return WpOrg\Requests\Cookie\Jar Cookie holder object.
    457457     */
    458458    public static function normalize_cookies( $cookies ) {
    459         $cookie_jar = new Requests_Cookie_Jar();
     459        $cookie_jar = new WpOrg\Requests\Cookie\Jar();
    460460
    461461        foreach ( $cookies as $name => $value ) {
     
    467467                    }
    468468                );
    469                 $cookie_jar[ $value->name ] = new Requests_Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) );
     469                $cookie_jar[ $value->name ] = new WpOrg\Requests\Cookie( $value->name, $value->value, $attributes, array( 'host-only' => $value->host_only ) );
    470470            } elseif ( is_scalar( $value ) ) {
    471                 $cookie_jar[ $name ] = new Requests_Cookie( $name, $value );
     471                $cookie_jar[ $name ] = new WpOrg\Requests\Cookie( $name, (string) $value );
    472472            }
    473473        }
     
    485485     * @since 4.6.0
    486486     *
    487      * @param string            $location URL to redirect to.
    488      * @param array             $headers  Headers for the redirect.
    489      * @param string|array      $data     Body to send with the request.
    490      * @param array             $options  Redirect request options.
    491      * @param Requests_Response $original Response object.
     487     * @param string                  $location URL to redirect to.
     488     * @param array                   $headers  Headers for the redirect.
     489     * @param string|array            $data     Body to send with the request.
     490     * @param array                   $options  Redirect request options.
     491     * @param WpOrg\Requests\Response $original Response object.
    492492     */
    493493    public static function browser_redirect_compatibility( $location, $headers, $data, &$options, $original ) {
    494494        // Browser compatibility.
    495495        if ( 302 === $original->status_code ) {
    496             $options['type'] = Requests::GET;
     496            $options['type'] = WpOrg\Requests\Requests::GET;
    497497        }
    498498    }
     
    503503     * @since 4.7.5
    504504     *
    505      * @throws Requests_Exception On unsuccessful URL validation.
     505     * @throws WpOrg\Requests\Exception On unsuccessful URL validation.
    506506     * @param string $location URL to redirect to.
    507507     */
    508508    public static function validate_redirects( $location ) {
    509509        if ( ! wp_http_validate_url( $location ) ) {
    510             throw new Requests_Exception( __( 'A valid URL was not provided.' ), 'wp_http.redirect_failed_validation' );
     510            throw new WpOrg\Requests\Exception( __( 'A valid URL was not provided.' ), 'wp_http.redirect_failed_validation' );
    511511        }
    512512    }
Note: See TracChangeset for help on using the changeset viewer.