Skip to content

Commit

Permalink
ifMatch type handling, small potential bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Hergen Dillema committed Aug 18, 2021
1 parent 7af3821 commit 5a6835a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
@@ -1,7 +1,7 @@
{
"name": "werk365/etagconditionals",
"description": "Laravel package to enable support for ETags and handling If-Match and If-None-Match conditional requests",
"version": "1.3.0",
"version": "1.3.1",
"license": "MIT",
"authors": [
{
Expand Down
16 changes: 13 additions & 3 deletions src/Middleware/IfMatch.php
Expand Up @@ -36,16 +36,26 @@ public function handle(Request $request, Closure $next)
$getEtag = EtagConditionals::getEtag($request, $getResponse);
$ifMatch = $request->header('If-Match');

if($ifMatch === null){
return response(null, 412);
}

$ifMatchArray = (is_string($ifMatch))?
explode(',', $ifMatch):
$ifMatch;

// Strip W/ if weak comparison algorithm can be used
if (config('etagconditionals.if_match_weak')) {
$ifMatch = str_replace('W/', '', $ifMatch);
foreach($ifMatchArray as &$match){
$match = str_replace('W/', '', $match);
}
unset($match);
}

$ifMatchArray = explode(',', $ifMatch);

foreach ($ifMatchArray as &$match) {
$match = trim($match);
}
unset($match);

// Compare current and request hashes
// Also allow wildcard (*) values
Expand Down

0 comments on commit 5a6835a

Please sign in to comment.