Skip to content

Unify more of the p2/p3 paths in the wasmtime-wasi-http crate#13812

Open
alexcrichton wants to merge 6 commits into
bytecodealliance:mainfrom
alexcrichton:http-unify
Open

Unify more of the p2/p3 paths in the wasmtime-wasi-http crate#13812
alexcrichton wants to merge 6 commits into
bytecodealliance:mainfrom
alexcrichton:http-unify

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

This PR takes us further down the road of designing the wasmtime-wasi-http crate in the same manner as the wasmtime-wasi crate which is to say that there's one source-of-truth context/configuration/etc which all WASI impls are derived from. Previously there were separate hooks/contexts for p2/p3 due to historical differences, and this is a refactoring to bring the two together.

The largest part of the refactoring here is the addition of a new wasmtime_wasi_http::Error type which unifies p2/p3 as well as underlying possible errors. This means that host-facing operations now work with this type rather than the raw WIT types.

Some pieces this helps are:

  • No more duplication of default_send_request
  • Large boilerplate removal in the handler.rs module
  • No more duplication of contexts/hooks/etc.
  • Better centralized documentation for types.
  • Hosts have an easier time supporting both p2/p3 with a unified error type.

Note that this is currently built on #13810

This commit is made in preparation for eventually merging the
`WasiHttpHooks` traits of the p2 and p3 modules to ensure that they're
handled uniformly across the crate. This'll pave the way for future
refactoring such as only handling one `default_send_request` and more
uniform handling of HTTP headers. These traits are not merged yet,
however, and the goal of this commit is to resolve a major point of
divergence: the `send_request` method. This commit changes the wasip2
signature to instead look like the wasip3 signature.

One change made in this commit as a result is that the
between-bytes-timeout is now only handled by default in
`default_send_request` instead of unconditionally wrapping whatever the
host generated. This is in-line with what wasip3 does, for example.

Much of this commit is juggling types around to get things to line up,
so various signatures/etc were all refactored along the way.
This commit starts paving the path to having wasip2 and wasip3 for HTTP
use the same context, hook trait, etc. The main piece introduced here is
a new `wasmtime_wasi_http::Error` type which is intended to unify the
wasip2 and wasip3 error codes while also supporting other typed errors.
This does not yet update wasip2 and only updates the wasip3 side of
things.

Much of the wasip3 changes are juggling errors types where everything
coming from the host is an `Error` while everything related to the guest
is an `ErrorCode`. Locations were adjusted as appropriate to convert
where needed.
Also get all the tests passing
No need for so much error conversion now that there's one crate type
@alexcrichton alexcrichton requested a review from dicej July 3, 2026 03:14
@alexcrichton alexcrichton requested review from a team as code owners July 3, 2026 03:14
@github-actions github-actions Bot added the wasmtime:c-api Issues pertaining to the C API. label Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasmtime:c-api Issues pertaining to the C API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant