Skip to content

Commit

Permalink
Update unsafeParseCustomMediaType to set binary for unrecognized MIM…
Browse files Browse the repository at this point in the history
…E types
  • Loading branch information
varshith257 committed Nov 9, 2024
1 parent db4d439 commit c857464
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions zio-http/shared/src/main/scala/zio/http/MediaType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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")
Expand Down

0 comments on commit c857464

Please sign in to comment.