Skip to content

Commit

Permalink
pick #2597
Browse files Browse the repository at this point in the history
  • Loading branch information
weidongxu-microsoft committed Mar 4, 2024
1 parent d26e4f4 commit 141f257
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,17 @@ public static SupportedMimeType getResponseKnownMimeType(Collection<String> medi
// This is mostly for the error response which is in JSON, and is not included in this calculation.

for (String mediaType : mediaTypes) {
SupportedMimeType type = SUPPORTED_MIME_TYPES.get(mediaType);
if (type != null) {
return type;
// The declared mime type can be of the form "application/json; charset=utf-8" or "application/json"
// So, we have to check if the mediaType starts with the supported mime type
if (!mediaType.equals("application/json;q=0.9")) { // skip the error media type
SupportedMimeType type = SUPPORTED_MIME_TYPES.entrySet().stream()
.filter(supportedMimeType -> mediaType.startsWith(supportedMimeType.getKey()))
.map(Map.Entry::getValue)
.findAny()
.orElse(null);
if (type != null) {
return type;
}
}
}
return SupportedMimeType.BINARY; // BINARY if not recognized
Expand Down

0 comments on commit 141f257

Please sign in to comment.