]> git.openstreetmap.org Git - rails.git/blobdiff - config/initializers/streaming.rb
Merge remote-tracking branch 'openstreetmap/pull/1312'
[rails.git] / config / initializers / streaming.rb
index 116ca51ddda71d7e514b28d625512ee5149bd9f3..0c27ba2e79e1f489cebbf2c4b9fbddc33b5b3328 100644 (file)
@@ -1,29 +1,21 @@
-# Hack ActionController::Streaming to allow streaming from a file handle
+# Hack ActionController::DataStreaming to allow streaming from a file handle
 module ActionController
-  module Streaming
-    alias_method :old_send_file, :send_file
+  module DataStreaming
+    alias old_send_file send_file
 
     def send_file(file, options = {})
-      if file.is_a? File or file.is_a? Tempfile
-        options[:length] ||= file.stat.size
+      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
 
-        @performed_render = false
-
-        if options[:stream]
-          render :status => options[:status], :text => Proc.new { |response, output|
-            logger.info "Streaming file #{file.path}" unless logger.nil?
-            len = options[:buffer_size] || 4096
-            while buf = file.read(len)
-              output.write(buf)
-            end
-          }
-        else
-          logger.info "Sending file #{file.path}" unless logger.nil?
-          render :status => options[:status], :text => file.read
-        end
+        self.status = options[:status] || 200
+        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