aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/metal/streaming.rb
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-02-23 15:37:17 -0800
committerCarlhuda <carlhuda@engineyard.com>2010-02-23 15:37:17 -0800
commit3345af61fb128d0a70793b235e3cb878781d6f40 (patch)
tree13f658ed836dc7d8c15eb9486cef39f340496722 /actionpack/lib/action_controller/metal/streaming.rb
parentee541049fdbe5eeebcca2f3b83144a5d803345a9 (diff)
downloadrails-3345af61fb128d0a70793b235e3cb878781d6f40.tar.gz
rails-3345af61fb128d0a70793b235e3cb878781d6f40.tar.bz2
rails-3345af61fb128d0a70793b235e3cb878781d6f40.zip
Fix streaming by having it create a File object, which can be handled by Rack servers as appropriate
Diffstat (limited to 'actionpack/lib/action_controller/metal/streaming.rb')
-rw-r--r--actionpack/lib/action_controller/metal/streaming.rb20
1 files changed, 6 insertions, 14 deletions
diff --git a/actionpack/lib/action_controller/metal/streaming.rb b/actionpack/lib/action_controller/metal/streaming.rb
index 8f03b8bb17..0d6fdafe0a 100644
--- a/actionpack/lib/action_controller/metal/streaming.rb
+++ b/actionpack/lib/action_controller/metal/streaming.rb
@@ -79,6 +79,8 @@ module ActionController #:nodoc:
# http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9
# for the Cache-Control header spec.
def send_file(path, options = {}) #:doc:
+ # self.response_body = File.open(path)
+
raise MissingFile, "Cannot read file #{path}" unless File.file?(path) and File.readable?(path)
options[:length] ||= File.size(path)
@@ -90,19 +92,9 @@ module ActionController #:nodoc:
if options[:x_sendfile]
head options[:status], X_SENDFILE_HEADER => path
else
- if options[:stream]
- # TODO : Make render :text => proc {} work with the new base
- render :status => options[:status], :text => Proc.new { |response, output|
- len = options[:buffer_size] || 4096
- File.open(path, 'rb') do |file|
- while buf = file.read(len)
- output.write(buf)
- end
- end
- }
- else
- File.open(path, 'rb') { |file| 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.open(path, "rb")
end
end
@@ -139,7 +131,7 @@ module ActionController #:nodoc:
# instead. See ActionController::Base#render for more information.
def send_data(data, options = {}) #:doc:
send_file_headers! options.merge(:length => data.bytesize)
- render :status => options[:status], :text => data
+ render options.slice(:status, :content_type).merge(:text => data)
end
private