From abc930b547920c002376edf11d26a9bc1d8d81a0 Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Sat, 9 Nov 2024 23:03:47 +0530 Subject: [PATCH] Update unsafeParseCustomMediaType to set binary for unrecognized MIME types --- zio-http/shared/src/main/scala/zio/http/MediaType.scala | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/zio-http/shared/src/main/scala/zio/http/MediaType.scala b/zio-http/shared/src/main/scala/zio/http/MediaType.scala index 5e28ffd9f..b98c22322 100644 --- a/zio-http/shared/src/main/scala/zio/http/MediaType.scala +++ b/zio-http/shared/src/main/scala/zio/http/MediaType.scala @@ -65,10 +65,7 @@ object MediaType extends MediaTypes { if (contentTypeParts.length == 2) { val subtypeParts = contentTypeParts(1).split(';') // Default binary to true for unknown types unless they belong to text families - val isBinary = customMediaType != "*/*" && - !customMediaType.startsWith("text/") && - !customMediaType.startsWith("application/json") && - !customMediaType.startsWith("application/xml") + val isBinary = customMediaType != "*/*" && customMediaType != "text/*" && !customMediaType.startsWith("text/") if (subtypeParts.length >= 1) { Some( MediaType( @@ -86,10 +83,12 @@ object MediaType extends MediaTypes { val contentTypeParts = customMediaType.split('/') if (contentTypeParts.length == 2) { val subtypeParts = contentTypeParts(1).split(';') + val isBinary = customMediaType != "*/*" && customMediaType != "text/*" && !customMediaType.startsWith("text/") if (subtypeParts.length >= 1) { MediaType( mainType = contentTypeParts.head, subType = subtypeParts.head, + binary = isBinary, parameters = if (subtypeParts.length >= 2) parseOptionalParameters(subtypeParts.tail) else Map.empty, ) } else throw new IllegalArgumentException(s"Invalid media type $customMediaType")