You are here

class CommandLineOrUnsafeMethod in Drupal 9

Same name and namespace in other branches
  1. 8 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

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 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.