Commit eb3bb842 authored by Alexander Shumenko's avatar Alexander Shumenko Committed by Alexander Shumenko
Browse files

Issue #3264583 by shumer, liquidcms, arnaud-brugnon: Fails for anon when anon...

Issue #3264583 by shumer, liquidcms, arnaud-brugnon: Fails for anon when anon not enabled ($this->request is null)
parent 2cd23b10
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -177,6 +177,19 @@ class CacheManager implements CacheManagerInterface, CacheTagsInvalidatorInterfa
    $this->killSwitch = $killSwitch;
  }

  /**
   * Gets the request object.
   *
   * @return \Symfony\Component\HttpFoundation\Request
   *   The request object.
   */
  protected function getRequest() {
    if (!$this->request) {
      $this->request = \Drupal::request();
    }
    return $this->request;
  }

  /**
   * {@inheritdoc}
   */
@@ -351,7 +364,7 @@ class CacheManager implements CacheManagerInterface, CacheTagsInvalidatorInterfa
   *   ESI enable state.
   */
  public function isEsiRequest() {
    $request_uri = $this->request->getRequestUri();
    $request_uri = $this->getRequest()->getRequestUri();

    // Check if we're not on user data route which is already an ESI callback.
    if (stripos($request_uri, '/adv_varnish/esi/user_blocks') !== FALSE) {
@@ -464,8 +477,8 @@ class CacheManager implements CacheManagerInterface, CacheTagsInvalidatorInterfa

    // Check if we acn be on disabled domain.
    $excluded_urls = explode(PHP_EOL, $this->config->get('available.excluded_urls'));
    $request_uri = $this->request->getRequestUri();
    $host = $this->request->getHost();
    $request_uri = $this->getRequest()->getRequestUri();
    $host = $this->getRequest()->getHost();
    foreach ($excluded_urls as $line) {
      $rule = explode('|', trim($line));
      if ((($rule[0] === '*') || ($host === $rule[0]))
@@ -484,7 +497,7 @@ class CacheManager implements CacheManagerInterface, CacheTagsInvalidatorInterfa
    }

    // Disable cache if page_cache_kill_switch is called.
    if ($this->killSwitch->check(new Response(), $this->request) == 'deny') {
    if ($this->killSwitch->check(new Response(), $this->getRequest()) == 'deny') {
      $this->log(RfcLogLevel::DEBUG, 'Cache disabled - page_kill_switch.');
      return FALSE;
    }
@@ -531,7 +544,7 @@ class CacheManager implements CacheManagerInterface, CacheTagsInvalidatorInterfa
  public function purgeUserBlocks() {
    $esi = $this->config->get('available.esi');
    $purge_user_blocks = $this->config->get('available.esi_purge_user_blocks');
    if ($esi && $purge_user_blocks && $this->request->isMethod('POST') && $this->account->id() > 0) {
    if ($esi && $purge_user_blocks && $this->getRequest()->isMethod('POST') && $this->account->id() > 0) {
      $this->invalidateTags(['user:' . $this->account->id()]);
    }
  }