Skip to content

Commit 0c743b8

Browse files
committed
update quality sort
1 parent d9cd57a commit 0c743b8

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/GraphQL.AspNetCore3/GraphQLHttpMiddleware.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,13 +697,15 @@ protected virtual MediaTypeHeaderValueMs SelectResponseContentType(HttpContext c
697697
} else if (acceptHeaders.Count > 0) {
698698
// enumerate through each content type and see if it matches a supported content type
699699
// give priority to specific types, then to types with wildcards
700-
foreach (var acceptHeader in acceptHeaders.OrderBy(x => x.MatchesAllTypes ? 4 : x.MatchesAllSubTypes ? 3 : x.MatchesAllSubTypesWithoutSuffix ? 2 : 1)) {
700+
var sortedAcceptHeaders = acceptHeaders
701+
.OrderByDescending(x => x.Quality ?? 1.0)
702+
.ThenBy(x => x.MatchesAllTypes ? 4 : x.MatchesAllSubTypes ? 3 : x.MatchesAllSubTypesWithoutSuffix ? 2 : 1);
703+
foreach (var acceptHeader in sortedAcceptHeaders) {
701704
var response = IsSupportedMediaType(acceptHeader);
702705
if (response != null)
703706
return response;
704707
}
705708
}
706-
707709
// return the default content type if no match is found, or if there is no 'Accept' header
708710
return _options.DefaultResponseContentType;
709711
}

0 commit comments

Comments
 (0)