HttpSocket Class Info:

Class Declaration:
class HttpSocket extends CakeSocket
File name:
cake/libs/http_socket.php
Summary:
Cake network socket connection class. Core base class for HTTP network communication.
Class Inheritance

CakeSocket Object

package
cake
subpackage
cake.cake.libs

Properties:

Show/Hide parent properties
protected _baseConfig Base configuration settings for the socket connection
public config Default configuration settings for the HttpSocket
public connected This boolean contains the current state of the CakeSocket class
public connection Reference to socket connection resource
public description Object description
public lastError This variable contains an array with the last error number (num) and string (str)
public lineBreak String that represents a line break.
protected _log Log object
public quirksMode When one activates the $quirksMode by setting it to true, all checks meant to enforce RFC 2616 (HTTP/1.1 specs) will be disabled and additional measures to deal with non-standard responses will be enabled.
public request The default values to use for a request
public response * The default structure for storing the response * @var array * @access public

Method Summary:

Show/Hide parent methods
public abort( )
public address( )
public addresses( )
public buildCookies( $cookies )
protected buildHeader( $header, $mode = 'standard' )
protected buildRequestLine( $request = array ( ), $versionToken = 'HTTP/1.1' )
protected buildUri( $uri = array ( ), $uriTemplate = '%scheme://%user:%pass@%host:%port/%path?%query#%fragment' )
public cakeError( $method, $messages = array ( ) )
protected configUri( $uri = NULL )
public connect( )
public __construct( $config = array ( ) )
protected decodeBody( $body, $encoding = 'chunked' )
protected decodeChunkedBody( $body )
public delete( $uri = NULL, $data = array ( ), $request = array ( ) )
public disconnect( )
public dispatchMethod( $method, $params = array ( ) )
protected escapeToken( $token, $chars = NULL )
public get( $uri = NULL, $query = array ( ), $request = array ( ) )
public host( )
protected httpSerialize( $data = array ( ) )
public lastError( )
public loadCookies( )
public log( $msg, $type = 2 )
public Object( )
public parseCookies( $header )
protected parseHeader( $header )
protected parseQuery( $query )
protected parseResponse( $message )
protected parseUri( $uri = NULL, $base = array ( ) )
protected _persist( $name, $return, $object, $type = NULL )
public post( $uri = NULL, $data = array ( ), $request = array ( ) )
public put( $uri = NULL, $data = array ( ), $request = array ( ) )
public read( $length = 1024 )
public request( $request = array ( ) )
public requestAction( $url, $extra = array ( ) )
public reset( $full = true )
public saveCookies( )
protected _savePersistent( $name, $object )
protected _set( $properties = array ( ) )
public setLastError( $errNum, $errStr )
public _stop( $status = 0 )
public toString( )
protected unescapeToken( $token, $chars = NULL )
public url( $url = NULL, $uriTemplate = NULL )
public write( $data )

abort

top
Abort socket operation.
Method defined in class:
CakeSocket
Method defined in file:
cake/libs/socket.php on line 242
return
boolean Success
access
public

address

top
Get the IP address of the current connection.
Method defined in class:
CakeSocket
Method defined in file:
cake/libs/socket.php on line 149
return
string IP address
access
public

addresses

top
Get all IP addresses associated with the current connection.
Method defined in class:
CakeSocket
Method defined in file:
cake/libs/socket.php on line 162
return
array IP addresses
access
public

buildCookies

top
undocumented function
Parameters:
$cookies unknown required (no default)
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 889
return
void
access
public
todo
Refactor token escape mechanism to be configurable

buildHeader

top
Builds the header.
Parameters:
$header array Header to build required (no default)
$mode optional 'standard'
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 769
return
string Header built from array
access
protected

buildRequestLine

top
Builds a request line according to HTTP/1.1 specs. Activate quirks mode to work outside specs.
Parameters:
$request array Needs to contain a 'uri' key. Should also contain a 'method' key, otherwise defaults to GET. optional array ( )
$versionToken string The version token to use, defaults to HTTP/1.1 optional 'HTTP/1.1'
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 720
return
string Request line
access
protected

buildUri

top
Takes a $uri array and turns it into a fully qualified URL string
Parameters:
$uri array A $uri array, or uses $this->config if left empty optional array ( )
$uriTemplate string The Uri template/format to use optional '%scheme://%user:%pass@%host:%port/%path?%query#%fragment'
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 552
return
string A fully qualified URL formated according to $uriTemplate
access
protected

cakeError

top
Used to report user friendly errors. If there is a file app/error.php or app/app_error.php this file will be loaded error.php is the AppError class it should extend ErrorHandler class.
Parameters:
$method string Method to be called in the error class (AppError or ErrorHandler classes) required (no default)
$messages array Message that is to be displayed by the error class optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 189
return
error message
access
public

configUri

top
Parses and sets the specified URI into current request configuration.
Parameters:
$uri mixed URI (see {@link parseUri()}) optional NULL
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 519
return
array Current configuration settings
access
protected

connect

top
Connect the socket to the given host and port.
Method defined in class:
CakeSocket
Method defined in file:
cake/libs/socket.php on line 102
return
boolean Success
access
public

__construct

top
Build an HTTP Socket using the specified configuration.
Parameters:
$config array Configuration optional array ( )
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 144

decodeBody

top
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:
$body string A string continaing the body to decode required (no default)
$encoding mixed Can be false in case no encoding is being used, or a string representing the encoding optional 'chunked'
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 433
return
mixed Array or false
access
protected

decodeChunkedBody

top
Decodes a chunked message $body and returns either an array with the keys 'body' and 'header' or false as a result.
Parameters:
$body string A string continaing the chunked body to decode required (no default)
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 458
return
mixed Array or false
access
protected

delete

top
Issues a DELETE request to the specified URI, query, and request.
Parameters:
$uri mixed URI to request (see {@link parseUri()}) optional NULL
$data optional array ( )
$request array An indexed array with indexes such as 'method' or uri optional array ( )
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 324
return
mixed Result of request
access
public

disconnect

top
Disconnect the socket from the current connection.
Method defined in class:
CakeSocket
Method defined in file:
cake/libs/socket.php on line 250
return
boolean Success
access
public

dispatchMethod

top
Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array, and improves performance by using straight method calls in most cases.
Parameters:
$method string Name of the method to call required (no default)
$params array Parameter list to use when calling $method optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 113
return
mixed Returns the result of the method call
access
public

escapeToken

top
Escapes a given $token according to RFC 2616 (HTTP 1.1 specs)
Parameters:
$token string Token to escape required (no default)
$chars optional NULL
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 936
return
string Escaped token
access
protected
todo
Test $chars parameter

get

top
Issues a GET request to the specified URI, query, and request.
Parameters:
$uri mixed URI to request (see {@link parseUri()}) optional NULL
$query array Query to append to URI optional array ( )
$request array An indexed array with indexes such as 'method' or uri optional array ( )
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 274
return
mixed Result of request
access
public

host

top
Get the host name of the current connection.
Method defined in class:
CakeSocket
Method defined in file:
cake/libs/socket.php on line 136
return
string Host name
access
public

httpSerialize

top
Serializes an array for transport.
Parameters:
$data array Data to serialize optional array ( )
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 753
return
string Serialized variable
access
protected

lastError

top
Get the last error as a string.
Method defined in class:
CakeSocket
Method defined in file:
cake/libs/socket.php on line 175
return
string Last error
access
public

loadCookies

top
undocumented function
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 912
return
void
access
public

log

top
API for logging events.
Parameters:
$msg string Log message required (no default)
$type integer Error type constant. Defined in app/config/core.php. optional 2
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 150
return
boolean Success of log write
access
public

Object

top
A hack to support __construct() on PHP 4 Hint: descendant classes have no PHP4 class_name() constructors, so this constructor gets called first and calls the top-layer __construct() which (if present) should call parent::__construct()
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 53
return
Object

parseCookies

top
undocumented function
Parameters:
$header unknown required (no default)
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 848
return
void
access
public
todo
Make this 100% RFC 2965 confirm

parseHeader

top
Parses an array based header.
Parameters:
$header array Header as an indexed array (field => value) required (no default)
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 798
return
array Parsed header
access
protected

parseQuery

top
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: - ?key[subKey]=value - ?key[]=value1&key[]=value2 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:
$query mixed A query string to parse into an array or an array to return directly "as is" required (no default)
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 663
return
array The $query parsed into a possibly multi-level array. If an empty $query is given, an empty array is returned.
access
protected

parseResponse

top
Parses the given message and breaks it down in parts.
Parameters:
$message string Message to parse required (no default)
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 370
return
array Parsed message (with indexed elements such as raw, status, header, body)
access
protected

parseUri

top
Parses the given URI and breaks it down into pieces as an indexed array with elements such as 'scheme', 'port', 'query'.
Parameters:
$uri string URI to parse optional NULL
$base mixed If true use default URI config, otherwise indexed array to set 'scheme', 'host', 'port', etc. optional array ( )
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 599
return
array Parsed URI
access
protected

_persist

top
Checks for a persistent class file, if found file is opened and true returned If file is not found a file is created and false returned If used in other locations of the model you should choose a unique name for the persistent file There are many uses for this method, see manual for examples
Parameters:
$name string name of the class to persist required (no default)
$return required (no default)
$object string the object to persist required (no default)
$type optional NULL
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 219
return
boolean Success
access
protected
todo
add examples to manual

post

top
Issues a POST request to the specified URI, query, and request.
Parameters:
$uri mixed URI to request (see {@link parseUri()}) optional NULL
$data optional array ( )
$request array An indexed array with indexes such as 'method' or uri optional array ( )
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 298
return
mixed Result of request
access
public

put

top
Issues a PUT request to the specified URI, query, and request.
Parameters:
$uri mixed URI to request (see {@link parseUri()}) optional NULL
$data optional array ( )
$request array An indexed array with indexes such as 'method' or uri optional array ( )
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 311
return
mixed Result of request
access
public

read

top
Read data from the socket. Returns false if no data is available or no connection could be established.
Parameters:
$length integer Optional buffer length to read; defaults to 1024 optional 1024
Method defined in class:
CakeSocket
Method defined in file:
cake/libs/socket.php on line 217
return
mixed Socket data
access
public

request

top
Issue the specified request.
Parameters:
$request mixed Either an URI string, or an array defining host/uri optional array ( )
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 163
return
mixed false on error, request body on success
access
public

requestAction

top
Calls a controller's method from any location.
Parameters:
$url mixed String or array-based url. required (no default)
$extra array if array includes the key "return" it sets the AutoRender to true. optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 86
return
mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
access
public

reset

top
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:
$full boolean If set to false only HttpSocket::response and HttpSocket::request are reseted optional true
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 977
return
boolean True on success
access
public

saveCookies

top
undocumented function
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 903
return
void
access
public

_savePersistent

top
You should choose a unique name for the persistent file There are many uses for this method, see manual for examples
Parameters:
$name string name used for object to cache required (no default)
$object object the object to persist required (no default)
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 247
return
boolean true on save, throws error if file can not be created
access
protected

_set

top
Allows setting of multiple properties of the object in a single line of code.
Parameters:
$properties array An associative array containing properties and corresponding values. optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 169
return
void
access
protected

setLastError

top
Set the last error.
Parameters:
$errNum integer Error code required (no default)
$errStr string Error string required (no default)
Method defined in class:
CakeSocket
Method defined in file:
cake/libs/socket.php on line 189
access
public

_stop

top
Stop execution of the current script
Parameters:
$status optional 0
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 139
return
void
access
public

toString

top
Object-to-string conversion. Each class can override this method as necessary.
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 73
return
string The name of this class
access
public

unescapeToken

top
Unescapes a given $token according to RFC 2616 (HTTP 1.1 specs)
Parameters:
$token string Token to unescape required (no default)
$chars optional NULL
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 923
return
string Unescaped token
access
protected
todo
Test $chars parameter

url

top
undocumented function
Parameters:
$url unknown optional NULL
$uriTemplate unknown optional NULL
Method defined in class:
HttpSocket
Method defined in file:
cake/libs/http_socket.php on line 336
return
void
access
public

write

top
Write data to the socket.
Parameters:
$data string The data to write to the socket required (no default)
Method defined in class:
CakeSocket
Method defined in file:
cake/libs/socket.php on line 199
return
boolean Success
access
public