[ XREF Home ] [ Index ]

PHP Cross Reference of WordPress Trunk

Provided by Yoast

title

Body

[close]

/wp-includes/ -> class-http.php (summary)

Simple and uniform HTTP request API. Standardizes the HTTP requests for WordPress. Handles cookies, gzip encoding and decoding, chunk decoding, if HTTP 1.1 and various other difficult HTTP protocol implementations.

File Size: 1725 lines (56 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 7 classes

WP_Http:: (11 methods):
  request()
  _get_first_available_transport()
  _dispatch_request()
  post()
  get()
  head()
  processResponse()
  processHeaders()
  buildCookieHeader()
  chunkTransferDecode()
  block_request()

WP_Http_Fsockopen:: (2 methods):
  request()
  test()

WP_Http_Streams:: (2 methods):
  request()
  test()

WP_Http_Curl:: (3 methods):
  request()
  stream_headers()
  test()

WP_HTTP_Proxy:: (9 methods):
  is_enabled()
  use_authentication()
  host()
  port()
  username()
  password()
  authentication()
  authentication_header()
  send_through_proxy()

WP_Http_Cookie:: (4 methods):
  __construct()
  test()
  getHeaderValue()
  getFullHeader()

WP_Http_Encoding:: (7 methods):
  compress()
  decompress()
  compatible_gzinflate()
  accept_encoding()
  content_encoding()
  should_decode()
  is_available()


Class: WP_Http  - X-Ref

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.

request( $url, $args = array()   X-Ref
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.

param: string $url URI resource.
param: str|array $args Optional. Override the defaults.
return: array|object Array containing 'headers', 'body', 'response', 'cookies'. A WP_Error instance upon error

_get_first_available_transport( $args, $url = null )   X-Ref
Tests which transports are capable of supporting the request.

param: array $args Request arguments
param: string $url URL to Request
return: string|false Class name for the first transport that claims to support the request.  False if no transport claims to support the request.

_dispatch_request( $url, $args )   X-Ref
Dispatches a HTTP request to a supporting transport.

Tests each transport in order to find a transport which matches the request arguements.
Also caches the transport instance to be used later.

The order for blocking requests is cURL, Streams, and finally Fsockopen.
The order for non-blocking requests is cURL, Streams and Fsockopen().

There are currently issues with "localhost" not resolving correctly with DNS. This may cause
an error "failed to open stream: A connection attempt failed because the connected party did
not properly respond after a period of time, or established connection failed because [the]
connected host has failed to respond."

param: string $url URL to Request
param: array $args Request arguments
return: array|object Array containing 'headers', 'body', 'response', 'cookies'. A WP_Error instance upon error

post($url, $args = array()   X-Ref
Uses the POST HTTP method.

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

param: string $url URI resource.
param: str|array $args Optional. Override the defaults.
return: array|object Array containing 'headers', 'body', 'response', 'cookies'. A WP_Error instance upon error

get($url, $args = array()   X-Ref
Uses the GET HTTP method.

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

param: string $url URI resource.
param: str|array $args Optional. Override the defaults.
return: array|object Array containing 'headers', 'body', 'response', 'cookies'. A WP_Error instance upon error

head($url, $args = array()   X-Ref
Uses the HEAD HTTP method.

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

param: string $url URI resource.
param: str|array $args Optional. Override the defaults.
return: array|object Array containing 'headers', 'body', 'response', 'cookies'. A WP_Error instance upon error

processResponse($strResponse)   X-Ref
Parses the responses and splits the parts into headers and body.

param: string $strResponse The full response string
return: array Array with 'headers' and 'body' keys.

processHeaders($headers)   X-Ref
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.

param: string|array $headers
return: array Processed string headers. If duplicate headers are encountered,

buildCookieHeader( &$r )   X-Ref
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.

param: array $r Full array of args passed into ::request()

chunkTransferDecode($body)   X-Ref
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.

param: string $body Body content
return: string Chunked decoded body on success or raw body on failure.

block_request($uri)   X-Ref
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.

param: string $uri URI of url.
return: bool True to block, false to allow.

Class: WP_Http_Fsockopen  - X-Ref

HTTP request method uses fsockopen function to retrieve the url.

This would be the preferred method, but the fsockopen implementation has the most overhead of all
the HTTP transport implementations.

request($url, $args = array()   X-Ref
Send a HTTP request to a URI using fsockopen().

Does not support non-blocking mode.

param: string $url URI resource.
param: str|array $args Optional. Override the defaults.
return: array 'headers', 'body', 'cookies' and 'response' keys.

test( $args = array()   X-Ref
Whether this class can be used for retrieving an URL.

return: boolean False means this class can not be used, true means it can.

Class: WP_Http_Streams  - X-Ref

HTTP request method uses Streams to retrieve the url.

Requires PHP 5.0+ and uses fopen with stream context. Requires that 'allow_url_fopen' PHP setting
to be enabled.

Second preferred method for getting the URL, for PHP 5.

request($url, $args = array()   X-Ref
Send a HTTP request to a URI using streams with fopen().

param: string $url
param: str|array $args Optional. Override the defaults.
return: array 'headers', 'body', 'cookies' and 'response' keys.

test( $args = array()   X-Ref
Whether this class can be used for retrieving an URL.

return: boolean False means this class can not be used, true means it can.

Class: WP_Http_Curl  - X-Ref

HTTP request method uses Curl extension to retrieve the url.

Requires the Curl extension to be installed.

request($url, $args = array()   X-Ref
Send a HTTP request to a URI using cURL extension.

param: string $url
param: str|array $args Optional. Override the defaults.
return: array 'headers', 'body', 'cookies' and 'response' keys.

stream_headers( $handle, $headers )   X-Ref
Grab the headers of the cURL request

Each header is sent individually to this callback, so we append to the $header property for temporary storage

return: int

test( $args = array()   X-Ref
Whether this class can be used for retrieving an URL.

return: boolean False means this class can not be used, true means it can.

Class: WP_HTTP_Proxy  - X-Ref

Adds Proxy support to the WordPress HTTP API.

There are caveats to proxy support. It requires that defines be made in the wp-config.php file to
enable proxy support. There are also a few filters that plugins can hook into for some of the
constants.

Please note that only BASIC authentication is supported by most transports.
cURL MAY support more methods (such as NTLM authentication) depending on your environment.

The constants are as follows:
<ol>
<li>WP_PROXY_HOST - Enable proxy support and host for connecting.</li>
<li>WP_PROXY_PORT - Proxy port for connection. No default, must be defined.</li>
<li>WP_PROXY_USERNAME - Proxy username, if it requires authentication.</li>
<li>WP_PROXY_PASSWORD - Proxy password, if it requires authentication.</li>
<li>WP_PROXY_BYPASS_HOSTS - Will prevent the hosts in this list from going through the proxy.
You do not need to have localhost and the blog host in this list, because they will not be passed
through the proxy. The list should be presented in a comma separated list, wildcards using * are supported, eg. *.wordpress.org</li>
</ol>

An example can be as seen below.
<code>
define('WP_PROXY_HOST', '192.168.84.101');
define('WP_PROXY_PORT', '8080');
define('WP_PROXY_BYPASS_HOSTS', 'localhost, www.example.com, *.wordpress.org');
</code>

is_enabled()   X-Ref
Whether proxy connection should be used.

return: bool

use_authentication()   X-Ref
Whether authentication should be used.

return: bool

host()   X-Ref
Retrieve the host for the proxy server.

return: string

port()   X-Ref
Retrieve the port for the proxy server.

return: string

username()   X-Ref
Retrieve the username for proxy authentication.

return: string

password()   X-Ref
Retrieve the password for proxy authentication.

return: string

authentication()   X-Ref
Retrieve authentication string for proxy authentication.

return: string

authentication_header()   X-Ref
Retrieve header string for proxy authentication.

return: string

send_through_proxy( $uri )   X-Ref
Whether URL should be sent through the proxy server.

We want to keep localhost and the blog URL from being sent through the proxy server, because
some proxies can not handle this. We also have the constant available for defining other
hosts that won't be sent through the proxy.

param: string $uri URI to check.
return: bool True, to send through the proxy and false if, the proxy should not be used.

Class: WP_Http_Cookie  - X-Ref

Internal representation of a single cookie.

Returned cookies are represented using this class, and when cookies are set, if they are not
already a WP_Http_Cookie() object, then they are turned into one.

__construct( $data )   X-Ref
Sets up this cookie object.

The parameter $data should be either an associative array containing the indices names below
or a header string detailing it.

If it's an array, it should include the following elements:
<ol>
<li>Name</li>
<li>Value - should NOT be urlencoded already.</li>
<li>Expires - (optional) String or int (UNIX timestamp).</li>
<li>Path (optional)</li>
<li>Domain (optional)</li>
</ol>

param: string|array $data Raw cookie data.

test( $url )   X-Ref
Confirms that it's OK to send this cookie to the URL checked against.

Decision is based on RFC 2109/2965, so look there for details on validity.

param: string $url URL you intend to send this cookie to
return: boolean TRUE if allowed, FALSE otherwise.

getHeaderValue()   X-Ref
Convert cookie name and value back to header string.

return: string Header encoded cookie name and value.

getFullHeader()   X-Ref
Retrieve cookie header for usage in the rest of the WordPress HTTP API.

return: string

Class: WP_Http_Encoding  - X-Ref

Implementation for deflate and gzip transfer encodings.

Includes RFC 1950, RFC 1951, and RFC 1952.

compress( $raw, $level = 9, $supports = null )   X-Ref
Compress raw string using the deflate format.

Supports the RFC 1951 standard.

param: string $raw String to compress.
param: int $level Optional, default is 9. Compression level, 9 is highest.
param: string $supports Optional, not used. When implemented it will choose the right compression based on what the server supports.
return: string|bool False on failure.

decompress( $compressed, $length = null )   X-Ref
Decompression of deflated string.

Will attempt to decompress using the RFC 1950 standard, and if that fails
then the RFC 1951 standard deflate will be attempted. Finally, the RFC
1952 standard gzip decode will be attempted. If all fail, then the
original compressed string will be returned.

param: string $compressed String to decompress.
param: int $length The optional length of the compressed data.
return: string|bool False on failure.

compatible_gzinflate($gzData)   X-Ref
Decompression of deflated string while staying compatible with the majority of servers.

Certain Servers will return deflated data with headers which PHP's gziniflate()
function cannot handle out of the box. The following function lifted from
http://au2.php.net/manual/en/function.gzinflate.php#77336 will attempt to deflate
the various return forms used.

param: string $gzData String to decompress.
return: string|bool False on failure.

accept_encoding()   X-Ref
What encoding types to accept and their priority values.

return: string Types of encoding to accept.

content_encoding()   X-Ref
What enconding the content used when it was compressed to send in the headers.

return: string Content-Encoding string to send in the header.

should_decode($headers)   X-Ref
Whether the content be decoded based on the headers.

param: array|string $headers All of the available headers.
return: bool

is_available()   X-Ref
Whether decompression and compression are supported by the PHP version.

Each function is tested instead of checking for the zlib extension, to
ensure that the functions all exist in the PHP version and aren't
disabled.

return: bool



Generated: Wed Jun 1 08:30:02 2011 Cross-referenced by PHPXref 0.7
Provided by Yoast and awesome WordPress Hosting