send_file now takes :last_modified option

fixes #131
This commit is contained in:
Konstantin Haase 2010-12-15 17:24:21 +01:00
parent d75f12cb43
commit 1e55be7285
2 changed files with 8 additions and 1 deletions

View File

@ -164,7 +164,7 @@ module Sinatra
# Use the contents of the file at +path+ as the response body.
def send_file(path, opts={})
stat = File.stat(path)
last_modified stat.mtime
last_modified(opts[:last_modified] || stat.mtime)
if opts[:type] or not response['Content-Type']
content_type opts[:type] || File.extname(path), :default => 'application/octet-stream'

View File

@ -419,6 +419,13 @@ class HelpersTest < Test::Unit::TestCase
assert_equal File.mtime(@file).httpdate, response['Last-Modified']
end
it 'allows passing in a differen Last-Modified response header with :last_modified' do
time = Time.now
send_file_app :last_modified => time
get '/file.txt'
assert_equal time.httpdate, response['Last-Modified']
end
it "returns a 404 when not found" do
mock_app {
get '/' do