From 284d1f7400032a13ffa25d100802da733f6cf202 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 15 Apr 2024 12:11:46 -0400 Subject: [PATCH] add optional middlewares to tiny_httpd_ws --- src/ws/tiny_httpd_ws.ml | 4 ++-- src/ws/tiny_httpd_ws.mli | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ws/tiny_httpd_ws.ml b/src/ws/tiny_httpd_ws.ml index d278e919..41a8cc67 100644 --- a/src/ws/tiny_httpd_ws.ml +++ b/src/ws/tiny_httpd_ws.ml @@ -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 diff --git a/src/ws/tiny_httpd_ws.mli b/src/ws/tiny_httpd_ws.mli index bb63f992..10ce1fee 100644 --- a/src/ws/tiny_httpd_ws.mli +++ b/src/ws/tiny_httpd_ws.mli @@ -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 ->