Browse files

Add slightly more capable accept header handling

  • Loading branch information...
1 parent 1bbecb0 commit 674b8dbf8c2d7dad1d20403904454330210119c2 @knuton committed Oct 6, 2011
Showing with 7 additions and 2 deletions.
  1. +6 −1 lib/second_mate/request.rb
  2. +1 −1 test/test_naive_finder.rb
View
7 lib/second_mate/request.rb
@@ -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
View
2 test/test_naive_finder.rb
@@ -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']

0 comments on commit 674b8db

Please sign in to comment.