Struct wasi::http::types::IncomingBody
source · pub struct IncomingBody { /* private fields */ }
Expand description
Represents an incoming HTTP Request or Response’s Body.
A body has both its contents - a stream of bytes - and a (possibly
empty) set of trailers, indicating that the full contents of the
body have been received. This resource represents the contents as
an input-stream
and the delivery of trailers as a future-trailers
,
and ensures that the user of this interface may only be consuming either
the body contents or waiting on trailers at any given time.
Implementations§
source§impl IncomingBody
impl IncomingBody
sourcepub fn stream(&self) -> Result<InputStream, ()>
pub fn stream(&self) -> Result<InputStream, ()>
Returns the contents of the body, as a stream of bytes.
Returns success on first call: the stream representing the contents can be retrieved at most once. Subsequent calls will return error.
The returned input-stream
resource is a child: it must be dropped
before the parent incoming-body
is dropped, or consumed by
incoming-body.finish
.
This invariant ensures that the implementation can determine whether
the user is consuming the contents of the body, waiting on the
future-trailers
to be ready, or neither. This allows for network
backpressure is to be applied when the user is consuming the body,
and for that backpressure to not inhibit delivery of the trailers if
the user does not read the entire body.
source§impl IncomingBody
impl IncomingBody
sourcepub fn finish(this: IncomingBody) -> FutureTrailers
pub fn finish(this: IncomingBody) -> FutureTrailers
Takes ownership of incoming-body
, and returns a future-trailers
.
This function will trap if the input-stream
child is still alive.