From ac09f85c198e6ea7266739f38b55020065ceb7b6 Mon Sep 17 00:00:00 2001 From: Maxime Levillain Date: Wed, 26 Jun 2024 10:17:05 +0200 Subject: [PATCH] Not_found instead of Method_not_allowed if the path has no services --- src/server/directory.ml | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/server/directory.ml b/src/server/directory.ml index abaaecf..e225600 100644 --- a/src/server/directory.ml +++ b/src/server/directory.ml @@ -208,22 +208,23 @@ let lookup ?meth ?content_type dir r path : (lookup_ok, lookup_error) result Lwt end | Some `HEAD -> Lwt.return_ok `head | Some (#Meth.t as m) -> - match m, MethMap.find_opt m dir.services with - | _, Some (Http {service; handler}) -> - let input = Service.input service in - let output = Service.output service in - let errors = Service.errors_handler service in - let access_control = Service.access_control service in - let h = ser_handler ?content_type ~access_control handler args input output errors in - Lwt.return_ok @@ `http h - | `GET, Some (Websocket {service; react; bg; onclose; step}) -> - let input = Service.input service in - let output = Service.output service in - let errors = Service.errors_encoding service in - let react, bg = ser_websocket react bg args input output errors in - let onclose = match onclose with None -> None | Some f -> Some (fun () -> f args) in - Lwt.return_ok @@ `ws (react, bg, onclose, step) - | _ -> Lwt.return_error `Method_not_allowed + if MethMap.is_empty dir.services then Lwt.return_error `Not_found + else match m, MethMap.find_opt m dir.services with + | _, Some (Http {service; handler}) -> + let input = Service.input service in + let output = Service.output service in + let errors = Service.errors_handler service in + let access_control = Service.access_control service in + let h = ser_handler ?content_type ~access_control handler args input output errors in + Lwt.return_ok @@ `http h + | `GET, Some (Websocket {service; react; bg; onclose; step}) -> + let input = Service.input service in + let output = Service.output service in + let errors = Service.errors_encoding service in + let react, bg = ser_websocket react bg args input output errors in + let onclose = match onclose with None -> None | Some f -> Some (fun () -> f args) in + Lwt.return_ok @@ `ws (react, bg, onclose, step) + | _ -> Lwt.return_error `Method_not_allowed let step_of_path path = let rec aux : type r p. (r, p) Path.t -> Step.t list -> Step.t list = fun path acc ->