Class WP_Http

Description

WordPress HTTP Class for managing HTTP Transports and making HTTP requests.

This class is called for the functionality of making HTTP requests and replaces Snoopy functionality. There is no available functionality to add HTTP transport implementations, since most of the HTTP transports are added and available for use.

There are no properties, because none are needed and for performance reasons. Some of the functions are static and while they do have some overhead over functions in PHP4, the purpose is maintainability. When PHP5 is finally the requirement, it will be easy to add the static keyword to the code. It is not as easy to convert a function to a method after enough code uses the old way.

Debugging includes several actions, which pass different variables for debugging the HTTP API.

  • since: 2.7.0

Located in /wp-includes/class-http.php (line 34)


	
			
Method Summary
static void buildCookieHeader ( &$r, array $r)
static string chunkTransferDecode (string $body)
static array processHeaders (string|array $headers)
static array processResponse (string $strResponse)
bool block_request (string $uri)
array|object Array get (string $url, [str|array $args = array()])
array|object Array head (string $url, [str|array $args = array()])
array|object Array post (string $url, [str|array $args = array()])
array|object Array request (string $url, [str|array $args = array()])
string|false _get_first_available_transport (array $args, [string $url = null])
Methods
static method buildCookieHeader (line 415)

Takes the arguments for a ::request() and checks for the cookie array.

If it's found, then it's assumed to contain WP_Http_Cookie objects, which are each parsed into strings and added to the Cookie: header (within the arguments array). Edits the array by reference.

  • version: 2.8.0
  • access: public
static void buildCookieHeader ( &$r, array $r)
  • array $r: Full array of args passed into ::request()
  • &$r
static method chunkTransferDecode (line 440)

Decodes chunk transfer-encoding, based off the HTTP 1.1 specification.

Based off the HTTP http_encoding_dechunk function. Does not support UTF-8. Does not support returning footer headers. Shouldn't be too difficult to support it though.

  • return: Chunked decoded body on success or raw body on failure.
  • todo: Add support for footer chunked headers.
  • since: 2.7.0
  • access: public
static string chunkTransferDecode (string $body)
  • string $body: Body content
static method processHeaders (line 348)

Transform header string into an array.

If an array is given then it is assumed to be raw header data with numeric keys with the headers as the values. No headers must be passed that were already processed.

  • return: Processed string headers. If duplicate headers are encountered, Then a numbered array is returned as the value of that header-key.
  • since: 2.7.0
  • access: public
static array processHeaders (string|array $headers)
  • string|array $headers
static method processResponse (line 328)

Parses the responses and splits the parts into headers and body.

  • return: Array with 'headers' and 'body' keys.
  • since: 2.7.0
  • access: public
static array processResponse (string $strResponse)
  • string $strResponse: The full response string
block_request (line 491)

Block requests through the proxy.

Those who are behind a proxy and want to prevent access to certain hosts may do so. This will prevent plugins from working and core functionality, if you don't include api.wordpress.org.

You block external URL requests by defining WP_HTTP_BLOCK_EXTERNAL as true in your wp-config.php file and this will only allow localhost and your blog to make requests. The constant WP_ACCESSIBLE_HOSTS will allow additional hosts to go through for requests. The format of the WP_ACCESSIBLE_HOSTS constant is a comma separated list of hostnames to allow, wildcard domains are supported, eg *.wordpress.org will allow for all subdomains of wordpress.org to be contacted.

bool block_request (string $uri)
  • string $uri: URI of url.
get (line 294)

Uses the GET HTTP method.

Used for sending data that is expected to be in the body.

  • return: containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
  • since: 2.7.0
  • access: public
array|object Array get (string $url, [str|array $args = array()])
  • string $url: URI resource.
  • str|array $args: Optional. Override the defaults.
head (line 312)

Uses the HEAD HTTP method.

Used for sending data that is expected to be in the body.

  • return: containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
  • since: 2.7.0
  • access: public
array|object Array head (string $url, [str|array $args = array()])
  • string $url: URI resource.
  • str|array $args: Optional. Override the defaults.
post (line 276)

Uses the POST HTTP method.

Used for sending data that is expected to be in the body.

  • return: containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
  • since: 2.7.0
  • access: public
array|object Array post (string $url, [str|array $args = array()])
  • string $url: URI resource.
  • str|array $args: Optional. Override the defaults.
request (line 81)

Send a 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. HTTP and HTTPS are assumed so the server might not know how to handle the send headers. Other protocols are unsupported and most likely will fail.

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. Version 1.1 is not supported, because of chunk response. 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.

'blocking' is the default, which is used to tell the transport, whether it should halt PHP while it performs the request or continue regardless. Actually, that isn't entirely correct. Blocking mode really just means whether the fread should just pull what it can whenever it gets bytes or if it should wait until it has enough in the buffer to read or finishes reading the entire content. It doesn't actually always mean that PHP will continue going after making the request.

  • return: containing 'headers', 'body', 'response', 'cookies', 'filename'. A WP_Error instance upon error
  • todo: Refactor this code. The code in this method extends the scope of its original purpose and should be refactored to allow for cleaner abstraction and reduce duplication of the code. One suggestion is to create a class specifically for the arguments, however preliminary refactoring to this affect has affect more than just the scope of the arguments. Something to ponder at least.
  • since: 2.7.0
  • access: public
array|object Array request (string $url, [str|array $args = array()])
  • string $url: URI resource.
  • str|array $args: Optional. Override the defaults.
_get_first_available_transport (line 205)

Tests which transports are capable of supporting the request.

  • return: Class name for the first transport that claims to support the request. False if no transport claims to support the request.
  • since: 3.2.0
  • access: public
string|false _get_first_available_transport (array $args, [string $url = null])
  • array $args: Request arguments
  • string $url: URL to Request

Documentation generated on Fri, 01 Aug 2014 01:34:43 +0100 by phpDocumentor 1.4.3