From 0b032a0c3ecb8855e080a0e4d1d904a7271090a4 Mon Sep 17 00:00:00 2001 From: Konstantin Haase Date: Wed, 1 Sep 2010 11:47:10 +0200 Subject: [PATCH] Always respect :type parameter for send_file. Fixes GH #42 --- lib/sinatra/base.rb | 1 + test/helpers_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/sinatra/base.rb b/lib/sinatra/base.rb index 22a48a38..7172a174 100644 --- a/lib/sinatra/base.rb +++ b/lib/sinatra/base.rb @@ -158,6 +158,7 @@ module Sinatra last_modified stat.mtime content_type mime_type(opts[:type]) || + opts[:type] || mime_type(File.extname(path)) || response['Content-Type'] || 'application/octet-stream' diff --git a/test/helpers_test.rb b/test/helpers_test.rb index 1a096a71..647a1dce 100644 --- a/test/helpers_test.rb +++ b/test/helpers_test.rb @@ -345,6 +345,18 @@ class HelpersTest < Test::Unit::TestCase assert_equal 'text/plain', response['Content-Type'] end + it 'sets the Content-Type response header if type option is set to a file extesion' do + send_file_app :type => 'html' + get '/file.txt' + assert_equal 'text/html', response['Content-Type'] + end + + it 'sets the Content-Type response header if type option is set to a mime type' do + send_file_app :type => 'application/octet-stream' + get '/file.txt' + assert_equal 'application/octet-stream', response['Content-Type'] + end + it 'sets the Content-Length response header' do send_file_app get '/file.txt'