Client: temporary hack

reaggregate http chunks for streamed RPC... :(
This commit is contained in:
Grégoire Henry 2018-04-17 10:35:01 +02:00
parent ec25690166
commit aeaf2a240c

View File

@ -319,28 +319,23 @@ module Make (Encoding : Resto.ENCODING) = struct
on_close () ;
Lwt.return (`Ok None)
| Some chunk ->
let buffer = Buffer.create 2048 in
let output = Service.output_encoding service in
log.log ~media output
`OK (lazy (Lwt.return chunk)) >>= fun () ->
match media.destruct output chunk with
| Error msg ->
Lwt.return (`Unexpected_content ((chunk, media), msg))
| Ok body ->
on_chunk body ;
let rec loop () =
Lwt_stream.get stream >>= function
let rec loop = function
| None -> on_close () ; Lwt.return_unit
| Some chunk ->
Buffer.add_string buffer chunk ;
let data = Buffer.contents buffer in
log.log ~media output
`OK (lazy (Lwt.return chunk)) >>= fun () ->
match media.destruct output chunk with
| Ok body -> on_chunk body ; loop ()
match media.destruct output data with
| Ok body ->
Buffer.reset buffer ;
on_chunk body ;
Lwt_stream.get stream >>= loop
| Error _msg ->
(* TODO log error. *)
ignore (Lwt_stream.junk_while (fun _ -> true) stream
: unit Lwt.t) ;
on_close () ; Lwt.return_unit in
ignore (loop () : unit Lwt.t) ;
Lwt_stream.get stream >>= loop in
ignore (loop (Some chunk) : unit Lwt.t) ;
Lwt.return (`Ok (Some (fun () ->
ignore (Lwt_stream.junk_while (fun _ -> true) stream
: unit Lwt.t) ;