Skip to content

Commit

Permalink
Restored the max_age option
Browse files Browse the repository at this point in the history
Previoulsy lost in the refactor.

Port of 70103eb

See #88
  • Loading branch information
nitriques committed Jun 8, 2016
1 parent 2671dd5 commit 1f63146
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
5 changes: 5 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Most of them are editable on Symphony's Preferences page.
'disable_upscaling' => 'yes', // yes/no (editable)
'disable_proxy_transform' => 'yes', // yes/no (editable)
'allow_origin' => '', // string (editable)
'max_age' => null, // integer (hidden)
),
```

Expand Down Expand Up @@ -54,6 +55,10 @@ Setting this to 'yes' will add a HTTP header to the response telling proxies to

If not empty, this value will be sent as the Cross-Origin HTTP header

### max_age

The value, in seconds, for the max-age specifier in the Cache-Control HTTP Header

## Updating

### 2.0.0
Expand Down
21 changes: 20 additions & 1 deletion extension.driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function update($previousVersion = false)
}
}

if (version_compare($previousVersion, '2.0.0', '<')) {
if (version_compare($previousVersion, '2.0.1', '<')) {
try {
// Re-simplify JIT htaccess rule
// see c7cd6183ffd15b9a8b7864df2eb29d3c1d96b5f9
Expand All @@ -191,6 +191,25 @@ public function update($previousVersion = false)
throw new Exception($message);
}
}

if (version_compare($previousVersion, '2.0.2', '<')) {
try {
$maxage = Symphony::Configuration()->get('max-age', 'image');
if (!empty($maxage)) {
Symphony::Configuration()->set('max_age', $maxage, 'image');
}
Symphony::Configuration()->remove('max-age', 'image');
} catch (Exception $ex) {
$message = __(
'An error occured while updating %s. %s',
array(
__('JIT Image Manipulation'),
$ex->getMessage()
)
);
throw new Exception($message);
}
}
}

public function uninstall()
Expand Down
2 changes: 1 addition & 1 deletion extension.meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</author>
</authors>
<releases>
<release version="2.0.1" date="TBA" min="2.6.0" max="2.x.x">
<release version="2.0.2" date="TBA" min="2.6.0" max="2.x.x">
- Refactored all filters to eliminate duplicated code
- Fixed a couple of bugs (#120, #121, #106)
- Fixed a regression in the .htaccess rule, where the file extension was added to the RewriteRule.
Expand Down
8 changes: 6 additions & 2 deletions lib/class.jit.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,12 @@ public function sendImageHeaders($parameters)
$cacheControl .= ', no-transform';
}

// Add max-age directive at the end
$cacheControl .= '; max-age=31536000';
// Use configured max-age or fallback on 3 days (See #88)
$maxage = isset($this->settings['max_age']) ? $this->settings['max_age'] : 86400;
if (!empty($maxage)) {
// Add max-age directive at the end
$cacheControl .= '; max-age=' . $maxage;
}

header('Last-Modified: ' . $last_modified_gmt);
header(sprintf('ETag: "%s"', $etag));
Expand Down

0 comments on commit 1f63146

Please sign in to comment.