send expiry header for redirects
authorChristian Weiske <cweiske@cweiske.de>
Wed, 9 Apr 2014 18:29:16 +0000 (20:29 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Wed, 9 Apr 2014 18:29:16 +0000 (20:29 +0200)
src/phancap/Image.php
www/get.php

index ab3868e..151847e 100644 (file)
@@ -12,6 +12,16 @@ class Image
         $this->name = $name;
     }
 
+    /**
+     * @return integer Unix timestamp
+     */
+    public function getExpiryDate(Options $options)
+    {
+        $mtime = filemtime($this->getPath());
+
+        return $mtime + $options->values['smaxage'];
+    }
+
     public function getMimeType()
     {
         $ext = substr($this->name, -4);
index 15463e4..739aaf8 100644 (file)
@@ -42,6 +42,7 @@ try {
     $img = $rep->getImage($options);
     if ($config->redirect) {
         header('HTTP/1.0 302 Found');
+        header('Expires: ' . date('r', $img->getExpiryDate($options)));
         header('Location: ' . $img->getUrl());
     } else {
         header('Content-type: ' . $img->getMimeType());