Skip to content
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
25 changes: 15 additions & 10 deletions lwt-core/cohttp_lwt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,19 @@ module Make_server(IO:IO) = struct
responses are then sent over the wire *)
let req_stream = request_stream ic in
let res_stream = response_stream spec.callback io_id conn_id req_stream in
(* Clean up resources when the response stream terminates and call
* the user callback *)
Lwt_stream.on_terminate res_stream conn_closed;
(* Transmit the responses *)
res_stream |> Lwt_stream.iter_s (fun (res,body) ->
let flush = Response.flush res in
Response.write ~flush (fun writer ->
Body.write_body (Response.write_body writer) body
) res oc
)
Lwt.finalize
(fun () ->
(* Transmit the responses *)
res_stream |> Lwt_stream.iter_s (fun (res,body) ->
let flush = Response.flush res in
Response.write ~flush (fun writer ->
Body.write_body (Response.write_body writer) body
) res oc
)
)
(fun () ->
(* Clean up resources when the response stream terminates and call
* the user callback *)
conn_closed () |> Lwt.return
)
end