From ac66cf1289a18504668baffeb1808540103ddc7a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 2 Jun 2006 00:51:56 +0000 Subject: Add :status option to send_data and send_file. Defaults to '200 OK'. Closes #5243. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4400 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/streaming.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/streaming.rb b/actionpack/lib/action_controller/streaming.rb index c265c86045..618888d096 100644 --- a/actionpack/lib/action_controller/streaming.rb +++ b/actionpack/lib/action_controller/streaming.rb @@ -28,6 +28,7 @@ module ActionController #:nodoc: # or to read the entire file before sending (false). Defaults to true. # * :buffer_size - specifies size (in bytes) of the buffer used to stream the file. # Defaults to 4096. + # * :status - specifies the status code to send with the response. Defaults to '200 OK'. # # The default Content-Type and Content-Disposition headers are # set to download arbitrary binary files in as many browsers as @@ -37,9 +38,12 @@ module ActionController #:nodoc: # Simple download: # send_file '/path/to.zip' # - # Show a JPEG in browser: + # Show a JPEG in the browser: # send_file '/path/to.jpeg', :type => 'image/jpeg', :disposition => 'inline' # + # Show a 404 page in the browser: + # send_file '/path/to/404.html, :type => 'text/html; charset=utf-8', :status => 404 + # # Read about the other Content-* HTTP headers if you'd like to # provide the user with more information (such as Content-Description). # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11 @@ -61,7 +65,7 @@ module ActionController #:nodoc: @performed_render = false if options[:stream] - render :text => Proc.new { |response, output| + render :status => options[:status], :text => Proc.new { |response, output| logger.info "Streaming file #{path}" unless logger.nil? len = options[:buffer_size] || 4096 File.open(path, 'rb') do |file| @@ -81,7 +85,7 @@ module ActionController #:nodoc: } else logger.info "Sending file #{path}" unless logger.nil? - File.open(path, 'rb') { |file| render :text => file.read } + File.open(path, 'rb') { |file| render :status => options[:status], :text => file.read } end end @@ -93,6 +97,7 @@ module ActionController #:nodoc: # * :type - specifies an HTTP content type. # Defaults to 'application/octet-stream'. # * :disposition - specifies whether the file will be shown inline or downloaded. + # * :status - specifies the status code to send with the response. Defaults to '200 OK'. # Valid values are 'inline' and 'attachment' (default). # # Generic data download: @@ -109,7 +114,7 @@ module ActionController #:nodoc: logger.info "Sending data #{options[:filename]}" unless logger.nil? send_file_headers! options.merge(:length => data.size) @performed_render = false - render :text => data + render :status => options[:status], :text => data end private @@ -139,4 +144,4 @@ module ActionController #:nodoc: @headers['Cache-Control'] = 'private' if @headers['Cache-Control'] == 'no-cache' end end -end \ No newline at end of file +end -- cgit v1.2.3