You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
[v0.3] handle implementations cannot forward trailers without trapping while handling transmit errors #163
Components exporting wasi:http@0.3.0-draft/handle.handle cannot correctly forward incoming requests while tracking the body transmit error.
Assume an application, which forwards the incoming request and returns a successful (200 OK) response with empty body iff forwarding of the incoming request in it's entirety has succeeded to the best of it's knowledge (we can never know for sure due to OS-level buffering).
Pseudo-code (in pseudo-Rust):
asyncfnhandle(req:Request) -> Result<Response,ErrorCode>{let headers = req.headers().clone();
headers.set("X-Forwarded-For",origin_of(headers));let req_body = req.body()?;let(req_stream, req_result) = req_body.stream()?;let(trailers_tx, trailers_rx) = future::new();// We don't know if we will receive trailers at this point, so we are forced to use this APIlet(out_body, out_result) = body::new_with_trailers(req_stream, trailers_rx);// NOTE: this is incorrect, trailers might not be present and we'll only know about it once we have received the body// We should not send empty trailers if none were given, but closing the future without a result is not valid according to the speclet res = http::handle(Request::new(headers,Some(out_body),None)).await?;let trailers = body::finish(req_body).await;// TRAP!}
The application will only find out whether there are trailers to forward once the full incoming body has been read, however the body constructor forces us to make a choice before that has happened (since we want to stream the body being forwarded)
The only way for the application to get a handle to the trailers is by calling finish on the incoming body, however we cannot do that, since there is an active stream handle, that we must pass to the body constructor.
It seems that we need to change the trailers future signature to return option<trailers> and have some way to acquire trailers from the body without moving it
changed the title [-][p3] `handle` implementations cannot forward trailers without trapping while handling transmit errors[/-][+][v0.3] `handle` implementations cannot forward trailers without trapping while handling transmit errors[/+]on Mar 19, 2025
The solution we discussed with @dicej and @lukewagner is creating a new stream and splicing data.
For the first iteration, this will require explicit copying bytes in the guest, however eventually we'll add splice operation on streams allowing to avoid the copy.
Activity
[-][p3] `handle` implementations cannot forward trailers without trapping while handling transmit errors[/-][+][v0.3] `handle` implementations cannot forward trailers without trapping while handling transmit errors[/+]rvolosatovs commentedon Mar 19, 2025
The solution we discussed with @dicej and @lukewagner is creating a new stream and splicing data.
For the first iteration, this will require explicit copying bytes in the guest, however eventually we'll add
spliceoperation on streams allowing to avoid the copy.The example would then look roughly like: