Skip to content

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

Merged
alexcrichton merged 11 commits into
bytecodealliance:mainfrom
alexcrichton:http-unify
Jul 7, 2026
Merged

Unify more of the p2/p3 paths in the wasmtime-wasi-http crate#13812
alexcrichton merged 11 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

@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
Comment thread crates/wasi-http/src/p2/error.rs Outdated
}
}

warn!("hyper error: {err:?}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit surprised to see warn-level logging in a From implementation. What's the rationale?

(same comment applies to p3/conv.rs)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pseudo-preserving preexisting behavior where this is a copy of this function for example, although it wasn't modeled as From before.

IIRC though the source of this is me asking to add a log here. I'm personally paranoid about dropping error context on the floor as it can create pretty confusing situations downstream, and this was intended to strike a balance of "someone can figure things out if things go wrong" with the representation needs here.

I do agree though it's a bit different being in From vs a freestanding function. Do you have a preference to model this not as From but with an explicit conversion?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel strongly about it, although making it an explicit conversion seems reasonable; most people aren't expecting From/Into to have side effects like logging.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another idea: implement TryFrom instead of From.

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
Leave this to a helper function for now.
Similar to the previous commit, but required a bit more juggling.
@alexcrichton alexcrichton requested a review from a team as a code owner July 6, 2026 22:01
@alexcrichton alexcrichton requested review from fitzgen and removed request for a team July 6, 2026 22:01
@alexcrichton

Copy link
Copy Markdown
Member Author

Ok @dicej mind taking another look at the recent commits?

@alexcrichton alexcrichton added this pull request to the merge queue Jul 6, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 6, 2026
@alexcrichton alexcrichton enabled auto-merge July 6, 2026 23:31
@alexcrichton alexcrichton added this pull request to the merge queue Jul 6, 2026
Merged via the queue into bytecodealliance:main with commit 41a902e Jul 7, 2026
57 checks passed
@alexcrichton alexcrichton deleted the http-unify branch July 7, 2026 00:09
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.

2 participants