Repository navigation
wasi-http: Ensure buffered body reads aren't dropped when guests pass a host-provided body - #15027
Conversation
|
|
||
| /// A wrapper around [http_body::Body], which yields `prefix` before `body` | ||
| struct BodyWithPrefix<T> { | ||
| prefix: Option<Bytes>, |
There was a problem hiding this comment.
What do you think about storing Bytes directly and checking for is_empty() instead of None?
| res.set_lower(hint.lower() + n); | ||
| if let Some(upper) = hint.upper() { | ||
| res.set_upper(upper + n); |
There was a problem hiding this comment.
nit; could we use saturating_add?
| .body(http_body_util::Full::new(Bytes::from_static( | ||
| b"hello world", | ||
| )))?; | ||
| let res = run_http(P3_HTTP_FORWARD_BODY_COMPONENT, req, oneshot::channel().0) |
There was a problem hiding this comment.
could oneshot::channel().0 be split into a separate assignment with a let, e.g. let (tx, _) = oneshot::channel()?
There was a problem hiding this comment.
Yeah I was also thinking we should refactor run_http since that channel is really only used for some of the tests. What do you think about this additionally: #15041 ?
| /// Enable when https://github.com/bytecodealliance/wasmtime/issues/15026 | ||
| /// has been fixed. | ||
| #[ignore] |
There was a problem hiding this comment.
Could we move this from a comment to a reason with ignore =? See https://doc.rust-lang.org/reference/attributes/testing.html#the-ignore-attribute
| .body(http_body_util::Full::new(Bytes::from_static( | ||
| b"hello world", | ||
| )))?; |
There was a problem hiding this comment.
Could we split this in at least two frames instead to test that the BodyWithPrefix actually forwards to the wrapped body correctly?
In the current test BodyWithPrefix never reads anything from the inner body, because it's read in full by HostBodyStreamProducer.
We could also consider adding trailers here
When a guest passes an http request/response to the host and the body contains a host provided
StreamProducer, we take the fast path of downcasting the stream to the underlyinghttp::Body. But if the guest read from the stream before passing it on, there may be a buffer of data that was read out of theStreamProducer, but not handled by the guest.This change ensures that that buffered data is included when downcasting to an
http::Body. Otherwise it will be silently dropped.Resolves #15020