Skip to content

Commit

Permalink
Max-age can be merged into s-maxage to have a least one value
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Dec 8, 2018
1 parent 9c3e6aa commit 6f1f9cf
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function add(Response $response)
}

$this->storeRelativeAgeDirective('max-age', $response->headers->getCacheControlDirective('max-age'), $age);
$this->storeRelativeAgeDirective('s-maxage', $response->headers->getCacheControlDirective('s-maxage'), $age);
$this->storeRelativeAgeDirective('s-maxage', $response->headers->getCacheControlDirective('s-maxage') ?: $response->headers->getCacheControlDirective('max-age'), $age);

$expires = $response->getExpires();
$expires = null !== $expires ? $expires->format('U') - $response->getDate()->format('U') : null;
Expand Down Expand Up @@ -133,12 +133,20 @@ public function update(Response $response)

$response->headers->set('Cache-Control', implode(', ', array_keys($flags)));

$maxAge = null;
$sMaxage = null;

if ($this->ageDirectives['max-age']) {
$response->headers->addCacheControlDirective('max-age', $this->ageDirectives['max-age'] + $this->age);
$maxAge = $this->ageDirectives['max-age'] + $this->age;
$response->headers->addCacheControlDirective('max-age', $maxAge);
}

if ($this->ageDirectives['s-maxage']) {
$response->headers->addCacheControlDirective('s-maxage', $this->ageDirectives['s-maxage'] + $this->age);
$sMaxage = $this->ageDirectives['s-maxage'] + $this->age;

if ($maxAge !== $sMaxage) {
$response->headers->addCacheControlDirective('s-maxage', $sMaxage);
}
}

if ($this->ageDirectives['expires']) {
Expand Down

0 comments on commit 6f1f9cf

Please sign in to comment.