Http.Body
Message bodies.
The type for reading bytes. Pull control flow.
Some (bytes, first, length)
for letting the client read bytes
from first
to first+length
valid until the next call to the function. The bytes
value must not be modified by the client.None
when there are no longer any bytes to read and subsequent calls always return None
.The type for writing bytes. Push control flow.
Some (byte, first, length)
to write the bytes
from first
to first+length
. These bytes should not be modified until the function returns and the function must only read the given bytes
.None
to signal that there is no longer any bytes to write.The type for body writers. These are functions defining bodies by writing them on the structure 'a
given to them. Typically for service responses the connector provides a structure to write on.
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 =
| Empty
Empty body.
*)| Byte_reader of byte_reader
Byte reader, pulls bytes.
*)| Byte_writer of byte_writer writer
Function that pushes bytes.
*)| Custom of custom_content
Custom content.
*)The type for body contents.
val make : ?content_length:int -> ?content_type:Media_type.t -> content -> t
make 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 None
Raises Invalid_argument
if content_length
is negative.
val empty : t
empty 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 ->
custom_content ->
t
of_custom_content c
is a body defined by the custom content c
.
val of_byte_writer :
?content_length:int ->
?content_type:Media_type.t ->
byte_writer writer ->
t
of_byte_writer w
is a body written by w
.
val of_byte_reader :
?content_length:int ->
?content_type:Media_type.t ->
byte_reader ->
t
of_byte_reader b
is a body from the given byte reader.
val of_string : ?content_type:Media_type.t -> string -> t
of_string s
is a body made of string s
(uses a Byte_writer
). content_length
is set to the length of s
.
val to_byte_reader : t -> (byte_reader, string) Stdlib.result
to_byte_reader b
is a byte reader on the inbound body b
. This errors on Custom
content. It works on Byte_writer
but entails a full copy in memory.
val to_string : t -> (string, string) Stdlib.result
to_string b
reads the body to a string. This errors on Custom
content.
val pp : Stdlib.Format.formatter -> t -> unit
pp
formats bodies for inspection. It guarantees not to touch the content.
val is_empty : t -> bool
is_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 content_type : t -> Media_type.t
content_type b
is the media type of b
.
val content_length : t -> int option
content_length b
is the content length of b
, if known.