@@ -35,8 +35,8 @@ def qualify(x):
3535 match = re .match (r'(^|;)q=(0(\.\d{,3})?|1(\.0{,3})?)(;|$)' ,
3636 parts [1 ])
3737 if match :
38- return parts [0 ], float (match .group (2 ))
39- return parts [0 ], 1
38+ return parts [0 ]. strip () , float (match .group (2 ))
39+ return parts [0 ]. strip () , 1
4040
4141 raw_content_types = request .META .get ('HTTP_ACCEPT' , '*/*' ).split (',' )
4242 qualified_content_types = map (qualify , raw_content_types )
@@ -280,10 +280,13 @@ def can_display_graphiql(cls, request, data):
280280 @classmethod
281281 def request_wants_html (cls , request ):
282282 accepted = get_accepted_content_types (request )
283- html_index = accepted .count ('text/html' )
284- json_index = accepted .count ('application/json' )
283+ accepted_length = len (accepted )
284+ # the list will be ordered in preferred first - so we have to make
285+ # sure the most preferred gets the highest number
286+ html_priority = accepted_length - accepted .index ('text/html' ) if 'text/html' in accepted else 0
287+ json_priority = accepted_length - accepted .index ('application/json' ) if 'application/json' in accepted else 0
285288
286- return html_index > json_index
289+ return html_priority > json_priority
287290
288291 @staticmethod
289292 def get_graphql_params (request , data ):
0 commit comments