Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/PageCache/RequestPolicy/CommandLineOrUnsafeMethod.php \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod
  2. 9 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

  • class \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod implements \Drupal\Core\PageCache\RequestPolicyInterface

Expanded class hierarchy of CommandLineOrUnsafeMethod

2 files declare their use of CommandLineOrUnsafeMethod
DefaultRequestPolicy.php in core/lib/Drupal/Core/PageCache/DefaultRequestPolicy.php
DefaultRequestPolicy.php in core/modules/dynamic_page_cache/src/PageCache/RequestPolicy/DefaultRequestPolicy.php

File

core/lib/Drupal/Core/PageCache/RequestPolicy/CommandLineOrUnsafeMethod.php, line 15

Namespace

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

  /**
   * {@inheritdoc}
   */
  public function check(Request $request) {
    if ($this
      ->isCli() || !$request
      ->isMethodCacheable()) {
      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
CommandLineOrUnsafeMethod::isCli protected function Indicates whether this is a CLI request.