HTTP streaming client, and trailer support#34
HTTP streaming client, and trailer support#34pchickey merged 9 commits intobytecodealliance:mainfrom
Conversation
|
Thank you for submitting this! In general, I'm a big fan of making people's lives easier, and I believe that the general thrust of what you're filing here is the right thing to do. So, yes - I believe this is reasonable! On a first pass, this is what stood out to me:
|
Do you still like calling it
Yeah, I'll work on factoring that out.
I think it'll lead to some trouble handling bodies too :-}. I need to revamp the |
|
I was delayed a bit by starting a new job, but I've rewritten the reactor and streams abstractions in #35 #37. Hopefully that makes some aspects of this a bit simpler. I also added a bunch of common code to translate between the wasi-http types and the I'd like to avoid forcing users to ever use/know about RUSTFLAGS to compile applications. We can produce a HTTP Proxy world application with an ordinary |
Since as of bytecodealliance#19, wstd is using the http crate's types for `HeaderMap`, `Method`, and `Uri`, switch it to use the http crate's types for `Request`, `Response`, and `StatusCode` too. These types have a few more features, and this change makes wstd more interoperable with code that uses the http crate. This also helps with bytecodealliance#34, as the new `Request` and `Response` types here are independent of being incoming or outgoing.
Move `IncomingBody` and related code out of the `response` module and into the `body` module, and prepare it to be used for incoming requests as well as incoming responses. This is in preparation for bytecodealliance#34.
3d0972b to
509c406
Compare
|
I've now overhauled the API here.
Here's a simple hello-world example: #[wstd::proxy]
async fn main(request: Request<IncomingBody>, responder: Responder) -> Finished {
responder
.respond(Response::new(b"Hello, wasi:http/proxy world!\n"))
.await
}For more interesting examples, including a streaming body, see the examples/http_server.rs in the PR.
I've now implemented this. That said, a downside is that it's not just the export, it's also the imports, and it means that the resulting proxy components don't run in plain |
54bafd3 to
dea0b98
Compare
e705d38 to
db2b1d0
Compare
6e0dca1 to
853da25
Compare
853da25 to
5aecf66
Compare
309be4a to
9e8f48f
Compare
9e8f48f to
052b115
Compare
|
With other features factored out into separate PRs that have now landed, this PR now contains a series of patches adding output-streaming client and client trailers support, and a nice example. |
052b115 to
0b2476d
Compare
src/http/client.rs
Outdated
| /// to wait for the response. | ||
| pub struct FutureIncomingResponse(WasiFutureIncomingResponse); | ||
|
|
||
| impl FutureIncomingResponse { |
There was a problem hiding this comment.
I think this can be https://doc.rust-lang.org/std/future/trait.IntoFuture.html ?
There was a problem hiding this comment.
I've now updated it to use impl Future.
Co-authored-by: Pat Hickey <pat@moreproductive.org>
Add a wstd API for creating proxy applications, wrapping the WASI proxy world trait and macro.
Compiling the example with
RUSTFLAGS="-Clink-arg=--wasi-adapter=proxy"produces a program that runs inwasmtime serve.Marking as a draft for now, as it's still experimental. Feedback on the approach or "is this even a reasonable idea" welcome 😄.