HTTP_Request2
[ class tree: HTTP_Request2 ] [ index: HTTP_Request2 ] [ all elements ]

Class: HTTP_Request2

Source Location: /HTTP_Request2-2.2.1/HTTP/Request2.php

Class Overview


Class representing a HTTP request message


Author(s):

Version:

  • Release: 2.2.1

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 42]
Class representing a HTTP request message


[ Top ]


Class Variables

$adapter =

[line 188]

Adapter used to perform actual HTTP request
  • Access: protected



[ Top ]

$auth =

[line 111]

Authentication data

Type:   array


[ Top ]

$body =  ''

[line 170]

Request body

Type:   string|resource


[ Top ]

$config = array(
        'adapter'           => 'HTTP_Request2_Adapter_Socket',
        'connect_timeout'   => 10,
        'timeout'           => 0,
        'use_brackets'      => true,
        'protocol_version'  => '1.1',
        'buffer_size'       => 16384,
        'store_body'        => true,
        'local_ip'          => null,

        'proxy_host'        => '',
        'proxy_port'        => '',
        'proxy_user'        => '',
        'proxy_password'    => '',
        'proxy_auth_scheme' => self::AUTH_BASIC,
        'proxy_type'        => 'http',

        'ssl_verify_peer'   => true,
        'ssl_verify_host'   => true,
        'ssl_cafile'        => null,
        'ssl_capath'        => null,
        'ssl_local_cert'    => null,
        'ssl_passphrase'    => null,

        'digest_compat_ie'  => false,

        'follow_redirects'  => false,
        'max_redirects'     => 5,
        'strict_redirects'  => false
    )

[line 124]

Configuration parameters

Type:   array


[ Top ]

$cookieJar =  null

[line 194]

Cookie jar to persist cookies between requests
  • Access: protected



[ Top ]

$headers = array()

[line 117]

Request headers
  • Access: protected

Type:   array


[ Top ]

$lastEvent = array(
        'name' => 'start',
        'data' => null
    )

[line 160]

Last event in request / response handling, intended for observers

Type:   array


[ Top ]

$method =  self::METHOD_GET

[line 104]

Request method
  • Access: protected

Type:   string


[ Top ]

$observers = array()

[line 92]

Observers attached to the request (instances of SplObserver)
  • Access: protected

Type:   array


[ Top ]

$postParams = array()

[line 176]

Array of POST parameters
  • Access: protected

Type:   array


[ Top ]

$uploads = array()

[line 182]

Array of file uploads (for multipart/form-data POST requests)
  • Access: protected

Type:   array


[ Top ]

$url =

[line 98]

Request URL
  • Access: protected

Type:   Net_URL2


[ Top ]



Method Detail

__construct (Constructor)   [line 205]

HTTP_Request2 __construct( [string|Net_Url2 $url = null], [string $method = self::METHOD_GET], [ $config = array()])

Constructor. Can set request URL, method and configuration array.

Also sets a default value for User-Agent header.

  • Access: public

Parameters:

string|Net_Url2   $url     Request URL
string   $method     Request method
array   $config     Configuration for this Request instance

[ Top ]

addCookie   [line 548]

HTTP_Request2 addCookie( string $name, string $value)

Adds a cookie to the request

If the request does not have a CookieJar object set, this method simply appends a cookie to "Cookie:" header.

If a CookieJar object is available, the cookie is stored in that object. Data from request URL will be used for setting its 'domain' and 'path' parameters, 'expires' and 'secure' will be set to null and false, respectively. If you need further control, use CookieJar's methods.


Parameters:

string   $name     cookie name
string   $value     cookie value

[ Top ]

addPostParameter   [line 700]

HTTP_Request2 addPostParameter( string|array $name, [mixed $value = null])

Adds POST parameter(s) to the request.
  • Access: public

Parameters:

string|array   $name     parameter name or array ('name' => 'value')
mixed   $value     parameter value (can be an array)

[ Top ]

addUpload   [line 654]

HTTP_Request2 addUpload( string $fieldName, string|resource|array $filename, [string $sendFilename = null], [string $contentType = null])

Adds a file to form-based file upload

Used to emulate file upload via a HTML form. The method also sets Content-Type of HTTP request to 'multipart/form-data'.

If you just want to send the contents of a file as the body of HTTP request you should use setBody() method.

If you provide file pointers rather than file names, they should support fstat() and rewind() operations.

  • Throws: HTTP_Request2_LogicException
  • Access: public

Parameters:

string   $fieldName     name of file-upload field
string|resource|array   $filename     full name of local file, pointer to open file or an array of files
string   $sendFilename     filename to send in the request
string   $contentType     content-type of file being uploaded

[ Top ]

attach   [line 721]

void attach( $observer)

Attaches a new observer
  • Access: public

Parameters:

SplObserver   $observer     any object implementing SplObserver

[ Top ]

detach   [line 736]

void detach( $observer)

Detaches an existing observer
  • Access: public

Parameters:

SplObserver   $observer     any object implementing SplObserver

[ Top ]

detectMimeType   [line 1012]

string detectMimeType( string $filename)

Tries to detect MIME type of a file

The method will try to use fileinfo extension if it is available, deprecated mime_content_type() function in the other case. If neither works, default 'application/octet-stream' MIME type is returned

  • Return: file MIME type
  • Access: protected

Parameters:

string   $filename     file name

[ Top ]

fopenWrapper   [line 967]

array fopenWrapper( string|resource $file, [bool $detectType = false])

Wrapper around fopen()/fstat() used by setBody() and addUpload()
  • Return: array('fp' => file pointer, 'size' => file size, 'type' => MIME type)
  • Throws: HTTP_Request2_LogicException
  • Access: protected

Parameters:

string|resource   $file     file name or pointer to open file
bool   $detectType     whether to try autodetecting MIME type of file, will only work if $file is a filename, not pointer

[ Top ]

getAuth   [line 441]

array getAuth( )

Returns the authentication data

The array has the keys 'user', 'password' and 'scheme', where 'scheme' is one of the HTTP_Request2::AUTH_* constants.

  • Access: public

[ Top ]

getBody   [line 610]

string|resource|HTTP_Request2_MultipartBody getBody( )

Returns the request body
  • Access: public

[ Top ]

getConfig   [line 396]

mixed getConfig( [string $name = null])

Returns the value(s) of the configuration parameter(s)
  • Return: value of $name parameter, array of all configuration parameters if $name is not given
  • Throws: HTTP_Request2_LogicException If the parameter is unknown
  • Access: public

Parameters:

string   $name     parameter name

[ Top ]

getCookieJar   [line 897]

HTTP_Request2_CookieJar|null getCookieJar( )

Returns current CookieJar object or null if none
  • Access: public

[ Top ]

getHeaders   [line 525]

array getHeaders( )

Returns the request headers

The array is of the form ('header name' => 'header value'), header names are lowercased

  • Access: public

[ Top ]

getLastEvent   [line 803]

array getLastEvent( )

Returns the last event

Observers should use this method to access the last change in request. The following event names are possible:

  • 'connect' - after connection to remote server, data is the destination (string)
  • 'disconnect' - after disconnection from server
  • 'sentHeaders' - after sending the request headers, data is the headers sent (string)
  • 'sentBodyPart' - after sending a part of the request body, data is the length of that part (int)
  • 'sentBody' - after sending the whole request body, data is request body length (int)
  • 'receivedHeaders' - after receiving the response headers, data is HTTP_Request2_Response object
  • 'receivedBodyPart' - after receiving a part of the response body, data is that part (string)
  • 'receivedEncodedBodyPart' - as 'receivedBodyPart', but data is still encoded by Content-Encoding
  • 'receivedBody' - after receiving the complete response body, data is HTTP_Request2_Response object
Different adapters may not send all the event types. Mock adapter does not send any events to the observers.

  • Return: The array has two keys: 'name' and 'data'
  • Access: public

[ Top ]

getMethod   [line 298]

string getMethod( )

Returns the request method
  • Access: public

[ Top ]

getUrl   [line 266]

Net_URL2 getUrl( )

Returns the request URL
  • Access: public

[ Top ]

notify   [line 749]

void notify( )

Notifies all observers
  • Access: public

[ Top ]

send   [line 908]

HTTP_Request2_Response send( )

Sends the request and returns the response
  • Throws: HTTP_Request2_Exception
  • Access: public

[ Top ]

setAdapter   [line 825]

HTTP_Request2 setAdapter( string|HTTP_Request2_Adapter $adapter)

Sets the adapter used to actually perform the request

You can pass either an instance of a class implementing HTTP_Request2_Adapter or a class name. The method will only try to include a file if the class name starts with HTTP_Request2_Adapter_, it will also try to prepend this prefix to the class name if it doesn't contain any underscores, so that

  1.  $request->setAdapter('curl');
will work.

  • Throws: HTTP_Request2_LogicException
  • Access: public

Parameters:

string|HTTP_Request2_Adapter   $adapter     Adapter to use

[ Top ]

setAuth   [line 418]

HTTP_Request2 setAuth( string $user, [string $password = ''], [string $scheme = self::AUTH_BASIC])

Sets the autentification data
  • Access: public

Parameters:

string   $user     user name
string   $password     password
string   $scheme     authentication scheme

[ Top ]

setBody   [line 585]

HTTP_Request2 setBody( string|resource|HTTP_Request2_MultipartBody $body, [bool $isFilename = false])

Sets the request body

If you provide file pointer rather than file name, it should support fstat() and rewind() operations.

  • Throws: HTTP_Request2_LogicException
  • Access: public

Parameters:

string|resource|HTTP_Request2_MultipartBody   $body     Either a string with the body or filename containing body or pointer to an open file or object with multipart body data
bool   $isFilename     Whether first parameter is a filename

[ Top ]

setConfig   [line 357]

HTTP_Request2 setConfig( string|array $nameOrConfig, [mixed $value = null])

Sets the configuration parameter(s)

The following parameters are available:

  • 'adapter' - adapter to use (string)
  • 'connect_timeout' - Connection timeout in seconds (integer)
  • 'timeout' - Total number of seconds a request can take. Use 0 for no limit, should be greater than 'connect_timeout' if set (integer)
  • 'use_brackets' - Whether to append [] to array variable names (bool)
  • 'protocol_version' - HTTP Version to use, '1.0' or '1.1' (string)
  • 'buffer_size' - Buffer size to use for reading and writing (int)
  • 'store_body' - Whether to store response body in response object. Set to false if receiving a huge response and using an Observer to save it (boolean)
  • 'local_ip' - Specifies the IP address that will be used for accessing the network (string)
  • 'proxy_type' - Proxy type, 'http' or 'socks5' (string)
  • 'proxy_host' - Proxy server host (string)
  • 'proxy_port' - Proxy server port (integer)
  • 'proxy_user' - Proxy auth username (string)
  • 'proxy_password' - Proxy auth password (string)
  • 'proxy_auth_scheme' - Proxy auth scheme, one of HTTP_Request2::AUTH_* constants (string)
  • 'proxy' - Shorthand for proxy_* parameters, proxy given as URL, e.g. 'socks5://localhost:1080/' (string)
  • 'ssl_verify_peer' - Whether to verify peer's SSL certificate (bool)
  • 'ssl_verify_host' - Whether to check that Common Name in SSL certificate matches host name (bool)
  • 'ssl_cafile' - Cerificate Authority file to verify the peer with (use with 'ssl_verify_peer') (string)
  • 'ssl_capath' - Directory holding multiple Certificate Authority files (string)
  • 'ssl_local_cert' - Name of a file containing local cerificate (string)
  • 'ssl_passphrase' - Passphrase with which local certificate was encoded (string)
  • 'digest_compat_ie' - Whether to imitate behaviour of MSIE 5 and 6 in using URL without query string in digest authentication (boolean)
  • 'follow_redirects' - Whether to automatically follow HTTP Redirects (boolean)
  • 'max_redirects' - Maximum number of redirects to follow (integer)
  • 'strict_redirects' - Whether to keep request method on redirects via status 301 and 302 (true, needed for compatibility with RFC 2616) or switch to GET (false, needed for compatibility with most browsers) (boolean)

  • Throws: HTTP_Request2_LogicException If the parameter is unknown
  • Access: public

Parameters:

string|array   $nameOrConfig     configuration parameter name or array ('parameter name' => 'parameter value')
mixed   $value     parameter value if $nameOrConfig is not an array

[ Top ]

setCookieJar   [line 870]

HTTP_Request2 setCookieJar( [HTTP_Request2_CookieJar|bool $jar = true])

Sets the cookie jar

A cookie jar is used to maintain cookies across HTTP requests and responses. Cookies from jar will be automatically added to the request headers based on request URL.

  • Throws: HTTP_Request2_LogicException
  • Access: public

Parameters:

HTTP_Request2_CookieJar|bool   $jar     Existing CookieJar object, true to create a new one, false to remove

[ Top ]

setHeader   [line 474]

HTTP_Request2 setHeader( string|array $name, [string|array|null $value = null], [bool $replace = true])

Sets request header(s)

The first parameter may be either a full header string 'header: value' or header name. In the former case $value parameter is ignored, in the latter the header's value will either be set to $value or the header will be removed if $value is null. The first parameter can also be an array of headers, in that case method will be called recursively.

Note that headers are treated case insensitively as per RFC 2616.

  1.  $req->setHeader('Foo: Bar')// sets the value of 'Foo' header to 'Bar'
  2.  $req->setHeader('FoO''Baz')// sets the value of 'Foo' header to 'Baz'
  3.  $req->setHeader(array('foo' => 'Quux'))// sets the value of 'Foo' header to 'Quux'
  4.  $req->setHeader('FOO')// removes 'Foo' header from request

  • Throws: HTTP_Request2_LogicException
  • Access: public

Parameters:

string|array   $name     header name, header string ('Header: value') or an array of headers
string|array|null   $value     header value if $name is not an array, header will be removed if value is null
bool   $replace     whether to replace previous header with the same name or append to its value

[ Top ]

setLastEvent   [line 765]

void setLastEvent( string $name, [mixed $data = null])

Sets the last event

Adapters should use this method to set the current state of the request and notify the observers.

  • Access: public

Parameters:

string   $name     event name
mixed   $data     event data

[ Top ]

setMethod   [line 279]

HTTP_Request2 setMethod( string $method)

Sets the request method
  • Throws: HTTP_Request2_LogicException if the method name is invalid
  • Access: public

Parameters:

string   $method     one of the methods defined in RFC 2616

[ Top ]

setUrl   [line 233]

HTTP_Request2 setUrl( string|Net_URL2 $url)

Sets the URL for this request

If the URL has userinfo part (username & password) these will be removed and converted to auth data. If the URL does not have a path component, that will be set to '/'.

  • Throws: HTTP_Request2_LogicException
  • Access: public

Parameters:

string|Net_URL2   $url     Request URL

[ Top ]


Documentation generated on Thu, 16 Jan 2014 20:00:07 +0000 by phpDocumentor 1.4.3. PEAR Logo Copyright © PHP Group 2004.