Skip to content

Commit

Permalink
Add some docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragsoni committed Dec 31, 2022
1 parent 3876035 commit 873c667
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions http/src/body.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
open! Core
open! Async

(** [Stream] represents streaming HTTP bodies. This module provides utilities to create
and consume streams, while enforcing the invariant that only one consume can read from
a stream, and that a stream can only be consumed once. *)
module Stream : sig
type t [@@deriving sexp_of]

Expand All @@ -9,11 +12,32 @@ module Stream : sig
closed, or EOF is reached. *)
val of_pipe : [ `Chunked | `Fixed of int ] -> string Pipe.Reader.t -> t

(** [close] allows for closing/tearing-down any resources that are used to produce the
content for a stream. For servers, this function will be called if the underlying
client socket connection is closed, or when the body is fully drained. *)
val close : t -> unit

(** [encoding] informs whether the body needs to be chunk encoded or not. For servers
this function is used to automatically populate the transfer-encoding or
content-length headers. *)
val encoding : t -> [ `Chunked | `Fixed of int ]

(** [iter t ~f] consumes chunks of data one at a time. The stream can only be iterated
on once. *)
val iter : t -> f:(string -> unit Deferred.t) -> unit Deferred.t

(** [drain] should consume items one at a time from the stream and discard them. This
function raises if its called after a consumer has started reading data from the
stream. *)
val drain : t -> unit Deferred.t

(** [closed] is a deferred that should be resolved when the stream is closed/drained. *)
val closed : t -> unit Deferred.t

(** [read_started] indicated whether a user started to consume a stream or not. Servers
will use [read_started] to verify if they should drain before starting the next
cycle of the server loop, or if they should wait for the body to be closed by the
user. *)
val read_started : t -> bool
end

Expand Down

0 comments on commit 873c667

Please sign in to comment.