XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
HTTP_Request2_CookieJar Class Reference
Inheritance diagram for HTTP_Request2_CookieJar:

Public Member Functions

 __construct ($serializeSessionCookies=false, $usePublicSuffixList=true)
 
 store (array $cookie, Net_URL2 $setter=null)
 
 addCookiesFromResponse (HTTP_Request2_Response $response, Net_URL2 $setter)
 
 getMatching (Net_URL2 $url, $asString=false)
 
 getAll ()
 
 serializeSessionCookies ($serialize)
 
 usePublicSuffixList ($useList)
 
 serialize ()
 
 unserialize ($serialized)
 
 domainMatch ($requestHost, $cookieDomain)
 

Static Public Member Functions

static getRegisteredDomain ($domain)
 

Protected Member Functions

 now ()
 
 checkAndUpdateFields (array $cookie, Net_URL2 $setter=null)
 

Static Protected Member Functions

static checkDomainsList (array $domainParts, $listNode)
 

Protected Attributes

 $cookies = array()
 
 $serializeSession = false
 
 $useList = true
 

Static Protected Attributes

static $psl = array()
 

Detailed Description

Definition at line 34 of file CookieJar.php.

Constructor & Destructor Documentation

HTTP_Request2_CookieJar::__construct (   $serializeSessionCookies = false,
  $usePublicSuffixList = true 
)

Class constructor, sets various options

Parameters
bool$serializeSessionCookiesControls serializing session cookies, see serializeSessionCookies()
bool$usePublicSuffixListControls using Public Suffix List, see usePublicSuffixList()

Definition at line 79 of file CookieJar.php.

Member Function Documentation

HTTP_Request2_CookieJar::addCookiesFromResponse ( HTTP_Request2_Response  $response,
Net_URL2  $setter 
)

Adds cookies set in HTTP response to the jar

Parameters
HTTP_Request2_Response$responseHTTP response message
Net_URL2$setteroriginal request URL, needed for setting default domain/path

Definition at line 226 of file CookieJar.php.

HTTP_Request2_CookieJar::checkAndUpdateFields ( array  $cookie,
Net_URL2  $setter = null 
)
protected

Checks cookie array for correctness, possibly updating its 'domain', 'path' and 'expires' fields

The checks are as follows:

  • cookie array should contain 'name' and 'value' fields;
  • name and value should not contain disallowed symbols;
  • 'expires' should be either empty parseable by DateTime;
  • 'domain' and 'path' should be either not empty or an URL where cookie was set should be provided.
  • if $setter is provided, then document at that URL should be allowed to set a cookie for that 'domain'. If $setter is not provided, then no domain checks will be made.

'expires' field will be converted to ISO8601 format from COOKIE format, 'domain' and 'path' will be set from setter URL if empty.

Parameters
array$cookiecookie data, as returned by HTTP_Request2_Response::getCookies()
Net_URL2$setterURL of the document that sent Set-Cookie header
Returns
array Updated cookie array
Exceptions
HTTP_Request2_LogicException
HTTP_Request2_MessageException

Definition at line 122 of file CookieJar.php.

static HTTP_Request2_CookieJar::checkDomainsList ( array  $domainParts,
  $listNode 
)
staticprotected

Recursive helper method for getRegisteredDomain()

Parameters
array$domainPartsremaining domain parts
mixed$listNodenode in HTTP_Request2_CookieJar::$psl to check
Returns
string|null concatenated domain parts, null in case of error

Definition at line 471 of file CookieJar.php.

HTTP_Request2_CookieJar::domainMatch (   $requestHost,
  $cookieDomain 
)

Checks whether a cookie domain matches a request host.

The method is used by store() to check for whether a document at given URL can set a cookie with a given domain attribute and by getMatching() to find cookies matching the request URL.

Parameters
string$requestHostrequest host
string$cookieDomaincookie domain
Returns
bool match success

Definition at line 398 of file CookieJar.php.

HTTP_Request2_CookieJar::getAll ( )

Returns all cookies stored in a jar

Returns
array

Definition at line 286 of file CookieJar.php.

HTTP_Request2_CookieJar::getMatching ( Net_URL2  $url,
  $asString = false 
)

Returns all cookies matching a given request URL

The following checks are made:

  • cookie domain should match request host
  • cookie path should be a prefix for request path
  • 'secure' cookies will only be sent for HTTPS requests
Parameters
Net_URL2$urlRequest url
bool$asStringWhether to return cookies as string for "Cookie: " header
Returns
array|string Matching cookies

Definition at line 246 of file CookieJar.php.

static HTTP_Request2_CookieJar::getRegisteredDomain (   $domain)
static

Removes subdomains to get the registered domain (the first after top-level)

The method will check Public Suffix List to find out where top-level domain ends and registered domain starts. It will remove domain parts to the left of registered one.

Parameters
string$domaindomain name
Returns
string|bool registered domain, will return false if $domain is either invalid or a TLD itself

Definition at line 431 of file CookieJar.php.

HTTP_Request2_CookieJar::now ( )
protected

Returns current time formatted in ISO-8601 at UTC timezone

Returns
string

Definition at line 91 of file CookieJar.php.

HTTP_Request2_CookieJar::serialize ( )

Returns string representation of object

Returns
string
See Also
Serializable::serialize()

Definition at line 342 of file CookieJar.php.

HTTP_Request2_CookieJar::serializeSessionCookies (   $serialize)

Sets whether session cookies should be serialized when serializing the jar

Parameters
boolean$serializeserialize?

Definition at line 304 of file CookieJar.php.

HTTP_Request2_CookieJar::store ( array  $cookie,
Net_URL2  $setter = null 
)

Stores a cookie in the jar

Parameters
array$cookiecookie data, as returned by HTTP_Request2_Response::getCookies()
Net_URL2$setterURL of the document that sent Set-Cookie header
Exceptions
HTTP_Request2_Exception

Definition at line 199 of file CookieJar.php.

HTTP_Request2_CookieJar::unserialize (   $serialized)

Constructs the object from serialized string

Parameters
string$serializedstring representation
See Also
Serializable::unserialize()

Definition at line 366 of file CookieJar.php.

HTTP_Request2_CookieJar::usePublicSuffixList (   $useList)

Sets whether Public Suffix List should be used for restricting cookie-setting

Without PSL domainMatch() will only prevent setting cookies for top-level domains like '.com' or '.org'. However, it will not prevent setting a cookie for '.co.uk' even though only third-level registrations are possible in .uk domain.

With the List it is possible to find the highest level at which a domain may be registered for a particular top-level domain and consequently prevent cookies set for '.co.uk' or '.msk.ru'. The same list is used by Firefox, Chrome and Opera browsers to restrict cookie setting.

Note that PSL is licensed differently to HTTP_Request2 package (refer to the license information in public-suffix-list.php), so you can disable its use if this is an issue for you.

Parameters
boolean$useListuse the list?

http://publicsuffix.org/learn/

Definition at line 330 of file CookieJar.php.

Member Data Documentation

HTTP_Request2_CookieJar::$cookies = array()
protected

Definition at line 50 of file CookieJar.php.

HTTP_Request2_CookieJar::$psl = array()
staticprotected

Definition at line 69 of file CookieJar.php.

HTTP_Request2_CookieJar::$serializeSession = false
protected

Definition at line 56 of file CookieJar.php.

HTTP_Request2_CookieJar::$useList = true
protected

Definition at line 62 of file CookieJar.php.


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