Make WordPress Core

Changeset 24894


Ignore:
Timestamp:
07/30/2013 03:37:01 PM (11 years ago)
Author:
nacin
Message:

Introduce wp_safe_remote_request(). Also wp_safe_remote_head(), wp_safe_remote_get(), wp_safe_remote_post().

Reverts [24482].

see #24646.

Location:
trunk/wp-includes
Files:
2 edited

Legend:

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

    r24890 r24894  
    8888            'httpversion' => apply_filters( 'http_request_version', '1.0'),
    8989            'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ),
    90             'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', true ),
     90            'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false ),
    9191            'blocking' => true,
    9292            'headers' => array(),
  • trunk/wp-includes/http.php

    r24641 r24894  
    2727
    2828    return $http;
     29}
     30
     31/**
     32 * Retrieve the raw response from a safe HTTP request.
     33 *
     34 * This function is ideal when the HTTP request is being made to an arbitrary
     35 * URL. The URL is validated to avoid redirection and request forgery attacks.
     36 *
     37 * @see wp_remote_request() For more information on the response array format
     38 *  and default arguments.
     39 *
     40 * @since 3.6.0
     41 *
     42 * @param string $url Site URL to retrieve.
     43 * @param array $args Optional. Override the defaults.
     44 * @return WP_Error|array The response or WP_Error on failure.
     45 */
     46function wp_safe_remote_request( $url, $args = array() ) {
     47    $args['reject_unsafe_urls'] = true;
     48    $http = _wp_http_get_object();
     49    return $http->request( $url, $args );
     50}
     51
     52/**
     53 * Retrieve the raw response from a safe HTTP request using the GET method.
     54 *
     55 * @see wp_remote_request() For more information on the response array format
     56 *  and default arguments.
     57 *
     58 * @since 3.6.0
     59 *
     60 * @param string $url Site URL to retrieve.
     61 * @param array $args Optional. Override the defaults.
     62 * @return WP_Error|array The response or WP_Error on failure.
     63 */
     64function wp_safe_remote_get( $url, $args = array() ) {
     65    $args['reject_unsafe_urls'] = true;
     66    $http = _wp_http_get_object();
     67    return $http->get( $url, $args );
     68}
     69
     70/**
     71 * Retrieve the raw response from a safe HTTP request using the POST method.
     72 *
     73 * @see wp_remote_request() For more information on the response array format
     74 *  and default arguments.
     75 *
     76 * @since 3.6.0
     77 *
     78 * @param string $url Site URL to retrieve.
     79 * @param array $args Optional. Override the defaults.
     80 * @return WP_Error|array The response or WP_Error on failure.
     81 */
     82function wp_safe_remote_post( $url, $args = array() ) {
     83    $args['reject_unsafe_urls'] = true;
     84    $http = _wp_http_get_object();
     85    return $http->post( $url, $args );
     86}
     87
     88/**
     89 * Retrieve the raw response from a safe HTTP request using the HEAD method.
     90 *
     91 * This function is ideal when the HTTP request is being made to an arbitrary
     92 * URL. The URL is validated to avoid redirection and request forgery attacks.
     93 *
     94 * @see wp_remote_request() For more information on the response array format
     95 *  and default arguments.
     96 *
     97 * @since 3.6.0
     98 *
     99 * @param string $url Site URL to retrieve.
     100 * @param array $args Optional. Override the defaults.
     101 * @return WP_Error|array The response or WP_Error on failure.
     102 */
     103function wp_safe_remote_head( $url, $args = array() ) {
     104    $args['reject_unsafe_urls'] = true;
     105    $http = _wp_http_get_object();
     106    return $http->head( $url, $args );
    29107}
    30108
Note: See TracChangeset for help on using the changeset viewer.