Skip to content

Commit

Permalink
[11.x] Introduce if_successful directive for conditional caching cont…
Browse files Browse the repository at this point in the history
…rol (#50903)

* Introduce if_successful directive for conditional caching control

* Update SetCacheHeaders.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
MinaWilliam and taylorotwell authored Apr 3, 2024
1 parent 209800f commit 94bfff1
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Http/Middleware/SetCacheHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public function handle($request, Closure $next, $options = [])
$options = $this->parseOptions($options);
}

if (! $response->isSuccessful()) {
return $response;
}

if (isset($options['etag']) && $options['etag'] === true) {
$options['etag'] = $response->getEtag() ?? md5($response->getContent());
}
Expand Down

0 comments on commit 94bfff1

Please sign in to comment.