Skip to content

Commit

Permalink
test-response-before-read: read body in a loop
Browse files Browse the repository at this point in the history
`schedule_read` only handles the first chunk, we need to re-schedule for
each successive chunk.
  • Loading branch information
dpatti committed Apr 3, 2021
1 parent 6481d40 commit 52eb318
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib_test/test_server_connection.ml
Original file line number Diff line number Diff line change
Expand Up @@ -858,11 +858,15 @@ let test_response_finished_before_body_read () =
let response = Response.create `OK ~headers:(Headers.encoding_fixed 4) in
let rev_body_chunks = ref [] in
let request_handler reqd =
Body.schedule_read
(Reqd.request_body reqd)
~on_read:(fun buf ~off ~len ->
rev_body_chunks := Bigstringaf.substring buf ~off ~len :: !rev_body_chunks)
~on_eof:ignore;
let rec read_body () =
Body.schedule_read
(Reqd.request_body reqd)
~on_read:(fun buf ~off ~len ->
rev_body_chunks := Bigstringaf.substring buf ~off ~len :: !rev_body_chunks;
read_body ())
~on_eof:ignore;
in
read_body ();
Reqd.respond_with_string reqd response "done"
in
let t = create request_handler in
Expand Down

0 comments on commit 52eb318

Please sign in to comment.