You are here

function advagg_relocate_process_http_request in Advanced CSS/JS Aggregation 7.2

Get the TTL and fix UTF-8 encoding.

Parameters

object $response: Response from http request.

string $type: Can be css, js, or font.

2 calls to advagg_relocate_process_http_request()
advagg_relocate_get_remote_data in advagg_relocate/advagg_relocate.advagg.inc
Gets external CSS and JS files; caches and returns response.
advagg_relocate_get_remote_font_data in advagg_relocate/advagg_relocate.advagg.inc
Gets external CSS files; caches it and returns css font rules.

File

advagg_relocate/advagg_relocate.advagg.inc, line 539
Advanced aggregation relocate module.

Code

function advagg_relocate_process_http_request(&$response, $type) {

  // Get ttl from response.
  $ttl = 0;
  if ($type === 'css') {
    $ttl = variable_get('advagg_relocate_css_min_ttl', ADVAGG_RELOCATE_CSS_MIN_TTL);
  }
  if ($type === 'js') {
    $ttl = variable_get('advagg_relocate_js_min_ttl', ADVAGG_RELOCATE_JS_MIN_TTL);
  }
  $now = REQUEST_TIME;
  if (isset($response->headers['expires'])) {
    $expires = strtotime($response->headers['expires']);
    if (isset($response->headers['date'])) {
      $now = max($now, strtotime($response->headers['date']));
    }
    $ttl = max($ttl, $expires - $now);
  }
  if (isset($response->headers['cache-control'])) {
    $cache_control_array = advagg_relocate_parse_cache_control($response->headers['cache-control']);
    if (isset($cache_control_array['max-age']) && is_numeric($cache_control_array['max-age'])) {
      $ttl = max($ttl, $cache_control_array['max-age']);
    }
    if (isset($cache_control_array['s-maxage']) && is_numeric($cache_control_array['s-maxage'])) {
      $ttl = max($ttl, $cache_control_array['s-maxage']);
    }
  }
  $response->ttl = $ttl;

  // If a BOM is found, convert the string to UTF-8.
  if (isset($response->data)) {
    $encoding = advagg_get_encoding_from_bom($response->data);
    if (!empty($encoding)) {
      $response->data = advagg_convert_to_utf8($response->data, $encoding);
    }
  }

  // Call hook_advagg_relocate_process_http_request_alter().
  drupal_alter('advagg_relocate_process_http_request', $response, $type);
}