You are here

public function CommandLineOrUnsafeMethod::check in Drupal 8

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/PageCache/RequestPolicy/CommandLineOrUnsafeMethod.php \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod::check()
  2. 10 core/lib/Drupal/Core/PageCache/RequestPolicy/CommandLineOrUnsafeMethod.php \Drupal\Core\PageCache\RequestPolicy\CommandLineOrUnsafeMethod::check()

Determines whether delivery of a cached page should be attempted.

Note that the request-policy check runs very early. In particular it is not possible to determine the logged in user. Also the current route match is not yet present when the check runs. Therefore, request-policy checks need to be designed in a way such that they do not depend on any other service and only take in account the information present on the incoming request.

When matching against the request path, special attention is needed to support path prefixes which are often used on multilingual sites.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The incoming request object.

Return value

string|null One of static::ALLOW, static::DENY or NULL. Calling code may attempt to deliver a cached page if static::ALLOW is returned. Returns NULL if the policy is not specified for the given request.

Overrides RequestPolicyInterface::check

File

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

Class

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

Namespace

Drupal\Core\PageCache\RequestPolicy

Code

public function check(Request $request) {
  if ($this
    ->isCli() || !$request
    ->isMethodCacheable()) {
    return static::DENY;
  }
}