]> source.dussan.org Git - redmine.git/commitdiff
Adds Etags on attachments.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 8 Jul 2012 15:26:40 +0000 (15:26 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 8 Jul 2012 15:26:40 +0000 (15:26 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9963 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/attachments_controller.rb

index 4ef929896d12e80b1410f6fdd2d99a6492831596..edae9b0cc25b12601808fdf1eda9c655d773e15b 100644 (file)
@@ -52,19 +52,22 @@ class AttachmentsController < ApplicationController
       @attachment.increment_download
     end
 
-    # images are sent inline
-    send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
-                                    :type => detect_content_type(@attachment),
-                                    :disposition => (@attachment.image? ? 'inline' : 'attachment')
-
+    if stale?(:etag => @attachment.digest)
+      # images are sent inline
+      send_file @attachment.diskfile, :filename => filename_for_content_disposition(@attachment.filename),
+                                      :type => detect_content_type(@attachment),
+                                      :disposition => (@attachment.image? ? 'inline' : 'attachment')
+    end
   end
 
   def thumbnail
     if @attachment.thumbnailable? && Setting.thumbnails_enabled? && thumbnail = @attachment.thumbnail
-      send_file thumbnail,
-        :filename => filename_for_content_disposition(@attachment.filename),
-        :type => detect_content_type(@attachment),
-        :disposition => 'inline'
+      if stale?(:etag => thumbnail)
+        send_file thumbnail,
+          :filename => filename_for_content_disposition(@attachment.filename),
+          :type => detect_content_type(@attachment),
+          :disposition => 'inline'
+      end
     else
       # No thumbnail for the attachment or thumbnail could not be created
       render :nothing => true, :status => 404