Http.BodyMessage bodies.
Important. Bodies are ressources, they must be properly consumed or dismissed if not used.
The type for functions writing on the given bytes writer. The bytes writer must write an Bytesrw.Bytes.Slice.eod before returning if and only if eod is true.
The type for custom body contents.
This allows bodies to expose connector specific readable or writable representations. For example the Webs_unix.Fd.Writer custom content defines a body content by a function that writes directly on an output file descriptor provided by the connector.
type content = | EmptyEmpty body.
*)| Bytes_reader of Bytesrw.Bytes.Reader.tBytes reader, pulls bytes.
*)| Bytes_writer of bytes_writerFunction that pushes bytes.
*)| Custom of custom_contentCustom content.
*)The type for body contents.
val make :
?content_length:int ->
?content_type:Media_type.t ->
?finally:(unit -> unit) ->
content ->
tmake c is a body with content c and:
content_type the content type. Defaults to Media_type.application_octet_stream.content_length the content length in bytes, if known. Defaults to Nonefinally is a function that is called after the body was consumed or dismissed. It must not raise and support being called more than once.Raises Invalid_argument if content_length is negative.
val empty : tempty s is a body with Empty content. The content_type is Media_type.none, the content_length is 0 and close is a nop.
val of_custom_content :
?content_length:int ->
?content_type:Media_type.t ->
?finally:(unit -> unit) ->
custom_content ->
tof_custom_content c is a body defined by the custom content c.
val of_bytes_writer :
?content_length:int ->
?content_type:Media_type.t ->
?finally:(unit -> unit) ->
bytes_writer ->
tof_byte_writer w is a body written by w.
val of_bytes_reader :
?content_length:int ->
?content_type:Media_type.t ->
?finally:(unit -> unit) ->
Bytesrw.Bytes.Reader.t ->
tof_byte_reader b is a body from the given byte reader.
val of_string : ?content_type:Media_type.t -> string -> tof_string s is a body made of string s (uses a Byte_writer). content_length is set to the length of s.
val content_type : t -> Media_type.tcontent_type b is the media type of b.
val content_length : t -> int optioncontent_length b is the content length of b, if known.
val finally : t -> unit -> unitfinally b is the function called whenever the body contents has been consumed. Unless otherwise noted this is called automatically by consuming functions.
val dismiss : t -> unitdismiss b must be called if the body will not be consumed.
val write :
eod:bool ->
Bytesrw.Bytes.Writer.t ->
t ->
(unit, string) Stdlib.resultwrite ~eod w body writes the body on w. This errors on Custom content.
val to_string : t -> (string, string) Stdlib.resultto_string b reads the body to a string. This errors on Custom content.
val to_bytes_reader : t -> (Bytesrw.Bytes.Reader.t, string) Stdlib.resultto_bytes_reader b is a bytes reader on the body b. This errors on Custom content. It works on Bytes_writers but entails a full copy in memory.
Important. After the reader has returned Bytesrw.Bytes.Slice.eod it is the client's duty to call finally b ().
val is_empty : t -> boolis_empty b is true iff content b is Empty. Note that this does not rule out a writer that doesn't write any data.
val pp : Stdlib.Format.formatter -> t -> unitpp formats bodies for inspection. It guarantees not to touch the content.