1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

add :status option to send_file. fixes #429.

This commit is contained in:
Konstantin Haase 2012-01-02 16:32:21 +01:00
parent 5eb65ef9b0
commit df195cdd22
4 changed files with 12 additions and 1 deletions

View file

@ -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 file

@ -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 file

@ -229,7 +229,7 @@ module Sinatra
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 file

@ -729,6 +729,12 @@ class HelpersTest < Test::Unit::TestCase
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') }