Moodle  2.2.1
http://www.collinsharper.com
HTTP_ConditionalGet Class Reference

Public Member Functions

 __construct ($spec)
 getHeaders ()
 setContentLength ($bytes)
 sendHeaders ()

Static Public Member Functions

static check ($lastModifiedTime=null, $isPublic=false, $options=array())
static gmtDate ($time)

Data Fields

 $cacheIsValid = null

Protected Member Functions

 _setEtag ($hash, $scope)
 _setLastModified ($time)
 _isCacheValid ()
 resourceMatchedEtag ()
 normalizeEtag ($etag)
 resourceNotModified ()

Protected Attributes

 $_headers = array()
 $_lmTime = null
 $_etag = null
 $_stripEtag = false

Detailed Description

Definition at line 63 of file ConditionalGet.php.


Constructor & Destructor Documentation

__construct ( spec)
Parameters:
array$specoptions

'isPublic': (bool) if true, the Cache-Control header will contain "public", allowing proxies to cache the content. Otherwise "private" will be sent, allowing only browser caching. (default false)

'lastModifiedTime': (int) if given, both ETag AND Last-Modified headers will be sent with content. This is recommended.

'encoding': (string) if set, the header "Vary: Accept-Encoding" will always be sent and a truncated version of the encoding will be appended to the ETag. E.g. "pub123456;gz". This will also trigger a more lenient checking of the client's If-None-Match header, as the encoding portion of the ETag will be stripped before comparison.

'contentHash': (string) if given, only the ETag header can be sent with content (only HTTP1.1 clients can conditionally GET). The given string should be short with no quote characters and always change when the resource changes (recommend md5()). This is not needed/used if lastModifiedTime is given.

'eTag': (string) if given, this will be used as the ETag header rather than values based on lastModifiedTime or contentHash. Also the encoding string will not be appended to the given value as described above.

'invalidate': (bool) if true, the client cache will be considered invalid without testing. Effectively this disables conditional GET. (default false)

'maxAge': (int) if given, this will set the Cache-Control max-age in seconds, and also set the Expires header to the equivalent GMT date. After the max-age period has passed, the browser will again send a conditional GET to revalidate its cache.

Returns:
null

Definition at line 112 of file ConditionalGet.php.

Here is the call graph for this function:


Member Function Documentation

_isCacheValid ( ) [protected]

Determine validity of client cache and queue 304 header if valid

Definition at line 286 of file ConditionalGet.php.

Here is the call graph for this function:

Here is the caller graph for this function:

_setEtag ( hash,
scope 
) [protected]

Definition at line 271 of file ConditionalGet.php.

Here is the caller graph for this function:

_setLastModified ( time) [protected]

Definition at line 277 of file ConditionalGet.php.

Here is the call graph for this function:

Here is the caller graph for this function:

static check ( lastModifiedTime = null,
isPublic = false,
options = array() 
) [static]

Exit if the client's cache is valid for this resource

This is a convenience method for common use of the class

Parameters:
int$lastModifiedTimeif given, both ETag AND Last-Modified headers will be sent with content. This is recommended.
bool$isPublic(default false) if true, the Cache-Control header will contain "public", allowing proxies to cache the content. Otherwise "private" will be sent, allowing only browser caching.
array$options(default empty) additional options for constructor
Returns:
null

Definition at line 236 of file ConditionalGet.php.

Get array of output headers to be sent

In the case of 304 responses, this array will only contain the response code header: array('_responseCode' => 'HTTP/1.0 304 Not Modified')

Otherwise something like: array( 'Cache-Control' => 'max-age=0, public' ,'ETag' => '"foobar"' )

Returns:
array

Definition at line 176 of file ConditionalGet.php.

static gmtDate ( time) [static]

Get a GMT formatted date for use in HTTP headers

header('Expires: ' . HTTP_ConditionalGet::gmtdate($time));

Parameters:
int$timeunix timestamp
Returns:
string

Definition at line 261 of file ConditionalGet.php.

Here is the caller graph for this function:

normalizeEtag ( etag) [protected]

Definition at line 323 of file ConditionalGet.php.

Here is the caller graph for this function:

resourceMatchedEtag ( ) [protected]

Definition at line 301 of file ConditionalGet.php.

Here is the call graph for this function:

Here is the caller graph for this function:

resourceNotModified ( ) [protected]

Definition at line 330 of file ConditionalGet.php.

Here is the call graph for this function:

Here is the caller graph for this function:

Send headers

See also:
getHeaders()

Note this doesn't "clear" the headers. Calling sendHeaders() will call header() again (but probably have not effect) and getHeaders() will still return the headers.

Returns:
null

Definition at line 208 of file ConditionalGet.php.

setContentLength ( bytes)

Set the Content-Length header in bytes

With most PHP configs, as long as you don't flush() output, this method is not needed and PHP will buffer all output and set Content-Length for you. Otherwise you'll want to call this to let the client know up front.

Parameters:
int$bytes
Returns:
int copy of input $bytes

Definition at line 192 of file ConditionalGet.php.


Field Documentation

$_etag = null [protected]

Definition at line 268 of file ConditionalGet.php.

$_headers = array() [protected]

Definition at line 266 of file ConditionalGet.php.

$_lmTime = null [protected]

Definition at line 267 of file ConditionalGet.php.

$_stripEtag = false [protected]

Definition at line 269 of file ConditionalGet.php.

$cacheIsValid = null

Definition at line 73 of file ConditionalGet.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations