Refactor WASIp2 wasi:http implementation #12748
Open
alexcrichton wants to merge 7 commits intobytecodealliance:mainfrom
Open
Refactor WASIp2 wasi:http implementation #12748alexcrichton wants to merge 7 commits intobytecodealliance:mainfrom
wasi:http implementation #12748alexcrichton wants to merge 7 commits intobytecodealliance:mainfrom
Conversation
This mirrors the `wasmtime-wasi` crate's organization where there's a `p2` module and a `p3` module at the top level.
This commit reorganizes and refactors the WASIp2 implementation of
`wasi:http` to look more like other `wasmtime-wasi`-style interfaces.
Specifically the old `WasiHttpImpl<T>` structure is removed in favor of
as `WasiHttpCtxView<'_>` type that is used to implement
bindgen-generated `Host` traits. This necessitated reorganizing the
methods of the previous `WasiHttpView` trait like so:
* The `WasiHttpView` trait is renamed to `WasiHttpHooks` to make space
for a new `WasiHttpView` which behaves like `WasiView`, for example.
* The `ctx` and `table` methods of `WasiHttpHooks` were removed since
they'll be fields in `WasiHttpCtxView`.
* Helper methods for WASIp2 were moved to methods on `WasiHttpCtxView`
instead of default methods on `WasiHttpHooks`.
With these changes in place the WASIp3 organization was also updated
slightly as well. Notably WASIp3 now contains a reference to the crate's
`WasiHttpCtx` structure (which has field limits for example). WASIp3's
previous `WasiHttpCtx` trait is now renamed to `WasiHttpHooks` as well.
This means that there are two `WasiHttpHooks` traits right now, one for
WASIp2 and one for WASIp3. In the future I would like to unify these two
but that will require some more work around the default `send_request`.
A final note here is that the `WasiHttpHooks` trait previously, and
continues to be, optional for embedders to implement. Default functions
are provided as `wasmtime_wasi_http::{p2, p3}::default_hooks`.
Additionally there's a `Default for &mut dyn WasiHttpHooks`
implementation, too.
With all that outlined: the motivation for this change is to bring the
WASIp2 and WASIp3 implementations of `wasi:http` closer together. This
is inspired by refactorings I was doing for bytecodealliance#12674 to apply the same
header limitations for WASIp3 as is done for WASIp2. Prior to this
change there were a number of differences such as WASIp3 not having
`crate::WasiHttpCtx` around, WASIp2 having a different organization of
structures/borrows, etc. The goal is to bring the two implementations
closer in line with each other to make refactoring across them more
consistent and easier.
rvolosatovs
approved these changes
Mar 10, 2026
rvolosatovs
reviewed
Mar 10, 2026
|
|
||
| #[doc(hidden)] | ||
| #[cfg(feature = "default-send-request")] | ||
| impl WasiHttpHooks for [(); 0] {} |
Member
There was a problem hiding this comment.
Out of curiosity, is there a reason to use empty array here as opposed to e.g. a unit?
Member
Author
There was a problem hiding this comment.
While I thought it was possible to return &mut ZST, apparently that's only implemented for empty arrays in rustc rather than all empty types -- hence the array here. It was the only way I could think of to safely get a &'static mut T to implement the trait on.
dicej
approved these changes
Mar 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is a refactoring and reorganization mostly around WASIp2's implementation of
wasi:http. Notably I am trying to get the implementations in this crate to look more likewasmtime-wasiwith changes such as:p2andp3module for each respective implementation.WasiHttpViewtrait which projects outWasiHttpCtxViewfor both WASI versionsWasiHttpCtxstructureWasiHttpViewandWasiHttpCtxViewtrait/struct (that's not done just yet)This PR is a step in this direction. There are two commits here which are doing similar things but are still separate. The first moves all the WASIp2 bits under a
p2top-level module. The second applies many structural refactorings to resolve the remaining bullets above.Future work here includes accounting for #12674, working to have a single
WasiHttpHookstrait (and thus a singleWasiHttpViewtrait/WasiHttpCtxViewstruct), and updating idioms around WASIp2 to look more like WASIp3 (e.g. similar-looking embedder-style APIs).