WordPress.org

Make WordPress Core

Ticket #40142: 40142.2.patch

File 40142.2.patch, 7.2 KB (added by desrosj, 3 years ago)

Added TRACE functions to previous patch. Improved documentation alignment. Few spacing improvements.

  • src/wp-includes/class-http.php

     
    605605         * @param string|array $args Optional. Override the defaults.
    606606         * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
    607607         */
    608         public function head($url, $args = array()) {
     608        public function head( $url, $args = array() ) {
    609609                $defaults = array('method' => 'HEAD');
    610610                $r = wp_parse_args( $args, $defaults );
    611611                return $this->request($url, $r);
    612612        }
    613613
    614614        /**
     615         * Uses the PUT HTTP method.
     616         *
     617         * Used for sending data that is expected to be in the body.
     618         *
     619         * @access public
     620         * @since 4.8.0
     621         *
     622         * @param string       $url  The request URL.
     623         * @param string|array $args Optional. Override the defaults.
     624         *
     625         * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
     626         */
     627        public function put( $url, $args = array() ) {
     628                $defaults = array( 'method' => 'PUT' );
     629                $r = wp_parse_args( $args, $defaults );
     630                return $this->request( $url, $r );
     631        }
     632
     633        /**
     634         * Uses the DELETE HTTP method.
     635         *
     636         * Used for sending data that is expected to be in the body.
     637         *
     638         * @access public
     639         * @since 4.8.0
     640         *
     641         * @param string       $url  The request URL.
     642         * @param string|array $args Optional. Override the defaults.
     643         *
     644         * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error.
     645         */
     646        public function delete( $url, $args = array() ) {
     647                $defaults = array( 'method' => 'DELETE' );
     648                $r = wp_parse_args( $args, $defaults );
     649                return $this->request( $url, $r );
     650        }
     651
     652        /**
     653         * Uses the TRACE HTTP method.
     654         *
     655         * Used for sending data that is expected to be in the body.
     656         *
     657         * @access public
     658         * @since 4.8.0
     659         *
     660         * @param string       $url  The request URL.
     661         * @param string|array $args Optional. Override the defaults.
     662         *
     663         * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error.
     664         */
     665        public function trace( $url, $args = array() ) {
     666                $defaults = array( 'method' => 'TRACE' );
     667                $r = wp_parse_args( $args, $defaults );
     668                return $this->request( $url, $r );
     669        }
     670
     671        /**
    615672         * Parses the responses and splits the parts into headers and body.
    616673         *
    617674         * @access public
  • src/wp-includes/http.php

     
    113113}
    114114
    115115/**
     116 * Retrieve the raw response from a safe HTTP request using the PUT method.
     117 *
     118 * This function is ideal when the HTTP request is being made to an arbitrary
     119 * URL. The URL is validated to avoid redirection and request forgery attacks.
     120 *
     121 * @since 4.8.0
     122 *
     123 * @see wp_remote_request() For more information on the response array format.
     124 * @see WP_Http::request() For default arguments information.
     125 *
     126 * @param string $url  Site URL to retrieve.
     127 * @param array  $args Optional. Request arguments. Default empty array.
     128 *
     129 * @return WP_Error|array The response or WP_Error on failure.
     130 */
     131function wp_safe_remote_put( $url, $args = array() ) {
     132        $args['reject_unsafe_urls'] = true;
     133        $http = _wp_http_get_object();
     134        return $http->put( $url, $args );
     135}
     136
     137/**
     138 * Retrieve the raw response from a safe HTTP request using the DELETE method.
     139 *
     140 * This function is ideal when the HTTP request is being made to an arbitrary
     141 * URL. The URL is validated to avoid redirection and request forgery attacks.
     142 *
     143 * @since 4.8.0
     144 *
     145 * @see wp_remote_request() For more information on the response array format.
     146 * @see WP_Http::request() For default arguments information.
     147 *
     148 * @param string $url  Site URL to retrieve.
     149 * @param array  $args Optional. Request arguments. Default empty array.
     150 *
     151 * @return WP_Error|array The response or WP_Error on failure.
     152 */
     153function wp_safe_remote_delete( $url, $args = array() ) {
     154        $args['reject_unsafe_urls'] = true;
     155        $http = _wp_http_get_object();
     156        return $http->delete( $url, $args );
     157}
     158
     159/**
     160 * Retrieve the raw response from a safe HTTP request using the TRACE method.
     161 *
     162 * This function is ideal when the HTTP request is being made to an arbitrary
     163 * URL. The URL is validated to avoid redirection and request forgery attacks.
     164 *
     165 * @since 4.8.0
     166 *
     167 * @see wp_remote_request() For more information on the response array format.
     168 * @see WP_Http::request() For default arguments information.
     169 *
     170 * @param string $url  Site URL to retrieve.
     171 * @param array  $args Optional. Request arguments. Default empty array.
     172 *
     173 * @return WP_Error|array The response or WP_Error on failure.
     174 */
     175function wp_safe_remote_trace( $url, $args = array() ) {
     176        $args['reject_unsafe_urls'] = true;
     177        $http = _wp_http_get_object();
     178        return $http->trace( $url, $args );
     179}
     180
     181/**
    116182 * Retrieve the raw response from the HTTP request.
    117183 *
    118184 * The array structure is a little complex:
     
    139205 *  - Default 'GET'  for wp_remote_get()
    140206 *  - Default 'POST' for wp_remote_post()
    141207 *  - Default 'HEAD' for wp_remote_head()
     208 *  - Default 'PUT'  for wp_remote_put()
     209 *  - Default 'DELETE' for wp_remote_delete()
     210 *  - Default 'TRACE' for wp_remote_trace()
    142211 *
    143212 * @since 2.7.0
    144213 *
     
    205274}
    206275
    207276/**
     277 * Retrieve the raw response from the HTTP request using the PUT method.
     278 *
     279 * @since 4.8.0
     280 *
     281 * @see wp_remote_request() For more information on the response array format.
     282 * @see WP_Http::request() For default arguments information.
     283 *
     284 * @param string $url  Site URL to retrieve.
     285 * @param array  $args Optional. Request arguments. Default empty array.
     286 *
     287 * @return WP_Error|array The response or WP_Error on failure.
     288 */
     289function wp_remote_put( $url, $args = array() ) {
     290        $http = _wp_http_get_object();
     291        return $http->put( $url, $args );
     292}
     293
     294/**
     295 * Retrieve the raw response from the HTTP request using the TRACE method.
     296 *
     297 * @since 4.8.0
     298 *
     299 * @see wp_remote_request() For more information on the response array format.
     300 * @see WP_Http::request() For default arguments information.
     301 *
     302 * @param string $url  Site URL to retrieve.
     303 * @param array  $args Optional. Request arguments. Default empty array.
     304 *
     305 * @return WP_Error|array The response or WP_Error on failure.
     306 */
     307function wp_remote_trace( $url, $args = array() ) {
     308        $http = _wp_http_get_object();
     309        return $http->trace( $url, $args );
     310}
     311
     312/**
     313 * Retrieve the raw response from the HTTP request using the DELETE method.
     314 *
     315 * @since 4.8.0
     316 *
     317 * @see wp_remote_request() For more information on the response array format.
     318 * @see WP_Http::request() For default arguments information.
     319 *
     320 * @param string $url  Site URL to retrieve.
     321 * @param array  $args Optional. Request arguments. Default empty array.
     322 *
     323 * @return WP_Error|array The response or WP_Error on failure.
     324 */
     325function wp_remote_delete( $url, $args = array() ) {
     326        $http = _wp_http_get_object();
     327        return $http->delete( $url, $args );
     328}
     329
     330/**
    208331 * Retrieve only the headers from the raw response.
    209332 *
    210333 * @since 2.7.0