-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clear response tagger after tagging to not leak tags from one respons…
…e to the next
- Loading branch information
Showing
4 changed files
with
45 additions
and
3 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
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 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 |
---|---|---|
|
@@ -21,6 +21,10 @@ | |
/** | ||
* Service for Response cache tagging. | ||
* | ||
* Record tags with this class and then either get the tags header or have the | ||
* tagger add the tags to a PSR-7 response. | ||
* Recorded tags are cleared after tagging a response. | ||
* | ||
* @author David de Boer <[email protected]> | ||
* @author David Buchmann <[email protected]> | ||
* @author André Rømcke <[email protected]> | ||
|
@@ -129,7 +133,18 @@ public function addTags(array $tags) | |
} | ||
|
||
/** | ||
* Set tags on a response. | ||
* Remove all tags that have been recorded. | ||
* | ||
* This is usually called after adding the tags header to a response. It is | ||
* automatically called by the tagResponse method. | ||
*/ | ||
public function clear() | ||
{ | ||
$this->tags = []; | ||
} | ||
|
||
/** | ||
* Set tags on a response and then clear the tags. | ||
* | ||
* @param ResponseInterface $response Original response | ||
* @param bool $replace Whether to replace the current tags | ||
|
@@ -143,10 +158,13 @@ public function tagResponse(ResponseInterface $response, $replace = false) | |
return $response; | ||
} | ||
|
||
$tagsHeaderValue = $this->getTagsHeaderValue(); | ||
$this->clear(); | ||
|
||
if ($replace) { | ||
return $response->withHeader($this->getTagsHeaderName(), $this->getTagsHeaderValue()); | ||
return $response->withHeader($this->getTagsHeaderName(), $tagsHeaderValue); | ||
} | ||
|
||
return $response->withAddedHeader($this->getTagsHeaderName(), $this->getTagsHeaderValue()); | ||
return $response->withAddedHeader($this->getTagsHeaderName(), $tagsHeaderValue); | ||
} | ||
} |
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