diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index f0f95b6f..07956191 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -801,6 +801,7 @@ module type SERVER_SENT_GENERATOR = sig ?retry:string -> data:string -> unit -> unit + val close : unit -> unit end type server_sent_generator = (module SERVER_SENT_GENERATOR) @@ -940,8 +941,10 @@ let add_route_server_sent_handler ?accept self route f = send_response_idempotent_() ) let send_event = send_event + let close () = raise Exit end in - f req (module SSG : SERVER_SENT_GENERATOR); + try f req (module SSG : SERVER_SENT_GENERATOR); + with Exit -> close_out oc in add_route_handler_ self ?accept ~meth:`GET route ~tr_req f diff --git a/src/Tiny_httpd.mli b/src/Tiny_httpd.mli index 77610de7..ec8dee10 100644 --- a/src/Tiny_httpd.mli +++ b/src/Tiny_httpd.mli @@ -595,6 +595,10 @@ module type SERVER_SENT_GENERATOR = sig unit -> unit (** Send an event from the server. If data is a multiline string, it will be sent on separate "data:" lines. *) + + val close : unit -> unit + (** Close connection. + @since 0.11 *) end type server_sent_generator = (module SERVER_SENT_GENERATOR)