Skip to content

Commit

Permalink
Add slightly more capable accept header handling
Browse files Browse the repository at this point in the history
  • Loading branch information
knuton committed Oct 6, 2011
1 parent 1bbecb0 commit 674b8db
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/second_mate/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ def extension_by_path
end

def extension_by_header
Rack::Mime::MIME_TYPES.invert[@env['HTTP_ACCEPT']]
Rack::Mime::MIME_TYPES.invert[accept]
end

# TODO parse, sort
def accept
@env['HTTP_ACCEPT'].to_s.split(',').first
end

def relative_path
Expand Down
2 changes: 1 addition & 1 deletion test/test_naive_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_get_collection_as_json_explicitly
end

def test_get_collection_as_json_implicitly
response = @finder.call 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/collection', 'HTTP_ACCEPT' => 'application/json'
response = @finder.call 'REQUEST_METHOD' => 'GET', 'PATH_INFO' => '/collection', 'HTTP_ACCEPT' => 'application/json, text/html'
assert_equal 200, response.first
assert_equal ['GET collection.json'], response.last.body
assert_equal 'application/json', response[1]['Content-Type']
Expand Down

0 comments on commit 674b8db

Please sign in to comment.