add optional middlewares to tiny_httpd_ws

This commit is contained in:
Simon Cruanes 2024-04-15 12:11:46 -04:00
parent 241d9aeaf1
commit 284d1f7400
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 3 additions and 2 deletions

View file

@ -468,14 +468,14 @@ struct
()
end
let add_route_handler ?accept ?(accept_ws_protocol = fun _ -> true)
let add_route_handler ?accept ?(accept_ws_protocol = fun _ -> true) ?middlewares
(server : Server.t) route (f : handler) : unit =
let module M = Make_upgrade_handler (struct
let handler = f
let accept_ws_protocol = accept_ws_protocol
end) in
let up : Server.upgrade_handler = (module M) in
Server.add_upgrade_handler ?accept server route up
Server.add_upgrade_handler ?accept ?middlewares server route up
module Private_ = struct
let apply_masking = Reader.apply_masking

View file

@ -17,6 +17,7 @@ exception Close_connection
val add_route_handler :
?accept:(unit Request.t -> (unit, int * string) result) ->
?accept_ws_protocol:(string -> bool) ->
?middlewares:Server.Head_middleware.t list ->
Server.t ->
(Server.upgrade_handler, Server.upgrade_handler) Route.t ->
handler ->