From 2d2ffc722a169827f440a63734474e5fee73a94d Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Sun, 12 Dec 2021 17:00:51 -0500 Subject: [PATCH] remove deprecated path handlers based on scanf --- src/Tiny_httpd.ml | 28 ---------------------------- src/Tiny_httpd.mli | 31 ------------------------------- 2 files changed, 59 deletions(-) diff --git a/src/Tiny_httpd.ml b/src/Tiny_httpd.ml index 0270ca90..58ed49bd 100644 --- a/src/Tiny_httpd.ml +++ b/src/Tiny_httpd.ml @@ -852,34 +852,6 @@ let add_decode_request_cb self f = self.cb_decode_req <- f :: self.cb_decode_re let add_encode_response_cb self f = self.cb_encode_resp <- f :: self.cb_encode_resp let set_top_handler self f = self.handler <- f -let add_path_handler_ - ?(accept=fun _req -> Ok ()) - ?meth ~tr_req self fmt f = - let ph req : cb_path_handler resp_result option = - match meth with - | Some m when m <> req.Request.meth -> None (* ignore *) - | _ -> - begin match Scanf.sscanf (Request.non_query_path req) fmt f with - | handler -> - (* we have a handler, do we accept the request based on its headers? *) - begin match accept req with - | Ok () -> Some (Ok (fun _oc req ~resp -> resp (handler (tr_req req)))) - | Error _ as e -> Some e - end - | exception _ -> - None (* path didn't match *) - end - in - self.path_handlers <- ph :: self.path_handlers - -(* TODO: remove *) -let add_path_handler ?accept ?meth self fmt f = - add_path_handler_ ?accept ?meth ~tr_req:Request.read_body_full self fmt f - -(* TODO: remove *) -let add_path_handler_stream ?accept ?meth self fmt f = - add_path_handler_ ?accept ?meth ~tr_req:(fun x->x) self fmt f - (* route the given handler. @param tr_req wraps the actual concrete function returned by the route and makes it into a handler. *) diff --git a/src/Tiny_httpd.mli b/src/Tiny_httpd.mli index f9bf9a15..21752f7c 100644 --- a/src/Tiny_httpd.mli +++ b/src/Tiny_httpd.mli @@ -544,37 +544,6 @@ val add_route_handler_stream : json decoder (such as [Jsonm]) or into a file. @since 0.6 *) -val add_path_handler : - ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> - ?meth:Meth.t -> - t -> - ('a, Scanf.Scanning.in_channel, - 'b, 'c -> string Request.t -> Response.t, 'a -> 'd, 'd) format6 -> - 'c -> unit -[@@ocaml.deprecated "use add_route_handler instead"] -(** Similar to {!add_route_handler} but based on scanf. - - This uses {!Scanf}'s splitting, which has some gotchas (in particular, - ["%s"] is eager, so it's generally necessary to delimit its - scope with a ["@/"] delimiter. The "@" before a character indicates it's - a separator. - - @deprecated use {!add_route_handler} instead. *) - -val add_path_handler_stream : - ?accept:(unit Request.t -> (unit, Response_code.t * string) result) -> - ?meth:Meth.t -> - t -> - ('a, Scanf.Scanning.in_channel, - 'b, 'c -> byte_stream Request.t -> Response.t, 'a -> 'd, 'd) format6 -> - 'c -> unit -[@@ocaml.deprecated "use add_route_handler_stream instead"] -(** Similar to {!add_path_handler}, but where the body of the request - is a stream of bytes that has not been read yet. - This is useful when one wants to stream the body directly into a parser, - json decoder (such as [Jsonm]) or into a file. - @since 0.3 *) - (** {2 Server-sent events} {b EXPERIMENTAL}: this API is not stable yet. *)