function aggregator_test_feed

Page callback. Generates a test feed and simulates last-modified and etags.

Parameters

$use_last_modified: Set TRUE to send a last modified header.

$use_etag: Set TRUE to send an etag.

1 string reference to 'aggregator_test_feed'
aggregator_test_menu in drupal/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.module
Implements hook_menu().

File

drupal/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.module, line 34

Code

function aggregator_test_feed($use_last_modified = FALSE, $use_etag = FALSE) {
  $last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
  $etag = Crypt::hashBase64($last_modified);
  $if_modified_since = strtotime(Drupal::request()->server
    ->get('HTTP_IF_MODIFIED_SINCE'));
  $if_none_match = stripslashes(Drupal::request()->server
    ->get('HTTP_IF_NONE_MATCH'));

  // Send appropriate response. We respond with a 304 not modified on either
  // etag or on last modified.
  if ($use_last_modified) {
    drupal_add_http_header('Last-Modified', gmdate(DATE_RFC1123, $last_modified));
  }
  if ($use_etag) {
    drupal_add_http_header('ETag', $etag);
  }

  // Return 304 not modified if either last modified or etag match.
  if ($last_modified == $if_modified_since || $etag == $if_none_match) {
    drupal_add_http_header('Status', '304 Not Modified');
    return;
  }

  // The following headers force validation of cache:
  drupal_add_http_header('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
  drupal_add_http_header('Cache-Control', 'must-revalidate');
  drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');

  // Read actual feed from file.
  $file_name = __DIR__ . '/aggregator_test_rss091.xml';
  $handle = fopen($file_name, 'r');
  $feed = fread($handle, filesize($file_name));
  fclose($handle);
  print $feed;
}