remove deprecated path handlers based on scanf

This commit is contained in:
Simon Cruanes 2021-12-12 17:00:51 -05:00
parent 267d29d6c7
commit 2d2ffc722a
No known key found for this signature in database
GPG key ID: 4AC01D0849AA62B6
2 changed files with 0 additions and 59 deletions

View file

@ -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. *)

View file

@ -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. *)