]> git.openstreetmap.org Git - rails.git/blobdiff - config/initializers/streaming.rb
Moved strings to locales + Added 'Issues' button + Fixed typo in tests
[rails.git] / config / initializers / streaming.rb
index 0fc0929511628a768927581ca9ac6f0054f33596..0c27ba2e79e1f489cebbf2c4b9fbddc33b5b3328 100644 (file)
@@ -1,10 +1,12 @@
 # Hack ActionController::DataStreaming to allow streaming from a file handle
 module ActionController
   module DataStreaming
 # Hack ActionController::DataStreaming to allow streaming from a file handle
 module ActionController
   module DataStreaming
-    alias_method :old_send_file, :send_file
+    alias old_send_file send_file
 
     def send_file(file, options = {})
 
     def send_file(file, options = {})
-      if file.is_a? File or file.is_a? Tempfile
+      if file.is_a?(File) || file.is_a?(Tempfile)
+        headers["Content-Length"] ||= file.size.to_s
+
         options[:filename] ||= File.basename(file.path) unless options[:url_based_filename]
         send_file_headers! options
 
         options[:filename] ||= File.basename(file.path) unless options[:url_based_filename]
         send_file_headers! options
 
@@ -12,6 +14,8 @@ module ActionController
         self.content_type = options[:content_type] if options.key?(:content_type)
         self.response_body = file
       else
         self.content_type = options[:content_type] if options.key?(:content_type)
         self.response_body = file
       else
+        headers["Content-Length"] ||= File.size(file).to_s
+
         old_send_file(file, options)
       end
     end
         old_send_file(file, options)
       end
     end