mirage/ocaml-cohttp — pull request #193 by djs55 (2014-11-04 11:29:08+00:00)
Title: eta-contract Response.read_body_chunk as we already have for Request.rea...

...d_body_chunk

This allows a streaming download loop like the following:

let reader = Response.read_body_chunk response in
(* the remaining length reference cell is now captured in 'reader' *)
let rec loop () =
reader ic
>>= function
| Cohttp.Transfer.Chunk x ->
Buffer.add_string body x;
loop ()
| Cohttp.Transfer.Final_chunk x ->
Buffer.add_string body x;
return (Buffer.contents body)
| Cohttp.Transfer.Done ->
return (Buffer.contents body) in
loop () >>= fun body ->

Without this, every call to reader ic generates a fresh reference cell and the
download never completes.

This mirrors the API in #154

Signed-off-by: David Scott