Skip to content

Commit

Permalink
Adjust content negotiation for binaries (#998)
Browse files Browse the repository at this point in the history
Resolves #997
  • Loading branch information
acoburn authored Aug 3, 2020
1 parent e6057f3 commit f5028dc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/http/src/main/java/org/trellisldp/http/impl/HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,15 @@ public static RDFSyntax getSyntax(final IOService ioService, final List<MediaTyp
if (acceptableTypes.isEmpty()) {
return mimeType != null ? null : TURTLE;
}
final MediaType mt = mimeType != null ? MediaType.valueOf(mimeType) : null;
for (final MediaType type : acceptableTypes) {
if (type.isCompatible(mt)) {
return null;
if (mimeType != null) {
final MediaType mt = MediaType.valueOf(mimeType);
for (final MediaType type : acceptableTypes) {
if (type.isCompatible(mt)) {
return null;
}
}
}
for (final MediaType type : acceptableTypes) {
final RDFSyntax syntax = ioService.supportedReadSyntaxes().stream()
.filter(s -> MediaType.valueOf(s.mediaType()).isCompatible(type))
.findFirst().orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ void testGetSyntaxEmpty() {
assertEquals(TURTLE, HttpUtils.getSyntax(ioService, emptyList(), null), "Turtle not default syntax!");
}

@Test
void testGetBinarySynax() {
assertNull(HttpUtils.getSyntax(ioService, asList(MediaType.TEXT_HTML_TYPE, MediaType.WILDCARD_TYPE),
"image/png"), "Incorrect binary syntax");
}

@Test
void testGetSyntaxFallback() {
final List<MediaType> types = asList(APPLICATION_JSON_TYPE, TEXT_XML_TYPE,
Expand Down

0 comments on commit f5028dc

Please sign in to comment.