Handles all linear and parallel HTTP requests using cURL and manages the responses.
2009.12.17
2006-2009 LifeNexus Digital, Inc., and contributors.
| Simplified BSD License | http://opensource.org/licenses/bsd-license.php |
HTTP method type: Get
HTTP method type: Post
HTTP method type: Put
HTTP method type: Delete
HTTP method type: Head
Container for all request-related methods.
The URL being requested.
The headers being sent in the request.
The body being sent in the request.
The response returned by the request.
The headers returned by the request.
The body returned by the request.
The HTTP status code returned by the request.
Additional response data.
The handle for the cURL object.
The method by which the request is being made.
Stores the proxy settings to use for the request.
The username to use for the request.
The password to use for the request.
Custom CURLOPT settings.
The default class to use for HTTP Requests (defaults to RequestCore).
The default class to use for HTTP Responses (defaults to ResponseCore).
Default useragent string to use.
public function __construct( $url = null, $proxy = null, $helpers = null )
The constructor
public
| url | string (Optional) The URL to request or service endpoint to query. |
| proxy | string (Optional) The faux-url to use for proxy settings. Takes the following format: proxy://user:pass@hostname:port |
| helpers | array (Optional) An associative array of classnames to use for request, and response functionality. Gets passed in automatically by the calling class. |
$this
public function set_credentials( $user, $pass )
Sets the credentials to use for authentication.
public
| user | string (Required) The username to authenticate with. |
| pass | string (Required) The password to authenticate with. |
$this
public function add_header( $key, $value )
Adds a custom HTTP header to the cURL request.
public
| key | string (Required) The custom HTTP header to set. |
| value | mixed (Required) The value to assign to the custom HTTP header. |
$this
public function remove_header( $key )
Removes an HTTP header from the cURL request.
public
| key | string (Required) The custom HTTP header to set. |
$this
public function set_method( $method )
Set the method type for the request.
public
| method | string (Required) One of the following constants: HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_HEAD, HTTP_DELETE. |
$this
public function set_useragent( $ua )
Sets a custom useragent string for the class.
public
| method | string (Required) The useragent string to use. |
$this
public function set_body( $body )
Set the body to send in the request.
public
| body | string (Required) The textual content to send along in the body of the request. |
$this
public function set_request_url( $url )
Set the URL to make the request to.
public
| body | string (Required) The textual content to send along in the body of the request. |
$this
public function set_curlopts( $curlopts )
Set additional CURLOPT settings. These will merge with the default settings, and override if there is a duplicate.
public
| curlopts | array (Optional) A set of key-value pairs that set CURLOPT options. These will merge with the existing CURLOPTs, and ones passed here will override the defaults. Keys should be the CURLOPT_* constants, not strings. |
$this
public function set_proxy( $proxy )
Set the proxy to use for making requests.
public
| proxy | string (Optional) The faux-url to use for proxy settings. Takes the following format: proxy://user:pass@hostname:port |
$this
public function prep_request()
Prepares and adds the details of the cURL request. This can be passed along to a curl_multi_exec() function.
public
The handle for the cURL object.
public function process_response( $curl_handle = null, $response = null )
Take the post-processed cURL data and break it down into useful header/body/info chunks. Uses the data stored in the curl_handle and response properties unless replacement data is passed in via parameters.
public
| curl_handle | string (Optional) The reference to the already executed cURL request. |
| response | string (Optional) The actual response content itself that needs to be parsed. |
ResponseCore object
public function send_request( $parse = false )
Sends the request, calling necessary utility functions to update built-in properties.
public
| parse | boolean (Optional) Whether to parse the response with ResponseCore or not. |
string The resulting unparsed data from the request.
public function send_multi_request( $handles )
Sends the request using curl_multi_exec(), enabling parallel requests.
public
| handles | array (Required) An indexed array of cURL handles to process simultaneously. |
array Post-processed cURL responses.
public function get_response_header( $header = null )
Get the HTTP response headers from the request.
public
| header | string (Optional) A specific header value to return. Defaults to all headers. |
string | array All or selected header values.
public function get_response_body()
Get the HTTP response body from the request.
public
string The response body.
public function get_response_code()
Get the HTTP response code from the request.
public
string The HTTP response code.
Container for all response-related methods.
Stores the HTTP header information.
Stores the SimpleXML response.
Stores the HTTP response code.
public function __construct( $header, $body, $status = null )
The constructor
public
| header | array (Required) Associative array of HTTP headers (typically returned by <RequestCore::getResponseHeader()>). |
| body | string (Required) XML-formatted response from AWS. |
| status | integer (Optional) HTTP response status code from the request. |
object Contains an array ‘header’ property (HTTP headers as an associative array), a SimpleXMLElement or string ‘body’ property, and an integer ‘status’ code.
public function isOK( $codes = array(200, 201, 204) )
Did we receive the status code we expected?
public
| codes | integer|array (Optional) The status code(s) to expect. Pass an integer for a single acceptable value, or an array of integers for multiple acceptable values. Defaults to array 200|204. |
boolean Whether we received the expected status code or not.