diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index ea154fb4..5a4f3d88 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -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' diff --git a/test/helpers_test.rb b/test/helpers_test.rb index f6696385..1bb78200 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -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