Skip to content

Commit

Permalink
refactor(async): small cleanups (#1061)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Jun 30, 2024
1 parent f66a84d commit c54b69f
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cohttp-async/src/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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 =
Expand Down

0 comments on commit c54b69f

Please sign in to comment.