Permalink
Browse files

add :status option to send_file. fixes #429.

  • Loading branch information...
1 parent 5eb65ef commit df195cdd22f9c8f4d1fbc6e82c23d396e3c2adb8 @rkh rkh committed Jan 2, 2012
Showing with 12 additions and 1 deletion.
  1. +2 −0 CHANGES
  2. +3 −0 README.rdoc
  3. +1 −1 lib/sinatra/base.rb
  4. +6 −0 test/helpers_test.rb
View
@@ -3,6 +3,8 @@
* No longer include Sinatra::Delegator in Object, instead extend the main
object only. (Konstantin Haase)
+ * Add :status option support to send_file. (Konstantin Haase)
+
* Exception#code is only used when :use_code is enabled and displays a warning.
Moreover, it will be ignored if the value is not between 400 and 599. You
should use Exception#http_status instead. (Konstantin Haase)
View
@@ -1070,6 +1070,9 @@ The options are:
[length]
Content-Length header, defaults to file size.
+[status]
+ Status code to be send. Useful when sending a static file as an error page.
+
If supported by the Rack handler, other means than streaming from the Ruby
process will be used. If you use this helper method, Sinatra will automatically
handle range requests.
View
@@ -229,7 +229,7 @@ def send_file(path, opts={})
file.path = path
result = file.serving env
result[1].each { |k,v| headers[k] ||= v }
- halt result[0], result[2]
+ halt opts[:status] || result[0], result[2]
rescue Errno::ENOENT
not_found
end
View
@@ -729,6 +729,12 @@ def send_file_app(opts={})
assert_equal 'attachment; filename="foo.txt"', response['Content-Disposition']
end
+ it 'allows setting a custom status code' do
+ send_file_app :status => 201
+ get '/file.txt'
+ assert_status 201
+ end
+
it "is able to send files with unkown mime type" do
@file = File.dirname(__FILE__) + '/file.foobar'
File.open(@file, 'wb') { |io| io.write('Hello World') }

0 comments on commit df195cd

Please sign in to comment.