You are here

public function Fastly::purgeQuery in Fastly 7.2

Same name and namespace in other branches
  1. 7 fastly.api.inc \Fastly::purgeQuery()

Performs an actual purge request for the given url.

1 call to Fastly::purgeQuery()
Fastly::purgePath in ./fastly.api.inc
Purge cache by path.

File

./fastly.api.inc, line 152
Contains Faslt class that handles API calls to the Fastly service.

Class

Fastly
Fastly API for Drupal.

Code

public function purgeQuery($original_url) {
  $this->webhook
    ->sendMessage($original_url . " " . t("purged"), "INFO", "purge_actions");
  $url = url($original_url, array(
    'absolute' => TRUE,
    'alias' => TRUE,
  ));
  $options = array(
    'method' => 'PURGE',
  );
  if (variable_get('fastly_purge_type', 'immediate') == 'soft') {
    $options['headers']['Fastly-Soft-Purge'] = 1;
  }
  if (module_exists('httprl')) {

    // We just want to execute the queue but not wait.
    $options['blocking'] = FALSE;

    // Support for alternative PURGE endpoint.
    $purge_endpoint = variable_get('fastly_purge_endpoint', NULL);
    if ($purge_endpoint) {

      // Extract Host header from URL.
      $parsed_url = @parse_url($url);
      $default_port = $parsed_url['scheme'] == 'https' ? 443 : 80;
      $port = isset($parsed_url['port']) ? $parsed_url['port'] : $default_port;
      $options['headers']['Host'] = $parsed_url['host'] . ($port != $default_port ? ':' . $port : '');

      // Use the purge endpoint as base URL for the PURGE request.
      $url = url($original_url, array(
        'absolute' => TRUE,
        'alias' => TRUE,
        'base_url' => $purge_endpoint,
      ));
    }
    httprl_request(array(
      $url,
    ), $options);
    httprl_send_request();
  }
  else {
    drupal_http_request($url, $options);
  }
}