From fc8cb12d605ac981ff551cf3bb8cc65c19fb09fe Mon Sep 17 00:00:00 2001 From: Nicholas Walter Knize Date: Wed, 27 Apr 2022 11:17:34 -0500 Subject: [PATCH] updates from PR feedback Signed-off-by: Nicholas Walter Knize --- .../org/opensearch/common/xcontent/MediaTypeParser.java | 6 +++--- .../java/org/opensearch/common/xcontent/XContentType.java | 3 ++- .../java/org/opensearch/rest/action/cat/RestTable.java | 4 ++-- .../org/opensearch/common/xcontent/XContentTypeTests.java | 8 ++++---- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaTypeParser.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaTypeParser.java index 05dbc73097a2c..ffe90b0458020 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaTypeParser.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/MediaTypeParser.java @@ -83,9 +83,9 @@ public T fromFormat(String format) { */ public ParsedMediaType parseMediaType(String headerValue) { if (headerValue != null) { - String[] split = headerValue.toLowerCase(Locale.ROOT).split(";"); + String[] split = headerValue.split(";"); - String[] typeSubtype = split[0].trim().toLowerCase(Locale.ROOT).split("/"); + String[] typeSubtype = split[0].trim().split("/"); if (typeSubtype.length == 2) { String type = typeSubtype[0]; String subtype = typeSubtype[1]; @@ -98,7 +98,7 @@ public ParsedMediaType parseMediaType(String headerValue) { if (keyValueParam.length != 2 || hasSpaces(keyValueParam[0]) || hasSpaces(keyValueParam[1])) { return null; } - parameters.put(keyValueParam[0].toLowerCase(Locale.ROOT), keyValueParam[1].toLowerCase(Locale.ROOT)); + parameters.put(keyValueParam[0], keyValueParam[1]); } return new ParsedMediaType(xContentType, parameters); } diff --git a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java index fa66973535590..a4777b932529b 100644 --- a/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java +++ b/libs/x-content/src/main/java/org/opensearch/common/xcontent/XContentType.java @@ -37,6 +37,7 @@ import org.opensearch.common.xcontent.smile.SmileXContent; import org.opensearch.common.xcontent.yaml.YamlXContent; +import java.util.Locale; import java.util.Map; /** @@ -155,7 +156,7 @@ public static XContentType fromFormat(String mediaType) { * This method will return {@code null} if no match is found */ public static XContentType fromMediaType(String mediaTypeHeaderValue) { - mediaTypeHeaderValue = removeVersionInMediaType(mediaTypeHeaderValue); + mediaTypeHeaderValue = removeVersionInMediaType(mediaTypeHeaderValue.toLowerCase(Locale.ROOT)); return MEDIA_TYPE_PARSER.fromMediaType(mediaTypeHeaderValue); } diff --git a/server/src/main/java/org/opensearch/rest/action/cat/RestTable.java b/server/src/main/java/org/opensearch/rest/action/cat/RestTable.java index 310bdd73f463a..542c428901475 100644 --- a/server/src/main/java/org/opensearch/rest/action/cat/RestTable.java +++ b/server/src/main/java/org/opensearch/rest/action/cat/RestTable.java @@ -64,14 +64,14 @@ public class RestTable { public static RestResponse buildResponse(Table table, RestChannel channel) throws Exception { RestRequest request = channel.request(); - XContentType xContentType = getxContentType(request); + XContentType xContentType = getXContentType(request); if (xContentType != null) { return buildXContentBuilder(table, channel); } return buildTextPlainResponse(table, channel); } - private static XContentType getxContentType(RestRequest request) { + private static XContentType getXContentType(RestRequest request) { if (request.hasParam("format")) { return XContentType.fromFormat(request.param("format")); } diff --git a/server/src/test/java/org/opensearch/common/xcontent/XContentTypeTests.java b/server/src/test/java/org/opensearch/common/xcontent/XContentTypeTests.java index 2804987fe5909..978db14225f00 100644 --- a/server/src/test/java/org/opensearch/common/xcontent/XContentTypeTests.java +++ b/server/src/test/java/org/opensearch/common/xcontent/XContentTypeTests.java @@ -114,9 +114,9 @@ public void testVersionedMediaType() throws Exception { assertThat(XContentType.fromMediaType("application/vnd.opensearch+smile;compatible-with=7"), equalTo(XContentType.SMILE)); assertThat(XContentType.fromMediaType("application/vnd.opensearch+json ;compatible-with=7"), equalTo(XContentType.JSON)); - assertThat( - XContentType.fromMediaType("application/vnd.opensearch+json ;compatible-with=7;charset=utf-8"), - equalTo(XContentType.JSON) - ); + + String mthv = "application/vnd.opensearch+json ;compatible-with=7;charset=utf-8"; + assertThat(XContentType.fromMediaType(mthv), equalTo(XContentType.JSON)); + assertThat(XContentType.fromMediaType(mthv.toUpperCase(Locale.ROOT)), equalTo(XContentType.JSON)); } }