Skip to content

Commit 1c6807d

Browse files
committed
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.
1 parent 91f68d0 commit 1c6807d

File tree

4 files changed

+5
-24
lines changed

4 files changed

+5
-24
lines changed

src/baselib/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
cryptokit
2727
re
2828
ocsigen_lib_base
29+
cohttp-lwt
2930
logs
3031
(select
3132
dynlink_wrapper.ml

src/baselib/ocsigen_stream.ml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,7 @@ let of_lwt_stream stream =
239239
in
240240
make aux
241241

242-
(** Convert an {!Ocsigen_stream.t} into a {!Lwt_stream.t}.
243-
@param is_empty function to skip empty chunk.
244-
*)
245-
let to_lwt_stream ?(is_empty = fun _ -> false) o_stream =
246-
let stream = ref (get o_stream) in
247-
let rec wrap () =
248-
next !stream >>= function
249-
| Finished None -> o_stream.finalizer `Success >>= fun () -> Lwt.return None
250-
| Finished (Some next) ->
251-
stream := next;
252-
wrap ()
253-
| Cont (value, next) ->
254-
stream := next;
255-
if is_empty value then wrap () else Lwt.return (Some value)
256-
in
257-
Lwt_stream.from wrap
242+
let of_cohttp_body body = Cohttp_lwt.Body.to_stream body |> of_lwt_stream
258243

259244
module StringStream = struct
260245
type out = string t

src/baselib/ocsigen_stream.mli

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,9 @@ val of_file : string -> string t
106106
val of_string : string -> string t
107107
(** returns a stream containing a string. *)
108108

109-
val of_lwt_stream : 'a Lwt_stream.t -> 'a t
109+
val of_cohttp_body : Cohttp_lwt.Body.t -> string t
110110
(** Convert a {!Lwt_stream.t} to an {!Ocsigen_stream.t}. *)
111111

112-
val to_lwt_stream : ?is_empty:('a -> bool) -> 'a t -> 'a Lwt_stream.t
113-
(** Convert an {!Ocsigen_stream.t} into a {!Lwt_stream.t}.
114-
@param is_empty function to skip empty chunk.
115-
*)
116-
117112
module StringStream : sig
118113
type out = string t
119114
(** Interface for stream creation (for tyxml) *)

src/server/ocsigen_multipart.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,10 @@ let post_params ~content_type body_gen =
365365
match String.lowercase_ascii ct, String.lowercase_ascii cst with
366366
| "application", "x-www-form-urlencoded" ->
367367
Some
368-
(body_gen |> Cohttp_lwt.Body.to_stream |> Ocsigen_stream.of_lwt_stream
368+
(body_gen |> Ocsigen_stream.of_cohttp_body
369369
|> post_params_form_urlencoded)
370370
| "multipart", "form-data" ->
371371
Some
372-
(body_gen |> Cohttp_lwt.Body.to_stream |> Ocsigen_stream.of_lwt_stream
372+
(body_gen |> Ocsigen_stream.of_cohttp_body
373373
|> post_params_multipart_form_data ctparams)
374374
| _ -> None

0 commit comments

Comments
 (0)