From 1c6807d6638e6b4102fca0fe9baf2f2884c02ab1 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Tue, 10 Jun 2025 14:12:52 +0200 Subject: [PATCH] Ocsigen_stream: Remove Lwt_stream related functions `of_cohttp_body` is added as it is needed by `Ocsigen_multipart`. This can be ported to other representations of cohttp's Body later if needed. --- src/baselib/dune | 1 + src/baselib/ocsigen_stream.ml | 17 +---------------- src/baselib/ocsigen_stream.mli | 7 +------ src/server/ocsigen_multipart.ml | 4 ++-- 4 files changed, 5 insertions(+), 24 deletions(-) diff --git a/src/baselib/dune b/src/baselib/dune index 6024b9c33..3bd1cd8f2 100644 --- a/src/baselib/dune +++ b/src/baselib/dune @@ -26,6 +26,7 @@ cryptokit re ocsigen_lib_base + cohttp-lwt logs (select dynlink_wrapper.ml diff --git a/src/baselib/ocsigen_stream.ml b/src/baselib/ocsigen_stream.ml index 8e7faa970..653ea2699 100644 --- a/src/baselib/ocsigen_stream.ml +++ b/src/baselib/ocsigen_stream.ml @@ -239,22 +239,7 @@ let of_lwt_stream stream = in make aux -(** Convert an {!Ocsigen_stream.t} into a {!Lwt_stream.t}. - @param is_empty function to skip empty chunk. -*) -let to_lwt_stream ?(is_empty = fun _ -> false) o_stream = - let stream = ref (get o_stream) in - let rec wrap () = - next !stream >>= function - | Finished None -> o_stream.finalizer `Success >>= fun () -> Lwt.return None - | Finished (Some next) -> - stream := next; - wrap () - | Cont (value, next) -> - stream := next; - if is_empty value then wrap () else Lwt.return (Some value) - in - Lwt_stream.from wrap +let of_cohttp_body body = Cohttp_lwt.Body.to_stream body |> of_lwt_stream module StringStream = struct type out = string t diff --git a/src/baselib/ocsigen_stream.mli b/src/baselib/ocsigen_stream.mli index 31ec51136..74e4c026a 100644 --- a/src/baselib/ocsigen_stream.mli +++ b/src/baselib/ocsigen_stream.mli @@ -106,14 +106,9 @@ val of_file : string -> string t val of_string : string -> string t (** returns a stream containing a string. *) -val of_lwt_stream : 'a Lwt_stream.t -> 'a t +val of_cohttp_body : Cohttp_lwt.Body.t -> string t (** Convert a {!Lwt_stream.t} to an {!Ocsigen_stream.t}. *) -val to_lwt_stream : ?is_empty:('a -> bool) -> 'a t -> 'a Lwt_stream.t -(** Convert an {!Ocsigen_stream.t} into a {!Lwt_stream.t}. - @param is_empty function to skip empty chunk. -*) - module StringStream : sig type out = string t (** Interface for stream creation (for tyxml) *) diff --git a/src/server/ocsigen_multipart.ml b/src/server/ocsigen_multipart.ml index 51888ea01..c53a1b44d 100644 --- a/src/server/ocsigen_multipart.ml +++ b/src/server/ocsigen_multipart.ml @@ -365,10 +365,10 @@ let post_params ~content_type body_gen = match String.lowercase_ascii ct, String.lowercase_ascii cst with | "application", "x-www-form-urlencoded" -> Some - (body_gen |> Cohttp_lwt.Body.to_stream |> Ocsigen_stream.of_lwt_stream + (body_gen |> Ocsigen_stream.of_cohttp_body |> post_params_form_urlencoded) | "multipart", "form-data" -> Some - (body_gen |> Cohttp_lwt.Body.to_stream |> Ocsigen_stream.of_lwt_stream + (body_gen |> Ocsigen_stream.of_cohttp_body |> post_params_multipart_form_data ctparams) | _ -> None