PHP WebSocket2 Library
PHP5 Library for browsing web
HttpRequestManager Class Reference

High-level HTTP request manager, which supports HTTP redirects, cookies and authentication. More...

Public Member Functions

 __construct (HttpSocket $socket, HttpCookieManager $cookie_manager=null)
 Constructor. More...
 
 setOnRedirectCallback (callable $on_redirect=null)
 Sets callback function that will be called before HTTP redirect occurs. More...
 
 getOnRedirectCallback ()
 Returns callback function that will be called before HTTP redirect occurs. More...
 
 getCookieManager ()
 Returns cookie manager. More...
 
 setCookieManager (HttpCookieManager $cookie_manager=null)
 Sets cookie manager. More...
 
 getSocket ()
 Returns socket to use for requests. More...
 
 setSocket (HttpSocket $socket)
 Sets socket to use for requests. More...
 
 getMaxRedirectionCount ()
 Returns maximal HTTP redirection count. Default is 10. More...
 
 setMaxRedirectionCount ($max_redirection_count)
 Sets maximal HTTP redirection count. Default is 10. More...
 
 isAutomaticRefererUsed ()
 Returns true if automatic referer header set up is on for redirections. More...
 
 useAutomaticReferer ($use_automatic_referer)
 Sets if automatic referer header set up is on for redirections. More...
 
 addAuthData ($realm, $login, $password)
 Adds authentication information for realm to allow automatic authentication (basic/digest) for it. More...
 
 getAuthData ($realm)
 Returns authentication information for realm. More...
 
 removeAuthData ($realm)
 Removes authentication information for realm. More...
 
 clearAuthData ()
 Clears authentication information for all realms.
 
 runRequest (WebRequest $request)
 Performs HTTP request. More...
 

Detailed Description

High-level HTTP request manager, which supports HTTP redirects, cookies and authentication.

Examples:
basic_http_authentication.php, basic_http_request_manager.php, http_cookies.php, and redirection_interception.php.

Constructor & Destructor Documentation

__construct ( HttpSocket  $socket,
HttpCookieManager  $cookie_manager = null 
)

Constructor.

Parameters
HttpSocket$socketSocket to use for requests
HttpCookieManager$cookie_managerCookie manager to use. Can be null.

Member Function Documentation

addAuthData (   $realm,
  $login,
  $password 
)

Adds authentication information for realm to allow automatic authentication (basic/digest) for it.

Parameters
string$realmRealm name. If null, this function will set login and password for all non-listed realms
string$loginLogin
string$passwordPassword
getAuthData (   $realm)

Returns authentication information for realm.

Parameters
string$realmRealm name. If null, this function will return login and password for all non-listed realms
Return values
ArrayArray('login', 'password'). Can be null, if no authentication information present for realm
getCookieManager ( )

Returns cookie manager.

Return values
HttpCookieManagerCookie manager to use or null.
getMaxRedirectionCount ( )

Returns maximal HTTP redirection count. Default is 10.

Return values
intMaximal HTTP redirection count or -1 (unlimited redirects)
getOnRedirectCallback ( )

Returns callback function that will be called before HTTP redirect occurs.

See setOnRedirectCallback also.

Return values
callableCallback function or null, if no HTTP redirect interception is needed
getSocket ( )

Returns socket to use for requests.

Return values
HttpSocketsocket to use for requests.
isAutomaticRefererUsed ( )

Returns true if automatic referer header set up is on for redirections.

Return values
boolTrue if automatic referer header set up is on for redirections
removeAuthData (   $realm)

Removes authentication information for realm.

Parameters
string$realmRealm name. If null, this function will remove login and password for all non-listed realms
runRequest ( WebRequest  $request)

Performs HTTP request.

May modify $request in case HTTP authentication will be required.

Parameters
WebRequest$requestHTTP request
Return values
WebResponseHTTP response (or just response headers in some cases, see NetworkSocket::setOnReceiveHeadersCallback, NetworkSocket::setOnReceiveBodyCallback)
Exceptions
WebRequestExceptionif an error occured
Examples:
redirection_interception.php.
setCookieManager ( HttpCookieManager  $cookie_manager = null)

Sets cookie manager.

Parameters
HttpCookieManager$cookie_managerCookie manager to use. Can be null.
setMaxRedirectionCount (   $max_redirection_count)

Sets maximal HTTP redirection count. Default is 10.

Parameters
int$max_redirection_countMaximal HTTP redirection count or -1 (unlimited redirects)
setOnRedirectCallback ( callable  $on_redirect = null)

Sets callback function that will be called before HTTP redirect occurs.

The prototype of callback function:

bool func(WebRequest $original_request, WebResponse $response,
WebRequest $new_request, int $http_code, HttpRequestManager $this);

Where:
$original_request is original WebRequest that lead to redirection response;
$response is server response;
$new_request is WebRequest that is going to be sent;
$http_code is HTTP redirection code;
$this is this request manager.

This function must return true to run redirect or false to abort it. If request is aborted from this callback, runRequest will return last WebResponse.

Parameters
callable$on_redirectCallback function or null, if no HTTP redirect interception is needed
setSocket ( HttpSocket  $socket)

Sets socket to use for requests.

Parameters
HttpSocket$socketSocket to use for requests
useAutomaticReferer (   $use_automatic_referer)

Sets if automatic referer header set up is on for redirections.

Parameters
int$use_automatic_refererIf true, automatic referer header set up is on for redirections.

The documentation for this class was generated from the following file: