Handling multiple file-uploads/multipart form data in Cohttp server?

server
multipart
cohttp

#1

What’s the best way to pull out multi-part form data from a Cohttp request, keeping headers for each content block? Are there any helpers implemented right now, or is it up to the user to split the body apart and reconstruct a higher-level type?


#2

As far as I know (but I did not follow the development of Cohttp for a long time), Cohttp does not implement the multipart. I sure than Ocsigen implements this feature. However, the multipart is not easy as I tried with Mr. MIME (which one implement the multipart but for e-mail) and it’s like a big recursive headache.

I don’t know the plan about Cohttp and, if httpaf will implement this feature too.


#3

There is a separate multipart-form-library that needs to be integrated into Cohttp - see https://github.com/mirage/ocaml-cohttp/issues/181 for the issue.


#4

Ah, that’s great. Would love to see it integrated.

Having used it though, running into an issue with \r\n being mangled in-between the multipart boundaries: https://github.com/cryptosense/multipart-form-data/issues/17

Right now, the individual body pieces are split on \r\n, and each “line” is turned into a stream. I need to interpose streams of \r\n before concatenating them. Is there an obvious way to do it? Lwt_stream.concat doesn’t take the same argument as String.concat for an in-between-elements separator.