Skip to content

Commit

Permalink
Normalize query string parameters before hashing (#426)
Browse files Browse the repository at this point in the history
* Normalize query string parameters

* removes duplicate method

* Update DefaultHasher.php

Co-authored-by: Freek Van der Herten <[email protected]>
  • Loading branch information
cosmastech and freekmurze authored Jan 23, 2023
1 parent eb1abe8 commit 263761a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Hasher/DefaultHasher.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ public function getHashFor(Request $request): string
$cacheNameSuffix = $this->getCacheNameSuffix($request);

return 'responsecache-' . md5(
"{$request->getHost()}-{$request->getRequestUri()}-{$request->getMethod()}/$cacheNameSuffix"
"{$request->getHost()}-{$this->getNormalizedRequestUri($request)}-{$request->getMethod()}/$cacheNameSuffix"
);
}

protected function getNormalizedRequestUri(Request $request): string
{
if ($queryString = $request->getQueryString()) {
$queryString = '?'.$queryString;
}

return $request->getBaseUrl().$request->getPathInfo().$queryString;
}

protected function getCacheNameSuffix(Request $request)
{
if ($request->attributes->has('responsecache.cacheNameSuffix')) {
Expand Down

0 comments on commit 263761a

Please sign in to comment.