]> git.openstreetmap.org Git - rails.git/blob - config/initializers/streaming.rb
Tooltips for map controls
[rails.git] / config / initializers / streaming.rb
1 # Hack ActionController::DataStreaming to allow streaming from a file handle
2 module ActionController
3   module DataStreaming
4     alias_method :old_send_file, :send_file
5
6     def send_file(file, options = {})
7       if file.is_a? File or file.is_a? Tempfile
8         headers["Content-Length"] ||= file.size.to_s
9
10         options[:filename] ||= File.basename(file.path) unless options[:url_based_filename]
11         send_file_headers! options
12
13         self.status = options[:status] || 200
14         self.content_type = options[:content_type] if options.key?(:content_type)
15         self.response_body = file
16       else
17         headers["Content-Length"] ||= File.size(file).to_s
18
19         old_send_file(file, options)
20       end
21     end
22   end
23 end