You are here

function authcache_varnish_authcache_debug_info in Authenticated User Page Caching (Authcache) 7.2

Implements hoook_authcache_debug_info().

File

modules/authcache_varnish/authcache_varnish.module, line 79
Authcache cache backend module for varnish.

Code

function authcache_varnish_authcache_debug_info() {
  $debuginfo = array();

  // Test whether Cache-Control header is present.
  $cache_control = '';
  $cc = preg_grep('/^cache-control:/i', headers_list());
  $cache_control_present = !empty($cc);
  if ($cache_control_present) {
    list($headername, $cache_control) = explode(': ', reset($cc), 2);
    unset($headername);
    $matched = preg_match('/^.*max-age=(\\d+).*$/i', $cache_control, $matches);
    $max_age = $matched ? $matches[1] : 0;

    // Warn if there is a Cache-Control header on response but max-age is
    // missing or zero.
    if ($matched && !$max_age) {
      authcache_debug_log('Varnish', t('Cache-Control header with max-age=0 on response. Varnish will not store this response.'));
    }
  }
  else {

    // Warn if there is no Cache-Control header on response.
    authcache_debug_log('Varnish', t('Cache-Control header missing from response.'));
  }

  // Test whether request came in through reverse proxy.
  $varnish_present = authcache_varnish_request_validate();
  if (!$varnish_present) {

    // Warn if authcache_varnish_request_validate failed.
    authcache_debug_log('Varnish', t('Request did not came in via a configured reverse proxy server. Authcache-Key not added to response.'));
  }

  // Return debug info displayed in the debug widget.
  $debuginfo['Cache-Control'] = $cache_control_present ? $cache_control : t('Missing');
  $debuginfo['Via reverse proxy'] = $varnish_present ? t('Yes') : t('No');
  return $debuginfo;
}