Skip to content

Commit ac09f85

Browse files
committed
Not_found instead of Method_not_allowed if the path has no services
1 parent 2823fb4 commit ac09f85

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/server/directory.ml

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,22 +208,23 @@ let lookup ?meth ?content_type dir r path : (lookup_ok, lookup_error) result Lwt
208208
end
209209
| Some `HEAD -> Lwt.return_ok `head
210210
| Some (#Meth.t as m) ->
211-
match m, MethMap.find_opt m dir.services with
212-
| _, Some (Http {service; handler}) ->
213-
let input = Service.input service in
214-
let output = Service.output service in
215-
let errors = Service.errors_handler service in
216-
let access_control = Service.access_control service in
217-
let h = ser_handler ?content_type ~access_control handler args input output errors in
218-
Lwt.return_ok @@ `http h
219-
| `GET, Some (Websocket {service; react; bg; onclose; step}) ->
220-
let input = Service.input service in
221-
let output = Service.output service in
222-
let errors = Service.errors_encoding service in
223-
let react, bg = ser_websocket react bg args input output errors in
224-
let onclose = match onclose with None -> None | Some f -> Some (fun () -> f args) in
225-
Lwt.return_ok @@ `ws (react, bg, onclose, step)
226-
| _ -> Lwt.return_error `Method_not_allowed
211+
if MethMap.is_empty dir.services then Lwt.return_error `Not_found
212+
else match m, MethMap.find_opt m dir.services with
213+
| _, Some (Http {service; handler}) ->
214+
let input = Service.input service in
215+
let output = Service.output service in
216+
let errors = Service.errors_handler service in
217+
let access_control = Service.access_control service in
218+
let h = ser_handler ?content_type ~access_control handler args input output errors in
219+
Lwt.return_ok @@ `http h
220+
| `GET, Some (Websocket {service; react; bg; onclose; step}) ->
221+
let input = Service.input service in
222+
let output = Service.output service in
223+
let errors = Service.errors_encoding service in
224+
let react, bg = ser_websocket react bg args input output errors in
225+
let onclose = match onclose with None -> None | Some f -> Some (fun () -> f args) in
226+
Lwt.return_ok @@ `ws (react, bg, onclose, step)
227+
| _ -> Lwt.return_error `Method_not_allowed
227228

228229
let step_of_path path =
229230
let rec aux : type r p. (r, p) Path.t -> Step.t list -> Step.t list = fun path acc ->

0 commit comments

Comments
 (0)