Allow to register a mime type with mime_type
This commit is contained in:
parent
31bf026087
commit
5da3460f90
|
@ -730,11 +730,12 @@ module Sinatra
|
|||
end
|
||||
end
|
||||
|
||||
# Look up a media type by file extension in Rack's mime registry.
|
||||
def mime_type(type)
|
||||
# Lookup or register a mime type in Rack's mime registry.
|
||||
def mime_type(type, value=nil)
|
||||
return type if type.nil? || type.to_s.include?('/')
|
||||
type = ".#{type}" unless type.to_s[0] == ?.
|
||||
Rack::Mime.mime_type(type, nil)
|
||||
return Rack::Mime.mime_type(type, nil) unless value
|
||||
Rack::Mime::MIME_TYPES[type] = value
|
||||
end
|
||||
|
||||
# Define a before filter. Filters are run before all requests
|
||||
|
|
|
@ -230,6 +230,19 @@ class HelpersTest < Test::Unit::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
test 'Base.mime_type registers mime type' do
|
||||
mock_app {
|
||||
mime_type :foo, 'application/foo'
|
||||
|
||||
get '/' do
|
||||
"foo is #{mime_type(:foo)}"
|
||||
end
|
||||
}
|
||||
|
||||
get '/'
|
||||
assert_equal 'foo is application/foo', body
|
||||
end
|
||||
|
||||
describe 'content_type' do
|
||||
it 'sets the Content-Type header' do
|
||||
mock_app {
|
||||
|
|
Loading…
Reference in New Issue