Class SimpleUserAgent

Description

Fetches web pages whilst keeping track of cookies and authentication.

Located in /libraries/pear/simpletest/user_agent.php (line 160)


	
			
Variable Summary
Method Summary
 SimpleUserAgent SimpleUserAgent ()
 void addHeader (string $header)
 void ageCookies (integer $interval)
 SimpleUrl createAbsoluteUrl (string/SimpleUrl $base, string/SimpleUrl $url)
 SimpleHttpResponse &fetchResponse (string $method, string/SimpleUrl $url, [hash $parameters = false])
 SimpleHttpResponse &fetchResponsePreservingBase (string $method, string/SimpleUrl $url, [hash $parameters = false])
 string getBaseCookieValue (string $name)
 string getBaseUrl ()
 string getCookieValue (string $host, string $path, string $name)
 void restartSession ([string/integer $date = false])
 void setBaseUrl (SimpleUrl $url)
 void setConnectionTimeout (integer $timeout)
 void setCookie (string $name, string $value, [string $host = false], [string $path = '/'], [string $expiry = false])
 void setIdentity (string $host, string $realm, string $username, string $password)
 void setMaximumRedirects (integer $max)
 void useProxy (string $proxy, string $username, string $password)
 void _addCookiesToJar (SimpleUrl $url, array $cookies)
 SimpleHttpRequest &_createHttpRequest (string $method, SimpleUrl $url, hash $parameters)
 SimpleHttpRequest &_createRequest (string $method, SimpleUrl $url, hash $parameters)
 SimpleHttpResponse &_fetch (string $method, SimpleUrl $url, hash $parameters)
 SimpleHttpResponse &_fetchWhileRedirected (string $method, string/SimpleUrl $url, hash $parameters)
 boolean _isTooManyRedirects (integer $redirects)
Variables
mixed $_additional_headers (line 169)
mixed $_authenticator (line 162)
mixed $_base_url (line 168)
mixed $_connection_timeout (line 167)
mixed $_cookie_jar (line 161)
mixed $_max_redirects (line 163)
mixed $_proxy (line 164)
mixed $_proxy_password (line 166)
mixed $_proxy_username (line 165)
Methods
Constructor SimpleUserAgent (line 175)

Starts with no cookies, realms or proxies.

  • access: public
SimpleUserAgent SimpleUserAgent ()
addHeader (line 228)

Adds a header to every fetch.

  • access: public
void addHeader (string $header)
  • string $header: Header line to add to every request until cleared.
ageCookies (line 237)

Ages the cookies by the specified time.

  • access: public
void ageCookies (integer $interval)
  • integer $interval: Amount in seconds.
createAbsoluteUrl (line 534)

Turns an incoming URL string or object into a URL object, filling the relative URL if a base URL is present.

  • return: Absolute URL.
  • static:
  • access: public
SimpleUrl createAbsoluteUrl (string/SimpleUrl $base, string/SimpleUrl $url)
  • string/SimpleUrl $base: Browser current URL.
  • string/SimpleUrl $url: Incoming URL.
fetchResponse (line 369)

Fetches a URL as a response object. Will keep trying if redirected.

It will also collect authentication realm information.

  • return: Hopefully the target page.
  • access: public
SimpleHttpResponse &fetchResponse (string $method, string/SimpleUrl $url, [hash $parameters = false])
  • string $method: GET, POST, etc.
  • string/SimpleUrl $url: Target to fetch.
  • hash $parameters: Additional parameters for request.
fetchResponsePreservingBase (line 396)

Fetches a response whilst preserving the base URL.

Useful for HEAD fetches and images and frames.

  • return: Hopefully the target page.
  • access: public
SimpleHttpResponse &fetchResponsePreservingBase (string $method, string/SimpleUrl $url, [hash $parameters = false])
  • string $method: GET, POST, etc.
  • string/SimpleUrl $url: Target to fetch.
  • hash $parameters: Additional parameters for request.
getBaseCookieValue (line 289)

Reads the current cookies for the base URL.

  • return: Null if there is no base URL, false if the cookie is not set.
  • access: public
string getBaseCookieValue (string $name)
  • string $name: Key of cookie to find.
getBaseUrl (line 201)

Accessor for base URL worked out from the current URL.

  • return: Base URL.
  • access: public
string getBaseUrl ()
getCookieValue (line 269)

Reads the most specific cookie value from the browser cookies.

  • return: False if not present, else the value as a string.
  • access: public
string getCookieValue (string $host, string $path, string $name)
  • string $host: Host to search.
  • string $path: Applicable path.
  • string $name: Name of cookie to read.
restartSession (line 218)

Removes expired and temporary cookies as if the browser was closed and re-opened.

  • access: public
void restartSession ([string/integer $date = false])
  • string/integer $date: Time when session restarted. If omitted then all persistent cookies are kept.
setBaseUrl (line 192)

Sets the current location.

  • access: public
void setBaseUrl (SimpleUrl $url)
setConnectionTimeout (line 302)

Sets the socket timeout for opening a connection.

  • access: public
void setConnectionTimeout (integer $timeout)
  • integer $timeout: Maximum time in seconds.
setCookie (line 251)

Sets an additional cookie. If a cookie has the same name and path it is replaced.

  • access: public
void setCookie (string $name, string $value, [string $host = false], [string $path = '/'], [string $expiry = false])
  • string $name: Cookie key.
  • string $value: Value of cookie.
  • string $host: Host upon which the cookie is valid.
  • string $path: Cookie path if not host wide.
  • string $expiry: Expiry date.
setIdentity (line 356)

Sets the identity for the current realm.

  • access: public
void setIdentity (string $host, string $realm, string $username, string $password)
  • string $host: Host to which realm applies.
  • string $realm: Full name of realm.
  • string $username: Username for realm.
  • string $password: Password for realm.
setMaximumRedirects (line 312)

Sets the maximum number of redirects before a page will be loaded anyway.

  • access: public
void setMaximumRedirects (integer $max)
  • integer $max: Most hops allowed.
useProxy (line 325)

Sets proxy to use on all requests for when testing from behind a firewall. Set URL to false to disable.

  • access: public
void useProxy (string $proxy, string $username, string $password)
  • string $proxy: Proxy URL.
  • string $username: Proxy username for authentication.
  • string $password: Proxy password for authentication.
_addAdditionalHeaders (line 503)

Adds additional manual headers.

  • access: private
void _addAdditionalHeaders (SimpleHttpRequest &$request)
_addCookiesToJar (line 515)

Extracts new cookies into the cookie jar.

  • access: private
void _addCookiesToJar (SimpleUrl $url, array $cookies)
  • SimpleUrl $url: Target to fetch as url object.
  • array $cookies: New cookies.
_createHttpRequest (line 468)

Builds the appropriate HTTP request object.

  • return: New request object.
  • access: protected
SimpleHttpRequest &_createHttpRequest (string $method, SimpleUrl $url, hash $parameters)
  • string $method: Fetching method.
  • SimpleUrl $url: Target to fetch as url object.
  • hash $parameters: POST/GET parameters.
_createRequest (line 452)

Creates a full page request.

  • return: New request.
  • access: private
SimpleHttpRequest &_createRequest (string $method, SimpleUrl $url, hash $parameters)
  • string $method: Fetching method.
  • SimpleUrl $url: Target to fetch as url object.
  • hash $parameters: POST/GET parameters.
_createRoute (line 487)

Sets up either a direct route or via a proxy.

  • return: Route to take to fetch URL.
  • access: protected
SimpleRoute &_createRoute (SimpleUrl $url)
  • SimpleUrl $url: Target to fetch as url object.
_fetch (line 436)

Actually make the web request.

  • return: Headers and hopefully content.
  • access: protected
SimpleHttpResponse &_fetch (string $method, SimpleUrl $url, hash $parameters)
  • string $method: GET, POST, etc.
  • SimpleUrl $url: Target to fetch.
  • hash $parameters: Additional parameters for request.
_fetchWhileRedirected (line 408)

Fetches the page until no longer redirected or until the redirect limit runs out.

  • return: Hopefully the target page.
  • access: private
SimpleHttpResponse &_fetchWhileRedirected (string $method, string/SimpleUrl $url, hash $parameters)
  • string $method: GET, POST, etc.
  • string/SimpleUrl $url: Target to fetch.
  • hash $parameters: Additional parameters for request.
_isTooManyRedirects (line 344)

Test to see if the redirect limit is passed.

  • return: True if over.
  • access: private
boolean _isTooManyRedirects (integer $redirects)
  • integer $redirects: Count so far.

Documentation generated on Thu, 20 Jan 2005 17:11:24 +0000 by phpDocumentor 1.3.0RC3