Respond with 406 if we can't return requested formats
This commit is contained in:
parent
212eb6d9d3
commit
65b1e6b988
|
@ -24,12 +24,14 @@ class Travis::Api::App
|
|||
def respond(resource, options)
|
||||
resource = apply_service_responder(resource, options)
|
||||
|
||||
acceptable_formats.find do |accept|
|
||||
response = acceptable_formats.find do |accept|
|
||||
responders(resource, options).find do |const|
|
||||
responder = const.new(self, resource, options.dup.merge(accept: accept))
|
||||
responder.apply if responder.apply?
|
||||
end
|
||||
end
|
||||
|
||||
response || (resource ? error(406) : error(404))
|
||||
end
|
||||
|
||||
def apply_service_responder(resource, options)
|
||||
|
|
|
@ -24,4 +24,9 @@ describe 'App' do
|
|||
response = get '/foo', {}, 'HTTP_ACCEPT' => 'image/jpeg, application/json'
|
||||
response.content_type.should =~ /^application\/json/
|
||||
end
|
||||
|
||||
it 'responds with 406 if server can\'t use any mime type' do
|
||||
response = get '/foo/hash', {}, 'HTTP_ACCEPT' => 'text/plain, image/jpeg'
|
||||
response.status.should == 406
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user