-
Notifications
You must be signed in to change notification settings - Fork 15
use http_body::Body #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
512947a to
c1451ba
Compare
it only needs to be an internal implementation detail
da75dda to
b5ad19c
Compare
b5ad19c to
5d82cd8
Compare
|
The previous |
|
There's no spawning required in order to produce a streaming body. The
Unfortunately, because Body is implemented in terms of a poll_ fn, its not trivial to hook it up to |
aea7ac5 to
85c2ab7
Compare
85c2ab7 to
7c0b015
Compare
sunfishcode
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I haven't studied the implementation here in detail, but I think the big picture here of integrating with the Rust http_body crate makes sense.
…cWrite traits because the traits have ?Send bounds, but the actual AsyncInputStream and AsyncOutputStream are both Send, so when we bypass the traits Rust can prove that the Future for splicing is Send. Same with write_all: when used through AsyncWrite its ?Send, but when used on AsyncOutputStream the Future for write_all is Send. Together, these changes allow us to show Rust that the Body::send and http::Client::send futures are Send.

This is a major rewrite of the http api to provide compatibility with the
http_body::Bodytrait. This trait is used throughout the Rust http ecosystem (e.g. hyper, reqwest, axum) to provide an async streaming representation of bodies with trailers.There is a new
wstd::http::Bodystruct that is a concrete representation for bodies.The http server entrypoint now looks like:
http::Client now looks like
There is no more
IntoBodytrait. To construct a Body, there are:Body::emptyfor the empty body, orimpl From<()> for BodyFrom<&[u8]>(which will make a clone) orFrom<Vec<u8>>orFrom<Bytes>for aBodyfrom bytes.From<&str>(which will make a clone) orFrom<String>for aBodyfrom strings.Body::from_jsonfor aBodyfrom aSerialize(requires featurejson)Body::from_streamorBody::from_try_streamfor aBodyfrom aStreamofInto<Bytes>From<AsyncInputStream>for aBodywith contents given by the contents of a WASI input-stream. Currently, this implementation goes by way ofBody::from_try_stream(AsyncInputStream::into_stream()), which means it does not get thewstd::io::copysplicing optimization. This can be improved in the future.incoming-bodyresource. This variation allows efficient forwarding to anoutgoing-bodywhere body streaming can skip copying in and out of the guest, viawstd::io::copy.The ways to consume a Body are:
Body::into_boxed_bodyconverts it to anUnsyncBoxBody<Bytes, Error>. This is a boxed representation ofhttp_body::Bodythat isSendbut notSync. The Unsync variant is required for compatibility with theaxumcrate.async fn Body::contents(&mut self) -> Result<&[u8], Error>is ready when all contents of the body have been collected, and gives them as a byte slice.async fn Body::str_contents(&mut self) -> Result<&str, Error>is ready when all contents of the body have been collected, and gives them as a str slice.async fn Body::json(&mut self) -> Result<T, Error>gathers body contents and then usesT: serde::Deserializeto deserialize to json (requires featurejson).The http server and client examples and their test harnesses have been rewritten and expanded as part of this effort.