From c54b69fc2f7e7187d84dc5d5a99acb1fe01073b0 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 30 Jun 2024 14:23:38 +0100 Subject: [PATCH] refactor(async): small cleanups (#1061) Signed-off-by: Rudi Grinberg --- cohttp-async/src/server.ml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cohttp-async/src/server.ml b/cohttp-async/src/server.ml index a23db905d..24a07a828 100644 --- a/cohttp-async/src/server.ml +++ b/cohttp-async/src/server.ml @@ -48,6 +48,8 @@ let collect_errors writer ~f = choice (try_with ~name:"Cohttp_async.Server.collect_errors" f) Fn.id; ] +let reader_info = Info.of_string "Cohttp_async.Server.Expert: Create reader" + let handle_client handle_request sock rd wr = collect_errors wr ~f:(fun () -> let rd = Input_channel.create rd in @@ -61,10 +63,8 @@ let handle_client handle_request sock rd wr = handle_request ~body:req_body sock req >>= function | `Expert (res, handler) -> Io.Response.write_header res wr >>= fun () -> - Input_channel.to_reader - (Info.of_string "Cohttp_async.Server.Expert: Create reader") - rd - >>= fun reader -> handler reader wr + Input_channel.to_reader reader_info rd >>= fun reader -> + handler reader wr | `Response (res, res_body) -> (* There are scenarios if a client leaves before consuming the full response, we might have a reference to an async Pipe that doesn't get drained. @@ -103,7 +103,7 @@ let handle_client handle_request sock rd wr = else Deferred.unit) in loop rd wr sock handle_request) - >>| fun res -> Result.ok_exn res + >>| Result.ok_exn let respond ?(flush = true) ?(headers = Http.Header.init ()) ?(body = `Empty) status : response Deferred.t =