You are here

function authcache_authcache_cancel in Authenticated User Page Caching (Authcache) 7.2

Implements hook_authcache_cancel().

Related topics

File

./authcache.module, line 1041
Authenticated User Page Caching (and anonymous users, too!)

Code

function authcache_authcache_cancel() {

  // Check content-type.
  $content_type = authcache_get_content_type();
  $allowed_mimetypes = preg_split('/(\\r\\n?|\\n)/', variable_get('authcache_mimetype', AUTHCACHE_MIMETYPE_DEFAULT), -1, PREG_SPLIT_NO_EMPTY);
  if (!in_array($content_type['mimetype'], $allowed_mimetypes)) {
    return t('Only cache allowed HTTP content types (HTML, JS, etc)');
  }

  // Check http status.
  if (variable_get('authcache_http200', FALSE) && _authcache_get_http_status() != 200) {
    return t('HTTP status 404/403s/etc');
  }

  // Check headers already were sent.
  if (headers_sent() || ob_get_level() < _authcache_original_ob_level()) {
    return t('Private file transfers or headers were unexpectedly sent');
  }

  // Make sure "Location" redirect isn't used.
  foreach (headers_list() as $header) {
    if (strpos($header, 'Location:') === 0) {
      return t('Location header detected');
    }
  }

  // Don't cache pages with PHP errors (Drupal can't catch fatal errors).
  if (function_exists('error_get_last') && ($error = error_get_last())) {
    switch ($error['type']) {
      case E_NOTICE:
      case E_USER_NOTICE:
      case E_DEPRECATED:
      case E_USER_DEPRECATED:

        // Ignore these errors.
        break;
      default:

        // Let user know there is PHP error and return.
        return t('PHP Error: @error', array(
          '@error' => $error['message'],
        ));
    }
  }

  // Don't cache if the vary header is not the same as the one required by the
  // active backend.
  if (!authcache_backend_check_vary()) {
    return t('The Vary header was modified during the request');
  }
}