Skip to content

Commit

Permalink
Fixes #379
Browse files Browse the repository at this point in the history
  • Loading branch information
iceboy233 committed Oct 29, 2017
1 parent fd9e5e6 commit 018da18
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion vj4/handler/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,14 @@ async def binary(self, data, content_type='application/octet-stream', file_name=

@property
def prefer_json(self):
for d in accept.parse(self.request.headers.get('Accept')):
accept_header = self.request.headers.get('Accept')
try:
parse_result = accept.parse(accept_header)
except (ValueError, IndexError):
# the accept library throws bogus exceptions
_logger.warning('Unparsable accept header: %s', accept_header)
return False
for d in parse_result:
if d.media_type == 'application/json':
return True
elif d.media_type == 'text/html' or d.all_types:
Expand Down

0 comments on commit 018da18

Please sign in to comment.