From f596e69f4ecb7d21f118f2b6daa1a2e370429980 Mon Sep 17 00:00:00 2001 From: Ryan Bergman Date: Mon, 19 Jun 2023 08:02:59 -0500 Subject: [PATCH] skip over any content type marked as binary --- unirest/src/main/java/kong/unirest/core/ContentType.java | 4 +++- .../src/test/java/kong/unirest/core/ContentTypeTest.java | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/unirest/src/main/java/kong/unirest/core/ContentType.java b/unirest/src/main/java/kong/unirest/core/ContentType.java index c0d6e562..02a84daf 100644 --- a/unirest/src/main/java/kong/unirest/core/ContentType.java +++ b/unirest/src/main/java/kong/unirest/core/ContentType.java @@ -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); @@ -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 diff --git a/unirest/src/test/java/kong/unirest/core/ContentTypeTest.java b/unirest/src/test/java/kong/unirest/core/ContentTypeTest.java index 7583f8d5..a9933900 100644 --- a/unirest/src/test/java/kong/unirest/core/ContentTypeTest.java +++ b/unirest/src/test/java/kong/unirest/core/ContentTypeTest.java @@ -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()); } @@ -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")); + } } \ No newline at end of file