Skip to content

Commit

Permalink
Optimize zio.http.codec.internal.EncoderDecoder.Single.decodeBody c…
Browse files Browse the repository at this point in the history
…ode (#3211)
  • Loading branch information
guizmaii authored Dec 2, 2024
1 parent 3d82a55 commit 547975e
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,18 +419,21 @@ private[codec] object EncoderDecoder {
private def decodeBody(config: CodecConfig, body: Body, inputs: Array[Any])(implicit
trace: Trace,
): Task[Unit] = {
val codecs = flattened.content
val isNonMultiPart = inputs.length < 2
if (isNonMultiPart) {
val codecs = flattened.content

if (inputs.length < 2) {
// non multi-part
codecs.headOption.map { codec =>
// noinspection SimplifyUnlessInspection
if (codecs.isEmpty) ZIO.unit
else {
val codec = codecs.head
codec
.decodeFromBody(body, config)
.mapBoth(
{ err => HttpCodecError.MalformedBody(err.getMessage(), Some(err)) },
{ err => HttpCodecError.MalformedBody(err.getMessage, Some(err)) },
result => inputs(0) = result,
)
}.getOrElse(ZIO.unit)
}
} else {
// multi-part
decodeForm(body.asMultipartFormStream, inputs, config) *> check(inputs)
Expand Down

0 comments on commit 547975e

Please sign in to comment.