Skip to content

Commit

Permalink
skip over any content type marked as binary
Browse files Browse the repository at this point in the history
  • Loading branch information
ryber committed Jun 19, 2023
1 parent 816a3c4 commit f596e69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion unirest/src/main/java/kong/unirest/core/ContentType.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class ContentType {
public static final ContentType APPLICATION_JSON = create("application/json", StandardCharsets.UTF_8);
public static final ContentType APPLICATION_JSON_PATCH = create("application/json-patch+json");
public static final ContentType APPLICATION_OCTET_STREAM = create("application/octet-stream", true);
public static final ContentType BINARY_OCTET_STREAM = create("binary/octet-stream", true);
public static final ContentType APPLICATION_SVG_XML = create("application/svg+xml", ISO_8859_1);
public static final ContentType APPLICATION_XHTML_XML = create("application/xhtml+xml", ISO_8859_1);
public static final ContentType APPLICATION_XML = create("application/xml", ISO_8859_1);
Expand Down Expand Up @@ -86,7 +87,8 @@ public static boolean isBinary(String mimeType) {
if(mimeType == null){
return false;
}
return BINARY_TYPES.contains(mimeType.toLowerCase());
String lc = mimeType.toLowerCase();
return lc.contains("binary") || BINARY_TYPES.contains(lc);
}

@Override
Expand Down
7 changes: 7 additions & 0 deletions unirest/src/test/java/kong/unirest/core/ContentTypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class ContentTypeTest {
@Test
void checkForBinaryTypes() {
assertTrue(ContentType.BINARY_OCTET_STREAM.isBinary());
assertTrue(ContentType.APPLICATION_OCTET_STREAM.isBinary());
assertFalse(ContentType.APPLICATION_JSON.isBinary());
}
Expand All @@ -44,4 +45,10 @@ void checkForBinaryTypesByString() {
assertFalse(ContentType.isBinary(ContentType.APPLICATION_JSON.getMimeType()));
assertFalse(ContentType.isBinary(null));
}

@Test
void anyOldBinary() {
assertTrue(ContentType.isBinary("binary/thing"));
assertFalse(ContentType.isBinary("application/thing"));
}
}

0 comments on commit f596e69

Please sign in to comment.