Skip to content
This repository was archived by the owner on Nov 25, 2025. It is now read-only.
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

@rvolosatovs

Description

@rvolosatovs

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):

async fn handle(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 API
    let (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 spec

    let 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

Refs #164

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions