diff --git a/async/cohttp_async_io.ml b/async/cohttp_async_io.ml index 6490545d6c..ee2fae9855 100644 --- a/async/cohttp_async_io.ml +++ b/async/cohttp_async_io.ml @@ -49,14 +49,19 @@ let read_line = |`Eof -> eprintf "<<>| function - | `Ok len' -> String.sub buf 0 len' + | `Ok len' -> + if len' = len then buf else String.sub buf 0 len' | `Eof -> "" let read_exactly ic len = - let buf = String.create len in + let buf, len = create_buf len in Reader.really_read ic ~pos:0 ~len buf >>| function |`Ok -> Some buf