-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix user hash tag being applied to main response when using Sf Proxy (#…
…64) * Fix user hash tag being applied to main response when using Symfony Proxy * CS * Update UserContextSubscriber.php
- Loading branch information
Showing
2 changed files
with
8 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,19 +8,18 @@ | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
use Symfony\Component\HttpKernel\Event\FilterResponseEvent; | ||
use Symfony\Component\HttpKernel\KernelEvents; | ||
use FOS\HttpCache\Handler\TagHandler; | ||
|
||
/** | ||
* Tag /_fos_user_context_hash responses, so we can expire/clear it by tag. | ||
*/ | ||
class UserContextSubscriber implements EventSubscriberInterface | ||
{ | ||
/** @var \FOS\HttpCache\Handler\TagHandler */ | ||
private $tagHandler; | ||
/** @var string */ | ||
private $tagHeader = 'xkey'; | ||
|
||
public function __construct(TagHandler $tagHandler) | ||
public function __construct($tagHeader) | ||
{ | ||
$this->tagHandler = $tagHandler; | ||
$this->tagHeader = $tagHeader; | ||
} | ||
|
||
public static function getSubscribedEvents() | ||
|
@@ -48,9 +47,8 @@ public function tagUserContext(FilterResponseEvent $event) | |
return; | ||
} | ||
|
||
// Improvement potential (mainly relevant if we plan to increase hash ttl notably): | ||
// - Get user id to also add tag by id, so user (un)assign don't need to clear all hashes | ||
// - If done in layer generating this, we could also tag role id so changes to roles only expire affected hashes | ||
$this->tagHandler->addTags(['ez-user-context-hash']); | ||
// We need to set tag directly on repsonse here to make sure this does not also get applied to the main request | ||
// when using Symfony Proxy, as tag handler does not clear tags between requests. | ||
$response->headers->set($this->tagHeader, 'ez-user-context-hash'); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
andrerom
Author
Contributor
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this problem should now be fixed in https://github.com/FriendsOfSymfony/FOSHttpCache/releases/tag/2.5.2