From 1f63146f3f34be667f43fb6cc1b87aa59a403b50 Mon Sep 17 00:00:00 2001 From: nitriques Date: Tue, 7 Jun 2016 20:31:34 -0400 Subject: [PATCH] Restored the max_age option Previoulsy lost in the refactor. Port of 70103eb5511761eefb3adca4c7da9dccff0f7d25 See #88 --- README.markdown | 5 +++++ extension.driver.php | 21 ++++++++++++++++++++- extension.meta.xml | 2 +- lib/class.jit.php | 8 ++++++-- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index 5eba204..4329c6f 100644 --- a/README.markdown +++ b/README.markdown @@ -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) ), ``` @@ -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 diff --git a/extension.driver.php b/extension.driver.php index 90e1f0f..6432941 100755 --- a/extension.driver.php +++ b/extension.driver.php @@ -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 @@ -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() diff --git a/extension.meta.xml b/extension.meta.xml index 15ce7e9..2a4b871 100644 --- a/extension.meta.xml +++ b/extension.meta.xml @@ -16,7 +16,7 @@ - + - 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. diff --git a/lib/class.jit.php b/lib/class.jit.php index 75786a7..ce82980 100644 --- a/lib/class.jit.php +++ b/lib/class.jit.php @@ -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));