[ Index ] |
PHP Cross Reference of BackPress |
[Source view] [Print] [Project Stats]
Simple and uniform HTTP request API. Will eventually replace and standardize the WordPress HTTP requests made.
Author: | Jacob Santos <wordpress@santosj.name> |
File Size: | 2052 lines (66 kb) |
Included or required: | 0 times |
Referenced: | 0 times |
Includes or requires: | 0 files |
WP_Http:: (13 methods):
WP_Http()
__construct()
_getTransport()
_postTransport()
request()
post()
get()
head()
processResponse()
processHeaders()
buildCookieHeader()
chunkTransferDecode()
block_request()
WP_Http_Fsockopen:: (2 methods):
request()
test()
WP_Http_Fopen:: (2 methods):
request()
test()
WP_Http_Streams:: (2 methods):
request()
test()
WP_Http_ExtHTTP:: (2 methods):
request()
test()
WP_Http_Curl:: (2 methods):
request()
test()
WP_HTTP_Proxy:: (9 methods):
is_enabled()
use_authentication()
host()
port()
username()
password()
authentication()
authentication_header()
send_through_proxy()
WP_Http_Cookie:: (5 methods):
WP_Http_Cookie()
__construct()
test()
getHeaderValue()
getFullHeader()
WP_Http_Encoding:: (16 methods):
compress()
decompress()
accept_encoding()
content_encoding()
should_decode()
is_available()
_wp_http_get_object()
wp_remote_request()
wp_remote_get()
wp_remote_post()
wp_remote_head()
wp_remote_retrieve_headers()
wp_remote_retrieve_header()
wp_remote_retrieve_response_code()
wp_remote_retrieve_response_message()
wp_remote_retrieve_body()
WP_Http() X-Ref |
PHP4 style Constructor - Calls PHP5 Style Constructor return: WP_Http since: 2.7.0 |
__construct() X-Ref |
PHP5 style Constructor - Setup available transport if not available. PHP4 does not have the 'self' keyword and since WordPress supports PHP4, the class needs to be used for the static call. The transport are setup to save time. This should only be called once, so the overhead should be fine. return: WP_Http since: 2.7.0 |
_getTransport( $args = array() X-Ref |
Tests the WordPress HTTP objects for an object to use and returns it. Tests all of the objects and returns the object that passes. Also caches that object to be used later. The order for the GET/HEAD requests are HTTP Extension, FSockopen Streams, Fopen, and finally cURL. Whilst Fsockopen has the highest overhead, Its used 2nd due to high compatibility with most hosts, The HTTP Extension is tested first due to hosts which have it enabled, are likely to work correctly with it. 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 connected host has failed to respond." return: object|null Null if no transports are available, HTTP transport object. param: array $args Request args, default us an empty array since: 2.7.0 |
_postTransport( $args = array() X-Ref |
Tests the WordPress HTTP objects for an object to use and returns it. Tests all of the objects and returns the object that passes. Also caches that object to be used later. This is for posting content to a URL and is used when there is a body. The plain Fopen Transport can not be used to send content, but the streams transport can. This is a limitation that is addressed here, by just not including that transport. return: object|null Null if no transports are available, HTTP transport object. param: array $args Request args, default us an empty array since: 2.7.0 |
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. return: array containing 'headers', 'body', 'response', 'cookies' param: string $url URI resource. param: str|array $args Optional. Override the defaults. since: 2.7.0 |
post($url, $args = array() X-Ref |
Uses the POST HTTP method. Used for sending data that is expected to be in the body. return: boolean param: string $url URI resource. param: str|array $args Optional. Override the defaults. since: 2.7.0 |
get($url, $args = array() X-Ref |
Uses the GET HTTP method. Used for sending data that is expected to be in the body. return: boolean param: string $url URI resource. param: str|array $args Optional. Override the defaults. since: 2.7.0 |
head($url, $args = array() X-Ref |
Uses the HEAD HTTP method. Used for sending data that is expected to be in the body. return: boolean param: string $url URI resource. param: str|array $args Optional. Override the defaults. since: 2.7.0 |
processResponse($strResponse) X-Ref |
Parses the responses and splits the parts into headers and body. return: array Array with 'headers' and 'body' keys. param: string $strResponse The full response string since: 2.7.0 |
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. return: array Processed string headers. If duplicate headers are encountered, param: string|array $headers since: 2.7.0 |
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. return: string Chunked decoded body on success or raw body on failure. param: string $body Body content since: 2.7.0 |
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 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. return: bool True to block, false to allow. param: string $uri URI of url. since: 2.8.0 |
Class: WP_Http_Fsockopen - X-Ref
HTTP request method uses fsockopen function to retrieve the url.request($url, $args = array() X-Ref |
Send a HTTP request to a URI using fsockopen(). Does not support non-blocking mode. return: array 'headers', 'body', 'cookies' and 'response' keys. param: string $url URI resource. param: str|array $args Optional. Override the defaults. since: 2.7 |
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. since: 2.7.0 |
Class: WP_Http_Fopen - X-Ref
HTTP request method uses fopen function to retrieve the url.request($url, $args = array() X-Ref |
Send a HTTP request to a URI using fopen(). This transport does not support sending of headers and body, therefore should not be used in the instances, where there is a body and headers. Notes: Does not support non-blocking mode. Ignores 'redirection' option. return: array 'headers', 'body', 'cookies' and 'response' keys. param: string $url URI resource. param: str|array $args Optional. Override the defaults. since: 2.7.0 |
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. since: 2.7.0 |
Class: WP_Http_Streams - X-Ref
HTTP request method uses Streams to retrieve the url.request($url, $args = array() X-Ref |
Send a HTTP request to a URI using streams with fopen(). return: array 'headers', 'body', 'cookies' and 'response' keys. param: string $url param: str|array $args Optional. Override the defaults. since: 2.7.0 |
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. since: 2.7.0 |
Class: WP_Http_ExtHTTP - X-Ref
HTTP request method uses HTTP extension to retrieve the url.request($url, $args = array() X-Ref |
Send a HTTP request to a URI using HTTP extension. Does not support non-blocking. return: array 'headers', 'body', 'cookies' and 'response' keys. param: string $url param: str|array $args Optional. Override the defaults. since: 2.7 |
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. since: 2.7.0 |
Class: WP_Http_Curl - X-Ref
HTTP request method uses Curl extension to retrieve the url.request($url, $args = array() X-Ref |
Send a HTTP request to a URI using cURL extension. return: array 'headers', 'body', 'cookies' and 'response' keys. param: string $url param: str|array $args Optional. Override the defaults. since: 2.7.0 |
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. since: 2.7.0 |
Class: WP_HTTP_Proxy - X-Ref
Adds Proxy support to the WordPress HTTP API.is_enabled() X-Ref |
Whether proxy connection should be used. return: bool since: 2.8 |
use_authentication() X-Ref |
Whether authentication should be used. return: bool since: 2.8 |
host() X-Ref |
Retrieve the host for the proxy server. return: string since: 2.8 |
port() X-Ref |
Retrieve the port for the proxy server. return: string since: 2.8 |
username() X-Ref |
Retrieve the username for proxy authentication. return: string since: 2.8 |
password() X-Ref |
Retrieve the password for proxy authentication. return: string since: 2.8 |
authentication() X-Ref |
Retrieve authentication string for proxy authentication. return: string since: 2.8 |
authentication_header() X-Ref |
Retrieve header string for proxy authentication. return: string since: 2.8 |
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. return: bool True, to send through the proxy and false if, the proxy should not be used. param: string $uri URI to check. since: unknown |
Class: WP_Http_Cookie - X-Ref
Internal representation of a single cookie.WP_Http_Cookie( $data ) X-Ref |
PHP4 style Constructor - Calls PHP5 Style Constructor. param: string|array $data Raw cookie data. since: 2.8.0 |
__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. since: 2.8.0 |
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. return: boolean TRUE if allowed, FALSE otherwise. param: string $url URL you intend to send this cookie to since: 2.8.0 |
getHeaderValue() X-Ref |
Convert cookie name and value back to header string. return: string Header encoded cookie name and value. since: 2.8.0 |
getFullHeader() X-Ref |
Retrieve cookie header for usage in the rest of the WordPress HTTP API. return: string since: 2.8.0 |
Class: WP_Http_Encoding - X-Ref
Implementation for deflate and gzip transfer encodings.compress( $raw, $level = 9, $supports = null ) X-Ref |
Compress raw string using the deflate format. Supports the RFC 1951 standard. return: string|bool False on failure. 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. since: 2.8 |
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. return: string|bool False on failure. param: string $compressed String to decompress. param: int $length The optional length of the compressed data. since: 2.8 |
accept_encoding() X-Ref |
What encoding types to accept and their priority values. return: string Types of encoding to accept. since: 2.8 |
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. since: 2.8 |
should_decode($headers) X-Ref |
Whether the content be decoded based on the headers. return: bool param: array|string $headers All of the available headers. since: 2.8 |
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 since: 2.8 |
_wp_http_get_object() X-Ref |
Returns the initialized WP_Http Object return: WP_Http HTTP Transport object. since: 2.7.0 |
wp_remote_request($url, $args = array() X-Ref |
Retrieve the raw response from the HTTP request. The array structure is a little complex. <code> $res = array( 'headers' => array(), 'response' => array('code' => int, 'message' => string) ); </code> 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. <code> $user_agent = $res['headers']['user-agent']; </code> 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. return: WP_Error|array The response or WP_Error on failure. param: string $url Site URL to retrieve. param: array $args Optional. Override the defaults. since: 2.7.0 |
wp_remote_get($url, $args = array() X-Ref |
Retrieve the raw response from the HTTP request using the GET method. return: WP_Error|array The response or WP_Error on failure. param: string $url Site URL to retrieve. param: array $args Optional. Override the defaults. since: 2.7.0 |
wp_remote_post($url, $args = array() X-Ref |
Retrieve the raw response from the HTTP request using the POST method. return: WP_Error|array The response or WP_Error on failure. param: string $url Site URL to retrieve. param: array $args Optional. Override the defaults. since: 2.7.0 |
wp_remote_head($url, $args = array() X-Ref |
Retrieve the raw response from the HTTP request using the HEAD method. return: WP_Error|array The response or WP_Error on failure. param: string $url Site URL to retrieve. param: array $args Optional. Override the defaults. since: 2.7.0 |
wp_remote_retrieve_headers(&$response) X-Ref |
Retrieve only the headers from the raw response. return: array The headers of the response. Empty array if incorrect parameter given. param: array $response HTTP response. since: 2.7.0 |
wp_remote_retrieve_header(&$response, $header) X-Ref |
Retrieve a single header by name from the raw response. return: string The header value. Empty string on if incorrect parameter given, or if the header doesnt exist. param: array $response param: string $header Header name to retrieve value from. since: 2.7.0 |
wp_remote_retrieve_response_code(&$response) X-Ref |
Retrieve only the response code from the raw response. Will return an empty array if incorrect parameter value is given. return: string the response code. Empty string on incorrect parameter given. param: array $response HTTP response. since: 2.7.0 |
wp_remote_retrieve_response_message(&$response) X-Ref |
Retrieve only the response message from the raw response. Will return an empty array if incorrect parameter value is given. return: string The response message. Empty string on incorrect parameter given. param: array $response HTTP response. since: 2.7.0 |
wp_remote_retrieve_body(&$response) X-Ref |
Retrieve only the body from the raw response. return: string The body of the response. Empty string if no body or incorrect parameter given. param: array $response HTTP response. since: 2.7.0 |
Generated: Sat Nov 23 01:00:54 2024 | Cross-referenced by PHPXref 0.7.1 |