Skip to content

Commit

Permalink
Fixed how mimeparse receives the list of acceptable formats. Thanks t…
Browse files Browse the repository at this point in the history
…o bartels & acdha for the report & for looking into possible solutions.
  • Loading branch information
toastdriven committed Nov 9, 2010
1 parent 59755dc commit 2e391e6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tastypie/utils/mime.py
Expand Up @@ -25,7 +25,12 @@ def determine_format(request, serializer, default_format='application/json'):

# Try to fallback on the Accepts header.
if request.META.get('HTTP_ACCEPT', '*/*') != '*/*':
best_format = mimeparse.best_match(serializer.supported_formats, request.META['HTTP_ACCEPT'])
formats = serializer.supported_formats or []
# Reverse the list, because mimeparse is weird like that. See also
# https://github.com/toastdriven/django-tastypie/issues#issue/12 for
# more information.
formats.reverse()
best_format = mimeparse.best_match(formats, request.META['HTTP_ACCEPT'])

if best_format:
return best_format
Expand Down
3 changes: 3 additions & 0 deletions tests/core/tests/utils.py
Expand Up @@ -60,3 +60,6 @@ def test_determine_format(self):

request.META = {'HTTP_ACCEPT': 'application/json; charset=UTF-8'}
self.assertEqual(determine_format(request, serializer), 'application/json')

request.META = {'HTTP_ACCEPT': 'text/javascript,application/json'}
self.assertEqual(determine_format(request, serializer), 'application/json')

0 comments on commit 2e391e6

Please sign in to comment.