avsm/ocaml-cohttp — pull request #8 by djs55 (2012-10-18 15:25:51+00:00)
Title: Fix reading of POSTs with non-empty bodies

The server creates an Lwt_stream of (request * body option) where
the body is also an Lwt_stream. In order to avoid reading request
number 2 and body number 1 in parallel, the (request * body option)
stream creation function waits until the body stream has terminated.
Unfortunately the body stream never terminates because its values
are never read by the client because the (request * body option)
stream constructor has blocked.

Fix by associating the stream with a read mutex. We unlock the
read mutex after reading the HTTP header *unless* there is a body.
In the body case we drop the read mutex when the body stream has
terminated. In all cases the (request * body option) stream
constructor returns and allows the client to process the request,
and request the body (if there is one).