Fix :provides crashes with no Accept header [#139]
An exception was raised on every request that did not have an Accept header due to the Accept parsing code calling split on nil. The Sinatra::Request#accept method now returns an empty collection if the HTTP Accept header is not present.
This commit is contained in:
parent
7a2ef0a6a1
commit
a1d9001a7a
|
@ -12,7 +12,7 @@ module Sinatra
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept
|
def accept
|
||||||
@env['HTTP_ACCEPT'].split(',').map { |a| a.strip }
|
@env['HTTP_ACCEPT'].to_s.split(',').map { |a| a.strip }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Override Rack 0.9.x's #params implementation (see #72 in lighthouse)
|
# Override Rack 0.9.x's #params implementation (see #72 in lighthouse)
|
||||||
|
|
|
@ -484,4 +484,18 @@ describe "Routing" do
|
||||||
assert_equal type, response.headers['Content-Type']
|
assert_equal type, response.headers['Content-Type']
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'degrades gracefully when optional accept header is not provided' do
|
||||||
|
mock_app {
|
||||||
|
get '/', :provides => :xml do
|
||||||
|
request.env['HTTP_ACCEPT']
|
||||||
|
end
|
||||||
|
get '/' do
|
||||||
|
'default'
|
||||||
|
end
|
||||||
|
}
|
||||||
|
get '/'
|
||||||
|
assert ok?
|
||||||
|
assert_equal 'default', body
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue