Make WordPress Core

Changeset 24896


Ignore:
Timestamp:
07/30/2013 06:41:03 PM (12 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].

Merges [24894] and [24895] to the 3.6 branch.

see #24646.

Location:
branches/3.6
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/3.6

  • branches/3.6/wp-includes/class-http.php

    r24767 r24896  
    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(),
  • branches/3.6/wp-includes/http.php

    r24641 r24896  
    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 * This function is ideal when the HTTP request is being made to an arbitrary
     56 * URL. The URL is validated to avoid redirection and request forgery attacks.
     57 *
     58 * @see wp_remote_request() For more information on the response array format
     59 *  and default arguments.
     60 *
     61 * @since 3.6.0
     62 *
     63 * @param string $url Site URL to retrieve.
     64 * @param array $args Optional. Override the defaults.
     65 * @return WP_Error|array The response or WP_Error on failure.
     66 */
     67function wp_safe_remote_get( $url, $args = array() ) {
     68    $args['reject_unsafe_urls'] = true;
     69    $http = _wp_http_get_object();
     70    return $http->get( $url, $args );
     71}
     72
     73/**
     74 * Retrieve the raw response from a safe HTTP request using the POST method.
     75 *
     76 * This function is ideal when the HTTP request is being made to an arbitrary
     77 * URL. The URL is validated to avoid redirection and request forgery attacks.
     78 *
     79 * @see wp_remote_request() For more information on the response array format
     80 *  and default arguments.
     81 *
     82 * @since 3.6.0
     83 *
     84 * @param string $url Site URL to retrieve.
     85 * @param array $args Optional. Override the defaults.
     86 * @return WP_Error|array The response or WP_Error on failure.
     87 */
     88function wp_safe_remote_post( $url, $args = array() ) {
     89    $args['reject_unsafe_urls'] = true;
     90    $http = _wp_http_get_object();
     91    return $http->post( $url, $args );
     92}
     93
     94/**
     95 * Retrieve the raw response from a safe HTTP request using the HEAD method.
     96 *
     97 * This function is ideal when the HTTP request is being made to an arbitrary
     98 * URL. The URL is validated to avoid redirection and request forgery attacks.
     99 *
     100 * @see wp_remote_request() For more information on the response array format
     101 *  and default arguments.
     102 *
     103 * @since 3.6.0
     104 *
     105 * @param string $url Site URL to retrieve.
     106 * @param array $args Optional. Override the defaults.
     107 * @return WP_Error|array The response or WP_Error on failure.
     108 */
     109function wp_safe_remote_head( $url, $args = array() ) {
     110    $args['reject_unsafe_urls'] = true;
     111    $http = _wp_http_get_object();
     112    return $http->head( $url, $args );
    29113}
    30114
Note: See TracChangeset for help on using the changeset viewer.