Introduce wp_safe_remote_request(). Also wp_safe_remote_head(), wp_safe_remote_get(), wp_safe_remote_post().
Reverts [24482]. see #24646. git-svn-id: https://develop.svn.wordpress.org/trunk@24894 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3be1012e8a
commit
84255b0e03
@ -87,7 +87,7 @@ class WP_Http {
|
|||||||
'redirection' => apply_filters( 'http_request_redirection_count', 5),
|
'redirection' => apply_filters( 'http_request_redirection_count', 5),
|
||||||
'httpversion' => apply_filters( 'http_request_version', '1.0'),
|
'httpversion' => apply_filters( 'http_request_version', '1.0'),
|
||||||
'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ),
|
'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) ),
|
||||||
'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', true ),
|
'reject_unsafe_urls' => apply_filters( 'http_request_reject_unsafe_urls', false ),
|
||||||
'blocking' => true,
|
'blocking' => true,
|
||||||
'headers' => array(),
|
'headers' => array(),
|
||||||
'cookies' => array(),
|
'cookies' => array(),
|
||||||
|
@ -28,6 +28,84 @@ function _wp_http_get_object() {
|
|||||||
return $http;
|
return $http;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the raw response from a safe HTTP request.
|
||||||
|
*
|
||||||
|
* This function is ideal when the HTTP request is being made to an arbitrary
|
||||||
|
* URL. The URL is validated to avoid redirection and request forgery attacks.
|
||||||
|
*
|
||||||
|
* @see wp_remote_request() For more information on the response array format
|
||||||
|
* and default arguments.
|
||||||
|
*
|
||||||
|
* @since 3.6.0
|
||||||
|
*
|
||||||
|
* @param string $url Site URL to retrieve.
|
||||||
|
* @param array $args Optional. Override the defaults.
|
||||||
|
* @return WP_Error|array The response or WP_Error on failure.
|
||||||
|
*/
|
||||||
|
function wp_safe_remote_request( $url, $args = array() ) {
|
||||||
|
$args['reject_unsafe_urls'] = true;
|
||||||
|
$http = _wp_http_get_object();
|
||||||
|
return $http->request( $url, $args );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the raw response from a safe HTTP request using the GET method.
|
||||||
|
*
|
||||||
|
* @see wp_remote_request() For more information on the response array format
|
||||||
|
* and default arguments.
|
||||||
|
*
|
||||||
|
* @since 3.6.0
|
||||||
|
*
|
||||||
|
* @param string $url Site URL to retrieve.
|
||||||
|
* @param array $args Optional. Override the defaults.
|
||||||
|
* @return WP_Error|array The response or WP_Error on failure.
|
||||||
|
*/
|
||||||
|
function wp_safe_remote_get( $url, $args = array() ) {
|
||||||
|
$args['reject_unsafe_urls'] = true;
|
||||||
|
$http = _wp_http_get_object();
|
||||||
|
return $http->get( $url, $args );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the raw response from a safe HTTP request using the POST method.
|
||||||
|
*
|
||||||
|
* @see wp_remote_request() For more information on the response array format
|
||||||
|
* and default arguments.
|
||||||
|
*
|
||||||
|
* @since 3.6.0
|
||||||
|
*
|
||||||
|
* @param string $url Site URL to retrieve.
|
||||||
|
* @param array $args Optional. Override the defaults.
|
||||||
|
* @return WP_Error|array The response or WP_Error on failure.
|
||||||
|
*/
|
||||||
|
function wp_safe_remote_post( $url, $args = array() ) {
|
||||||
|
$args['reject_unsafe_urls'] = true;
|
||||||
|
$http = _wp_http_get_object();
|
||||||
|
return $http->post( $url, $args );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the raw response from a safe HTTP request using the HEAD method.
|
||||||
|
*
|
||||||
|
* This function is ideal when the HTTP request is being made to an arbitrary
|
||||||
|
* URL. The URL is validated to avoid redirection and request forgery attacks.
|
||||||
|
*
|
||||||
|
* @see wp_remote_request() For more information on the response array format
|
||||||
|
* and default arguments.
|
||||||
|
*
|
||||||
|
* @since 3.6.0
|
||||||
|
*
|
||||||
|
* @param string $url Site URL to retrieve.
|
||||||
|
* @param array $args Optional. Override the defaults.
|
||||||
|
* @return WP_Error|array The response or WP_Error on failure.
|
||||||
|
*/
|
||||||
|
function wp_safe_remote_head( $url, $args = array() ) {
|
||||||
|
$args['reject_unsafe_urls'] = true;
|
||||||
|
$http = _wp_http_get_object();
|
||||||
|
return $http->head( $url, $args );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the raw response from the HTTP request.
|
* Retrieve the raw response from the HTTP request.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user