Skip to content

Commit

Permalink
updates from PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Walter Knize <nknize@apache.org>
  • Loading branch information
nknize committed Apr 27, 2022
1 parent 813e2b9 commit fc8cb12
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit fc8cb12

Please sign in to comment.