Skip to content

Ocsigen_stream: Remove Lwt_stream related functions #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/baselib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
cryptokit
re
ocsigen_lib_base
cohttp-lwt
logs
(select
dynlink_wrapper.ml
Expand Down
17 changes: 1 addition & 16 deletions src/baselib/ocsigen_stream.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions src/baselib/ocsigen_stream.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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) *)
Expand Down
4 changes: 2 additions & 2 deletions src/server/ocsigen_multipart.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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