tapir
tapir copied to clipboard
Add multipart body support for ZIO-HTTP integration
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 avoidClassCastExceptions 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.partTypesto figure out the part type (file vs text),asMultipartFormStreamfor parts metadata like field name and filename, - And I used
asMultipartMixedfor the actual file payload becauseasMultipartFormStreamgave me this content with line-breaks corrupted.
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.
Closing in favor of #3690