HttpSocket Class Reference

Inheritance diagram for HttpSocket:

CakeSocket Object List of all members.

Public Member Functions

 __construct ($config=array())
 __tokenEscapeChars ($hex=true, $chars=null)
 buildCookies ($cookies)
 buildHeader ($header, $mode= 'standard')
 buildRequestLine ($request=array(), $versionToken= 'HTTP/1.1')
 buildUri ($uri=array(), $uriTemplate= '%scheme://%user:%pass @%host:%port/%path?%query#%fragment')
 configUri ($uri=null)
 decodeBody ($body, $encoding= 'chunked')
 decodeChunkedBody ($body)
 delete ($uri=null, $data=array(), $request=array())
 escapeToken ($token, $chars=null)
 get ($uri=null, $query=array(), $request=array())
 httpSerialize ($data=array())
 loadCookies ()
 parseCookies ($header)
 parseHeader ($header)
 parseQuery ($query)
 parseResponse ($message)
 parseUri ($uri=null, $base=array())
 post ($uri=null, $data=array(), $request=array())
 put ($uri=null, $data=array(), $request=array())
 request ($request=array())
 reset ($full=true)
 saveCookies ()
 unescapeToken ($token, $chars=null)
 url ($url=null, $uriTemplate=null)

Public Attributes

 $config
 $description = 'HTTP-based DataSource Interface'
 $lineBreak = "\r\n"
 $quirksMode = false
 $request
 $response

Detailed Description

Definition at line 34 of file http_socket.php.


Constructor & Destructor Documentation

HttpSocket::__construct ( config = array()  ) 

Build an HTTP Socket using the specified configuration.

Parameters:
array $config Configuration

Reimplemented from CakeSocket.

Definition at line 144 of file http_socket.php.

References $config, __construct(), config(), configUri(), Set::merge(), and request().


Member Function Documentation

HttpSocket::__tokenEscapeChars ( hex = true,
chars = null 
)

Gets escape chars according to RFC 2616 (HTTP 1.1 specs).

Parameters:
boolean $hex true to get them as HEX values, false otherwise
Returns:
array Escape chars private
Todo:
Test $chars parameter

Definition at line 949 of file http_socket.php.

HttpSocket::buildCookies ( cookies  ) 

undocumented function

Parameters:
unknown $cookies
Returns:
void public
Todo:
Refactor token escape mechanism to be configurable

Definition at line 889 of file http_socket.php.

Referenced by request().

HttpSocket::buildHeader ( header,
mode = 'standard' 
)

Builds the header.

Parameters:
array $header Header to build
Returns:
string Header built from array protected

Definition at line 769 of file http_socket.php.

Referenced by parseResponse(), and request().

HttpSocket::buildRequestLine ( request = array(),
versionToken = 'HTTP/1.1' 
)

Builds a request line according to HTTP/1.1 specs. Activate quirks mode to work outside specs.

Parameters:
array $request Needs to contain a 'uri' key. Should also contain a 'method' key, otherwise defaults to GET.
string $versionToken The version token to use, defaults to HTTP/1.1
Returns:
string Request line protected

Definition at line 720 of file http_socket.php.

Referenced by request().

HttpSocket::buildUri ( uri = array(),
uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment' 
)

Takes a $uri array and turns it into a fully qualified URL string

Parameters:
array $uri A $uri array, or uses $this->config if left empty
string $uriTemplate The Uri template/format to use
Returns:
string A fully qualified URL formated according to $uriTemplate protected

Definition at line 552 of file http_socket.php.

References CakeSocket::host().

Referenced by get(), and url().

HttpSocket::configUri ( uri = null  ) 

Parses and sets the specified URI into current request configuration.

Parameters:
mixed $uri URI (see parseUri())
Returns:
array Current configuration settings protected

Definition at line 519 of file http_socket.php.

References $config, config(), CakeSocket::host(), Set::merge(), parseUri(), and request().

Referenced by __construct(), and request().

HttpSocket::decodeBody ( body,
encoding = 'chunked' 
)

Generic function to decode a $body with a given $encoding. Returns either an array with the keys 'body' and 'header' or false on failure.

Parameters:
string $body A string continaing the body to decode
mixed $encoding Can be false in case no encoding is being used, or a string representing the encoding
Returns:
mixed Array or false protected

Definition at line 433 of file http_socket.php.

References __(), and error().

Referenced by parseResponse().

HttpSocket::decodeChunkedBody ( body  ) 

Decodes a chunked message $body and returns either an array with the keys 'body' and 'header' or false as a result.

Parameters:
string $body A string continaing the chunked body to decode
Returns:
mixed Array or false protected

Todo:
See if there are popular chunk extensions we should implement

Definition at line 458 of file http_socket.php.

References __(), and parseHeader().

HttpSocket::delete ( uri = null,
data = array(),
request = array() 
)

Issues a DELETE request to the specified URI, query, and request.

Parameters:
mixed $uri URI to request (see parseUri())
array $query Query to append to URI
array $request An indexed array with indexes such as 'method' or uri
Returns:
mixed Result of request public

Definition at line 324 of file http_socket.php.

References $request, Set::merge(), and request().

HttpSocket::escapeToken ( token,
chars = null 
)

Escapes a given $token according to RFC 2616 (HTTP 1.1 specs)

Parameters:
string $token Token to escape
Returns:
string Escaped token protected
Todo:
Test $chars parameter

Definition at line 936 of file http_socket.php.

HttpSocket::get ( uri = null,
query = array(),
request = array() 
)

Issues a GET request to the specified URI, query, and request.

Parameters:
mixed $uri URI to request (see parseUri())
array $query Query to append to URI
array $request An indexed array with indexes such as 'method' or uri
Returns:
mixed Result of request public

Definition at line 274 of file http_socket.php.

References $request, buildUri(), Set::merge(), parseUri(), and request().

HttpSocket::httpSerialize ( data = array()  ) 

Serializes an array for transport.

Parameters:
array $data Data to serialize
Returns:
string Serialized variable protected

Definition at line 753 of file http_socket.php.

Referenced by request().

HttpSocket::loadCookies (  ) 

undocumented function

Returns:
void public

Definition at line 912 of file http_socket.php.

HttpSocket::parseCookies ( header  ) 

undocumented function

Parameters:
unknown $header
Returns:
void public
Todo:
Make this 100% RFC 2965 confirm

Definition at line 848 of file http_socket.php.

Referenced by parseResponse().

HttpSocket::parseHeader ( header  ) 

Parses an array based header.

Parameters:
array $header Header as an indexed array (field => value)
Returns:
array Parsed header protected

Definition at line 798 of file http_socket.php.

Referenced by decodeChunkedBody(), parseResponse(), and request().

HttpSocket::parseQuery ( query  ) 

This function can be thought of as a reverse to PHP5's http_build_query(). It takes a given query string and turns it into an array and supports nesting by using the php bracket syntax. So this menas you can parse queries like:

A leading '?' mark in $query is optional and does not effect the outcome of this function. For the complete capabilities of this implementation take a look at HttpSocketTest::testParseQuery()

Parameters:
mixed $query A query string to parse into an array or an array to return directly "as is"
Returns:
array The $query parsed into a possibly multi-level array. If an empty $query is given, an empty array is returned. protected

Definition at line 663 of file http_socket.php.

HttpSocket::parseResponse ( message  ) 

Parses the given message and breaks it down in parts.

Parameters:
string $message Message to parse
Returns:
array Parsed message (with indexed elements such as raw, status, header, body) protected

Definition at line 370 of file http_socket.php.

References $response, buildHeader(), decodeBody(), parseCookies(), and parseHeader().

Referenced by request().

HttpSocket::parseUri ( uri = null,
base = array() 
)

Parses the given URI and breaks it down into pieces as an indexed array with elements such as 'scheme', 'port', 'query'.

Parameters:
string $uri URI to parse
mixed $base If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc.
Returns:
array Parsed URI protected

Definition at line 599 of file http_socket.php.

Referenced by configUri(), get(), request(), and url().

HttpSocket::post ( uri = null,
data = array(),
request = array() 
)

Issues a POST request to the specified URI, query, and request.

Parameters:
mixed $uri URI to request (see parseUri())
array $query Query to append to URI
array $request An indexed array with indexes such as 'method' or uri
Returns:
mixed Result of request public

Definition at line 298 of file http_socket.php.

References $request, Set::merge(), and request().

HttpSocket::put ( uri = null,
data = array(),
request = array() 
)

Issues a PUT request to the specified URI, query, and request.

Parameters:
mixed $uri URI to request (see parseUri())
array $query Query to append to URI
array $request An indexed array with indexes such as 'method' or uri
Returns:
mixed Result of request public

Definition at line 311 of file http_socket.php.

References $request, Set::merge(), and request().

HttpSocket::request ( request = array()  ) 

Issue the specified request.

Parameters:
mixed $request Either an URI string, or an array defining host/uri
Returns:
mixed false on error, request body on success public

Definition at line 163 of file http_socket.php.

References $request, $response, buildCookies(), buildHeader(), buildRequestLine(), close(), config(), configUri(), CakeSocket::disconnect(), CakeSocket::host(), httpSerialize(), Set::merge(), parseHeader(), parseResponse(), parseUri(), CakeSocket::read(), reset(), url(), and CakeSocket::write().

Referenced by __construct(), configUri(), delete(), get(), post(), put(), and url().

HttpSocket::reset ( full = true  ) 

Resets the state of this HttpSocket instance to it's initial state (before Object::__construct got executed) or does the same thing partially for the request and the response property only.

Parameters:
boolean $full If set to false only HttpSocket::response and HttpSocket::request are reseted
Returns:
boolean True on success public

Reimplemented from CakeSocket.

Definition at line 977 of file http_socket.php.

Referenced by request().

HttpSocket::saveCookies (  ) 

undocumented function

Returns:
void public

Definition at line 903 of file http_socket.php.

HttpSocket::unescapeToken ( token,
chars = null 
)

Unescapes a given $token according to RFC 2616 (HTTP 1.1 specs)

Parameters:
string $token Token to unescape
Returns:
string Unescaped token protected
Todo:
Test $chars parameter

Definition at line 923 of file http_socket.php.

HttpSocket::url ( url = null,
uriTemplate = null 
)

undocumented function

Parameters:
unknown $url
unknown $uriTemplate
Returns:
void public

Definition at line 336 of file http_socket.php.

References $url, buildUri(), config(), CakeSocket::host(), parseUri(), and request().

Referenced by request().


Member Data Documentation

HttpSocket::$config

Initial value:

 array(
        'persistent' => false,
        'host'       => 'localhost',
        'protocol'   => 'tcp',
        'port'       => 80,
        'timeout'    => 30,
        'request' => array(
            'uri' => array(
                'scheme' => 'http',
                'host' => 'localhost',
                'port' => 80
            ),
            'auth' => array(
                'method' => 'Basic',
                'user' => null,
                'pass' => null
            ),
            'cookies' => array()
        )
    )

Reimplemented from CakeSocket.

Definition at line 111 of file http_socket.php.

Referenced by __construct(), and configUri().

HttpSocket::$description = 'HTTP-based DataSource Interface'

Reimplemented from CakeSocket.

Definition at line 41 of file http_socket.php.

HttpSocket::$lineBreak = "\r\n"

Definition at line 137 of file http_socket.php.

HttpSocket::$quirksMode = false

Definition at line 49 of file http_socket.php.

HttpSocket::$request

Initial value:

 array(
        'method' => 'GET',
        'uri' => array(
            'scheme' => 'http',
            'host' => null,
            'port' => 80,
            'user' => null,
            'pass' => null,
            'path' => null,
            'query' => null,
            'fragment' => null
        ),
        'auth' => array(
            'method' => 'Basic',
            'user' => null,
            'pass' => null
        ),
        'version' => '1.1',
        'body' => '',
        'line' => null,
        'header' => array(
            'Connection' => 'close',
            'User-Agent' => 'CakePHP'
        ),
        'raw' => null,
        'cookies' => array()
    )

Definition at line 56 of file http_socket.php.

Referenced by delete(), get(), post(), put(), and request().

HttpSocket::$response

Initial value:

 array(
        'raw' => array(
            'status-line' => null,
            'header' => null,
            'body' => null,
            'response' => null
        ),
        'status' => array(
            'http-version' => null,
            'code' => null,
            'reason-phrase' => null
        ),
        'header' => array(),
        'body' => '',
        'cookies' => array()
    )

Definition at line 89 of file http_socket.php.

Referenced by parseResponse(), and request().


The documentation for this class was generated from the following file:
Generated on Sun Nov 22 00:30:56 2009 for CakePHP 1.2.x.x (v1.2.4.8284) by doxygen 1.4.7