TarzanHTTPRequest

Handles all linear and parallel HTTP requests using cURL.

Version

2008.11.03

Copyright

2006-2008 LifeNexus Digital, Inc., and contributors.

License

Simplified BSD Licensehttp://opensource.org/licenses/bsd-license.php

See Also

Tarzanhttp://tarzan-aws.com

TarzanHTTPRequest

Container for all request-related methods.  The naming convention for methods mimics those of PEAR’s HTTP_Request class.

Properties

request_url

The URL being requested.

request_headers

The headers being sent in the request.

request_body

The body being sent in the request.

response

The response returned by the request.

response_headers

The headers returned by the request.

response_body

The body returned by the request.

response_code

The HTTP status code returned by the request.

response_info

Additional response data.

curl_handle

The handle for the cURL object.

method

The method by which the request is being made.

proxy

Stores the proxy settings to use for the request.

username

The username to use for the request.

password

The password to use for the request.

utilities_class

The default class to use for Utilities (defaults to TarzanUtilities).

request_class

The default class to use for HTTP Requests (defaults to TarzanHTTPRequest).

response_class

The default class to use for HTTP Responses (defaults to TarzanHTTPResponse).

Functions

__construct()

public function __construct($url,  
$proxy =  null,
$helpers =  null)

The constructor

Access

public

Parameters

urlstring (Required) The URL to request or service endpoint to query.
proxystring (Optional) The faux-url to use for proxy settings.  Takes the following format: proxy://user:pass@hostname:port
helpersarray (Optional) An associative array of classnames to use for utilities, request, and response functionality.  Gets passed in automatically by the calling class.

Returns

void

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/httprequest/__construct.phps

setCredentials()

public function setCredentials($user,
$pass)

Sets the credentials to use for authentication.

Access

public

Parameters

userstring (Required) The username to authenticate with.
passstring (Required) The password to authenticate with.

Returns

void

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/httprequest/set_credentials.phps

addHeader()

public function addHeader($key,
$value)

Adds a custom HTTP header to the cURL request.

Access

public

Parameters

keystring (Required) The custom HTTP header to set.
valuemixed (Required) The value to assign to the custom HTTP header.

Returns

void

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/httprequest/add_header.phps

removeHeader()

public function removeHeader($key)

Removes an HTTP header from the cURL request.

Access

public

Parameters

keystring (Required) The custom HTTP header to set.

Returns

void

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/httprequest/remove_header.phps

setMethod()

public function setMethod($method)

Set the method type for the request.

Access

public

Parameters

methodstring (Required) One of the following constants: HTTP_GET, HTTP_POST, HTTP_PUT, HTTP_HEAD, HTTP_DELETE.

Returns

void

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/httprequest/set_method.phps

setBody()

public function setBody($body)

Set the body to send in the request.

Access

public

Parameters

bodystring (Required) The textual content to send along in the body of the request.

Returns

void

See Also

Example Usagehttp://tarzan-aws.com/docs/examples/httprequest/set_body.phps

prepRequest()

public function prepRequest()

Prepares and adds the details of the cURL request.  This can be passed along to a curl_multi_exec() function.

Access

public

Returns

The handle for the cURL object.

processResponse()

public function processResponse($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.

Access

public

Parameters

curl_handlestring (Optional) The reference to the already executed cURL request.
responsestring (Optional) The actual response content itself that needs to be parsed.

Returns

TarzanHTTPResponse object

sendRequest()

public function sendRequest()

Sends the request, calling necessary utility functions to update built-in properties.

Access

public

Returns

string The resulting unparsed data from the request.

See Also

RelatedsendMultiRequest()
Example Usagehttp://tarzan-aws.com/docs/examples/httprequest/send_request.phps

sendMultiRequest()

public function sendMultiRequest($handles)

Sends the request using curl_multi_exec(), enabling parallel requests.

Access

public

Parameters

handlesarray (Required) An indexed array of cURL handles to process simultaneously.

Returns

array Post-processed cURL responses.

See Also

RelatedsendRequest()
Example Usagehttp://tarzan-aws.com/docs/examples/httprequest/send_multi_request.phps

getResponseHeader()

public function getResponseHeader($header =  null)

Get the HTTP response headers from the request.

Access

public

Parameters

headerstring (Optional) A specific header value to return.  Defaults to all headers.

Returns

string | array All or selected header values.

See Also

RelatedgetResponseBody(), getResponseCode()
Example Usagehttp://tarzan-aws.com/docs/examples/httprequest/get_response_header.phps

getResponseBody()

public function getResponseBody()

Get the HTTP response body from the request.

Access

public

Returns

string The response body.

See Also

RelatedgetResponseHeader(), getResponseCode()
Example Usagehttp://tarzan-aws.com/docs/examples/httprequest/get_response_body.phps

getResponseCode()

public function getResponseCode()

Get the HTTP response code from the request.

Access

public

Returns

string The HTTP response code.

See Also

RelatedgetResponseHeader(), getResponseBody()
Example Usagehttp://tarzan-aws.com/docs/examples/httprequest/get_response_code.phps