@@ -35,8 +35,8 @@ def qualify(x):
35
35
match = re .match (r'(^|;)q=(0(\.\d{,3})?|1(\.0{,3})?)(;|$)' ,
36
36
parts [1 ])
37
37
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
40
40
41
41
raw_content_types = request .META .get ('HTTP_ACCEPT' , '*/*' ).split (',' )
42
42
qualified_content_types = map (qualify , raw_content_types )
@@ -280,10 +280,13 @@ def can_display_graphiql(cls, request, data):
280
280
@classmethod
281
281
def request_wants_html (cls , request ):
282
282
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
285
288
286
- return html_index > json_index
289
+ return html_priority > json_priority
287
290
288
291
@staticmethod
289
292
def get_graphql_params (request , data ):
0 commit comments