tapir icon indicating copy to clipboard operation
tapir copied to clipboard

Add multipart body support for ZIO-HTTP integration

Open asavelyev01 opened this issue 1 year ago • 1 comments

This is an attempt to support the multipart request body. I tested it to work in our corporate setup, with a derived multipart codec for a case class which included a file part.

Here is a list of excuses for how clumsy this code looks:

  • I had to tread really carefully to provide the object of the correct class to resulting Part[_] to avoid ClassCastExceptions down the stream,
  • There wasn't one good way I could come up with to collect the needed information about each of the body parts. In particular, I used MultipartBody.partTypes to figure out the part type (file vs text), asMultipartFormStream for parts metadata like field name and filename,
  • And I used asMultipartMixed for the actual file payload because asMultipartFormStream gave me this content with line-breaks corrupted.

asavelyev01 avatar Aug 07 '24 12:08 asavelyev01

Thanks! There's also another PR which attempts to fix this: https://github.com/softwaremill/tapir/pull/3690, but is currently blocked by a bug in zio-http (waiting its release).

One thing that might be useful in development is enabling the multipart tests in in ZioHttpServerTest.

adamw avatar Aug 07 '24 14:08 adamw

Closing in favor of #3690

adamw avatar Sep 17 '24 09:09 adamw