Browse Source

Add checkbox to disable caching functionality.

pull/393/head
Adam Vessey 11 years ago
parent
commit
67999de1e7
  1. 6
      includes/admin.form.inc
  2. 17
      includes/datastream.inc

6
includes/admin.form.inc

@ -55,6 +55,12 @@ function islandora_repository_admin(array $form, array &$form_state) {
'#description' => t('The PID of the Root Collection Object'), '#description' => t('The PID of the Root Collection Object'),
'#required' => TRUE, '#required' => TRUE,
), ),
'islandora_use_datastream_cache_headers' => array(
'#type' => 'checkbox',
'#title' => t('Generate/parse datastream HTTP cache headers'),
'#description' => t('HTTP caching can reduce network traffic, by allowing clients to used cached copies.'),
'#default_value' => variable_get('islandora_use_datastream_cache_headers', TRUE),
),
), ),
'islandora_namespace' => array( 'islandora_namespace' => array(
'#type' => 'fieldset', '#type' => 'fieldset',

17
includes/datastream.inc

@ -85,6 +85,15 @@ function islandora_view_datastream(AbstractDatastream $datastream, $download = F
/** /**
* Parse "etags" from HTTP If-Match or If-None-Match headers. * Parse "etags" from HTTP If-Match or If-None-Match headers.
* *
* Parses from the CSV-like struture supported by HTTP headers into an array,
* so `"asdf", "fdsa", W/"2132"` should become an array containing the strings:
* - asdf
* - fdsa
* - 2132
*
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.24
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.26
*
* @param string $header_value * @param string $header_value
* The value from the headers. * The value from the headers.
* *
@ -93,7 +102,9 @@ function islandora_view_datastream(AbstractDatastream $datastream, $download = F
*/ */
function islandora_parse_http_match_headers($header_value) { function islandora_parse_http_match_headers($header_value) {
$matches = array(); $matches = array();
// Match the CSV-like structure supported by the HTTP headers.
$count = preg_match_all('/(((W\/)?("?)(\*|.+?)\4)(, +)?)/', $header_value, $matches); $count = preg_match_all('/(((W\/)?("?)(\*|.+?)\4)(, +)?)/', $header_value, $matches);
// The fifth sub-expression/group is which will contain the etags.
return $matches[5]; return $matches[5];
} }
@ -105,13 +116,17 @@ function islandora_parse_http_match_headers($header_value) {
* *
* @return int * @return int
* An integer representing the HTTP response code. One of: * An integer representing the HTTP response code. One of:
* - 200: Proceed as normal. * - 200: Proceed as normal. (Full download).
* - 304: Resource hasn't changed; pass cache validation. * - 304: Resource hasn't changed; pass cache validation.
* - 412: Resource has channged; fail cache validation. * - 412: Resource has channged; fail cache validation.
* *
* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
*/ */
function islandora_view_datastream_cache_check(AbstractDatastream $datastream) { function islandora_view_datastream_cache_check(AbstractDatastream $datastream) {
if (!variable_get('islandora_use_datastream_cache_headers', TRUE)) {
return 200;
}
// Let's assume that if we get here, we'll be able to complete the request. // Let's assume that if we get here, we'll be able to complete the request.
$return = 200; $return = 200;

Loading…
Cancel
Save