pub struct OutgoingBody { /* private fields */ }
Expand description
Represents an outgoing HTTP Request or Response’s Body.
A body has both its contents - a stream of bytes - and a (possibly
empty) set of trailers, inducating the full contents of the body
have been sent. This resource represents the contents as an
output-stream
child resource, and the completion of the body (with
optional trailers) with a static function that consumes the
outgoing-body
resource, and ensures that the user of this interface
may not write to the body contents after the body has been finished.
If the user code drops this resource, as opposed to calling the static
method finish
, the implementation should treat the body as incomplete,
and that an error has occured. The implementation should propogate this
error to the HTTP protocol by whatever means it has available,
including: corrupting the body on the wire, aborting the associated
Request, or sending a late status code for the Response.
Implementations§
Source§impl OutgoingBody
impl OutgoingBody
Sourcepub fn write(&self) -> Result<OutputStream, ()>
pub fn write(&self) -> Result<OutputStream, ()>
Returns a stream for writing the body contents.
The returned output-stream
is a child resource: it must be dropped
before the parent outgoing-body
resource is dropped (or finished),
otherwise the outgoing-body
drop or finish
will trap.
Returns success on the first call: the output-stream
resource for
this outgoing-body
may be retrieved at most once. Subsequent calls
will return error.
Source§impl OutgoingBody
impl OutgoingBody
Sourcepub fn finish(
this: OutgoingBody,
trailers: Option<Trailers>,
) -> Result<(), ErrorCode>
pub fn finish( this: OutgoingBody, trailers: Option<Trailers>, ) -> Result<(), ErrorCode>
Finalize an outgoing body, optionally providing trailers. This must be
called to signal that the response is complete. If the outgoing-body
is dropped without calling outgoing-body.finalize
, the implementation
should treat the body as corrupted.
Fails if the body’s outgoing-request
or outgoing-response
was
constructed with a Content-Length header, and the contents written
to the body (via write
) does not match the value given in the
Content-Length.