You are here

function advagg_missing_send_file in Advanced CSS/JS Aggregation 7

Same name and namespace in other branches
  1. 6 advagg.missing.inc \advagg_missing_send_file()

Send the file or send a 307 redirect.

Parameters

$filepath: filename

$uri: css or js

1 call to advagg_missing_send_file()
advagg_missing_regenerate in includes/missing.inc
regenerates a missing css file.

File

includes/missing.inc, line 131
Advanced aggregation module; 404 handler.

Code

function advagg_missing_send_file($filepath, $uri, $type) {
  if (!headers_sent()) {

    // Code from file_download.
    if (file_exists($filepath)) {
      $headers = module_invoke_all('file_download', $filepath, $type);
      if ($key = array_search(-1, $headers)) {
        unset($headers[$key]);
      }

      // Remove all previously set Cache-Control headers, because we're going to
      // override it. Since multiple Cache-Control headers might have been set,
      // simply setting a new, overriding header isn't enough: that would only
      // override the *last* Cache-Control header. Yay for PHP!
      foreach ($headers as $key => $header) {
        if (strpos($header, 'Cache-Control:') === 0) {
          unset($headers[$key]);
        }
        elseif (strpos($header, 'ETag:') === 0) {
          unset($headers[$key]);
        }
      }
      if (function_exists('header_remove')) {
        header_remove('Cache-Control');
        header_remove('ETag');
      }
      else {
        drupal_add_http_header('Cache-Control', '');
        drupal_add_http_header('Cache-Control', '');
        drupal_add_http_header('ETag', '');
        drupal_add_http_header('ETag', '');
      }

      // Set a far future Cache-Control header (480 weeks), which prevents
      // intermediate caches from transforming the data and allows any
      // intermediate cache to cache it, since it's marked as a public resource.
      $headers[] = "Cache-Control: max-age=290304000, no-transform, public";
      if (count($headers)) {
        advagg_missing_file_transfer($filepath, $headers);
      }
    }

    // advagg_missing_file_transfer didn't run/send data, redirect via header.
    header('Location: ' . $uri, TRUE, 307);
    usleep(250000);

    // Sleep for 250ms
  }
}