From 61b8ba846123ed1283f380122deea12265990985 Mon Sep 17 00:00:00 2001 From: Drew Jaynes Date: Fri, 18 Jul 2014 22:01:15 +0000 Subject: [PATCH] Convert documentation for default arguments in `WP_Http::request()` to a hash notation. Also update corresponding docs for functions that leverage its arguments. See #28298. Built from https://develop.svn.wordpress.org/trunk@29230 git-svn-id: http://core.svn.wordpress.org/trunk@29014 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-http.php | 76 ++++++++++++++++----------- wp-includes/http.php | 103 +++++++++++++++++-------------------- 2 files changed, 94 insertions(+), 85 deletions(-) diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index e5a46f2d9c..8e5d635bd9 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -28,41 +28,57 @@ class WP_Http { /** - * Send a HTTP request to a URI. + * Send an HTTP request to a URI. * - * The body and headers are part of the arguments. The 'body' argument is for the body and will - * accept either a string or an array. The 'headers' argument should be an array, but a string - * is acceptable. If the 'body' argument is an array, then it will automatically be escaped - * using http_build_query(). - * - * The only URI that are supported in the HTTP Transport implementation are the HTTP and HTTPS - * protocols. - * - * The defaults are 'method', 'timeout', 'redirection', 'httpversion', 'blocking' and - * 'user-agent'. - * - * Accepted 'method' values are 'GET', 'POST', and 'HEAD', some transports technically allow - * others, but should not be assumed. The 'timeout' is used to sent how long the connection - * should stay open before failing when no response. 'redirection' is used to track how many - * redirects were taken and used to sent the amount for other transports, but not all transports - * accept setting that value. - * - * The 'httpversion' option is used to sent the HTTP version and accepted values are '1.0', and - * '1.1' and should be a string. The 'user-agent' option is the user-agent and is used to - * replace the default user-agent, which is 'WordPress/WP_Version', where WP_Version is the - * value from $wp_version. - * - * The 'blocking' parameter can be used to specify if the calling code requires the result of - * the HTTP request. If set to false, the request will be sent to the remote server, and - * processing returned to the calling code immediately, the caller will know if the request - * suceeded or failed, but will not receive any response from the remote server. + * Please note: The only URI that are supported in the HTTP Transport implementation + * are the HTTP and HTTPS protocols. * * @access public * @since 2.7.0 * - * @param string $url The request URL. - * @param string|array $args Optional. Override the defaults. - * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error + * @param string $url The request URL. + * @param string|array $args { + * Optional. Array or string of HTTP request arguments. + * + * @type string $method Request method. Accepts 'GET', 'POST', 'HEAD', or 'PUT'. + * Some transports technically allow others, but should not be + * assumed. Default 'GET'. + * @type int $timeout How long the connection should stay open in seconds. Default 5. + * @type int $redirection Number of allowed redirects. Not supported by all transports + * Default 5. + * @type string $httpversion Version of the HTTP protocol to use. Accepts '1.0' and '1.1'. + * Default '1.0'. + * @type string $user-agent User-agent value sent. + * Default WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ). + * @type bool $reject_unsafe_urls Whether to pass URLs through {@see wp_http_validate_url()}. + * Default false. + * @type bool $blocking Whether the calling code requires the result of the request. + * If set to false, the request will be sent to the remote server, + * and processing returned to the calling code immediately, the caller + * will know if the request succeeded or failed, but will not receive + * any response from the remote server. Default true. + * @type string|array $headers Array or string of headers to send with the request. + * Default empty array. + * @type array $cookies List of cookies to send with the request. Default empty array. + * @type string|array $body Body to send with the request. Default null. + * @type bool $compress Whether to compress the $body when sending the request. + * Default false. + * @type bool $decompress Whether to decompress a compressed response. If set to false and + * compressed content is returned in the response anyway, it will + * need to be separately decompressed. Default true. + * @type bool $sslverify Whether to verify SSL for the request. Default true. + * @type string sslcertificates Absolute path to an SSL certificate .crt file. + * Default ABSPATH . WPINC . '/certificates/ca-bundle.crt'. + * @type bool $stream Whether to stream to a file. If set to true and no filename was + * given, it will be droped it in the WP temp dir and its name will + * be set using the basename of the URL. Default false. + * @type string $filename Filename of the file to write to when streaming. $stream must be + * set to true. Default null. + * @type int $limit_response_size Size in bytes to limit the response to. Default null. + * + * } + * @return array|WP_Error Array containing 'headers', 'body', 'response', 'cookies', 'filename'. + * A WP_Error instance upon error. */ public function request( $url, $args = array() ) { global $wp_version; diff --git a/wp-includes/http.php b/wp-includes/http.php index f70a720cc8..3a5f4ada90 100644 --- a/wp-includes/http.php +++ b/wp-includes/http.php @@ -34,13 +34,13 @@ function _wp_http_get_object() { * 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. + * @see wp_remote_request() For more information on the response array format. + * @see WP_Http::request() For default arguments information. + * + * @param string $url Site URL to retrieve. + * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ function wp_safe_remote_request( $url, $args = array() ) { @@ -55,13 +55,13 @@ function wp_safe_remote_request( $url, $args = array() ) { * 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. + * @see wp_remote_request() For more information on the response array format. + * @see WP_Http::request() For default arguments information. + * + * @param string $url Site URL to retrieve. + * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ function wp_safe_remote_get( $url, $args = array() ) { @@ -76,13 +76,13 @@ function wp_safe_remote_get( $url, $args = array() ) { * 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. + * @see wp_remote_request() For more information on the response array format. + * @see WP_Http::request() For default arguments information. + * + * @param string $url Site URL to retrieve. + * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ function wp_safe_remote_post( $url, $args = array() ) { @@ -97,13 +97,13 @@ function wp_safe_remote_post( $url, $args = array() ) { * 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 * + * @see wp_remote_request() For more information on the response array format. + * @see WP_Http::request() For default arguments information. + * * @param string $url Site URL to retrieve. - * @param array $args Optional. Override the defaults. + * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ function wp_safe_remote_head( $url, $args = array() ) { @@ -115,47 +115,37 @@ function wp_safe_remote_head( $url, $args = array() ) { /** * Retrieve the raw response from the HTTP request. * - * The array structure is a little complex. + * The array structure is a little complex: * - * - * $res = array( 'headers' => array(), 'response' => array('code' => int, 'message' => string) ); - * + * $res = array( + * 'headers' => array(), + * 'response' => array( + * 'code' => int, + * 'message' => string + * ) + * ); * * All of the headers in $res['headers'] are with the name as the key and the * value as the value. So to get the User-Agent, you would do the following. * - * - * $user_agent = $res['headers']['user-agent']; - * + * $user_agent = $res['headers']['user-agent']; * * The body is the raw response content and can be retrieved from $res['body']. * * This function is called first to make the request and there are other API * functions to abstract out the above convoluted setup. * - * List of default arguments: - * 'method' => 'GET' + * Request method defaults for helper functions: * - Default 'GET' for wp_remote_get() * - Default 'POST' for wp_remote_post() * - Default 'HEAD' for wp_remote_head() - * 'timeout' => 5 - * 'redirection' => 5 - * 'httpversion' => '1.0' - * 'user-agent' => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) - * 'blocking' => true - * 'headers' => array() - * 'cookies' => array() - * 'body' => null - * 'compress' => false, - * 'decompress' => true, - * 'sslverify' => true, - * 'stream' => false, - * 'filename' => null * * @since 2.7.0 * - * @param string $url Site URL to retrieve. - * @param array $args Optional. Override the defaults. + * @see WP_Http::request() For additional information on default arguments. + * + * @param string $url Site URL to retrieve. + * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ function wp_remote_request($url, $args = array()) { @@ -166,12 +156,13 @@ function wp_remote_request($url, $args = array()) { /** * Retrieve the raw response from the HTTP request using the GET method. * - * @see wp_remote_request() For more information on the response array format and default arguments. - * * @since 2.7.0 * - * @param string $url Site URL to retrieve. - * @param array $args Optional. Override the defaults. + * @see wp_remote_request() For more information on the response array format. + * @see WP_Http::request() For default arguments information. + * + * @param string $url Site URL to retrieve. + * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ function wp_remote_get($url, $args = array()) { @@ -182,12 +173,13 @@ function wp_remote_get($url, $args = array()) { /** * Retrieve the raw response from the HTTP request using the POST method. * - * @see wp_remote_request() For more information on the response array format and default arguments. - * * @since 2.7.0 * - * @param string $url Site URL to retrieve. - * @param array $args Optional. Override the defaults. + * @see wp_remote_request() For more information on the response array format. + * @see WP_Http::request() For default arguments information. + * + * @param string $url Site URL to retrieve. + * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ function wp_remote_post($url, $args = array()) { @@ -198,12 +190,13 @@ function wp_remote_post($url, $args = array()) { /** * Retrieve the raw response from the HTTP request using the HEAD method. * - * @see wp_remote_request() For more information on the response array format and default arguments. - * * @since 2.7.0 * - * @param string $url Site URL to retrieve. - * @param array $args Optional. Override the defaults. + * @see wp_remote_request() For more information on the response array format. + * @see WP_Http::request() For default arguments information. + * + * @param string $url Site URL to retrieve. + * @param array $args Optional. Request arguments. Default empty array. * @return WP_Error|array The response or WP_Error on failure. */ function wp_remote_head($url, $args = array()) {