You are here

class CommandLineOrUnsafeMethod in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/PageCache/RequestPolicy/CommandLineOrUnsafeMethod.php \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod

Reject when running from the command line or when HTTP method is not safe.

The policy denies caching if the request was initiated from the command line interface (drush) or the request method is neither GET nor HEAD (see RFC 2616, section 9.1.1 - Safe Methods).

Hierarchy

Expanded class hierarchy of CommandLineOrUnsafeMethod

1 file declares its use of CommandLineOrUnsafeMethod
DefaultRequestPolicy.php in core/modules/dynamic_page_cache/src/PageCache/RequestPolicy/DefaultRequestPolicy.php
Contains \Drupal\dynamic_page_cache\PageCache\RequestPolicy\DefaultRequestPolicy.

File

core/lib/Drupal/Core/PageCache/RequestPolicy/CommandLineOrUnsafeMethod.php, line 20
Contains \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod.

Namespace

Drupal\Core\PageCache\RequestPolicy
View source
class CommandLineOrUnsafeMethod implements RequestPolicyInterface {

  /**
   * {@inheritdoc}
   */
  public function check(Request $request) {
    if ($this
      ->isCli() || !$request
      ->isMethodSafe()) {
      return static::DENY;
    }
  }

  /**
   * Indicates whether this is a CLI request.
   */
  protected function isCli() {
    return PHP_SAPI === 'cli';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommandLineOrUnsafeMethod::check public function Determines whether delivery of a cached page should be attempted. Overrides RequestPolicyInterface::check
CommandLineOrUnsafeMethod::isCli protected function Indicates whether this is a CLI request.
RequestPolicyInterface::ALLOW constant Allow delivery of cached pages.
RequestPolicyInterface::DENY constant Deny delivery of cached pages.