Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(async): small cleanups #1061

Merged
merged 1 commit into from
Jun 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading