diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-06-02 00:51:56 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-06-02 00:51:56 +0000 |
commit | ac66cf1289a18504668baffeb1808540103ddc7a (patch) | |
tree | 404a296d35ce4981ab047c0b3ae12a94bff2df95 /actionpack/lib/action_controller | |
parent | 9e7e89a5611d7c798018c318b612a5ba046d8947 (diff) | |
download | rails-ac66cf1289a18504668baffeb1808540103ddc7a.tar.gz rails-ac66cf1289a18504668baffeb1808540103ddc7a.tar.bz2 rails-ac66cf1289a18504668baffeb1808540103ddc7a.zip |
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
Diffstat (limited to 'actionpack/lib/action_controller')
-rw-r--r-- | actionpack/lib/action_controller/streaming.rb | 15 |
1 files changed, 10 insertions, 5 deletions
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. # * <tt>:buffer_size</tt> - specifies size (in bytes) of the buffer used to stream the file. # Defaults to 4096. + # * <tt>:status</tt> - 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: # * <tt>:type</tt> - specifies an HTTP content type. # Defaults to 'application/octet-stream'. # * <tt>:disposition</tt> - specifies whether the file will be shown inline or downloaded. + # * <tt>:status</tt> - 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 |