sw17ch opened PR #15225 from sw17ch:sw17ch/expose-http-extensions to bytecodealliance:main:
Add a public
extensionsfield to the p3RequestandResponsetypes.This allows embedders to attach host-side data to a request or response and to retrieve it through the
Resource. For example, this allows the host to stash information associated with the request or response without placing it in headers. This change does not allow the guest to observe or construct extensions. Requests and responses created by the guest start with an empty set of extensions.My specific use case is that I need to associate metadata with a request that came in with a header, but I want to strip this header from the request before forwarding it to the guest. The guest is able to use host calls to interact with this metadata, but should not be able to observe the value directly. By putting this in the extensions, I can reach the metadata through the
Resourcehandle rather than having to rely on something like the address of a reachableArcthat should be unique to theRequest.I had considered and rejected several alternatives:
- Keying off of
Resource::rep()- if the guest drops the request and creates a new one, it may reuse theu32id- Tracking with
TaskGroupHook- trackingguest->hostandhost->guestcalls cannot handle the case where a request or response migrates to a different taskWorkerState::RequestData- does not work with custom worlds usingwasi:httptypes, and is only available viaWorkerState::on_request_startforbidden_header_filter()and re-parse the header on host calls - forbidden headers are stripped before entering the guest viaFieldMap::new_immutable; additionally, this is expensive for my use caseThere is a behavior change: extensions that were previously dropped when converting between
httpandp3types now pass through the guest. A concrete example is that hyper's client records non-canonical HTTP/1 reason phrases as an extension. If the guest returns this response and the host forwards it through to a hyper HTTP/1 server, that server will now write that non-canonical phrase to its client.New tests verify that extensions survive a guest forwarding a request or response unchanged, and that the reason phrase from the hyper client survives as a
hyper::ext::ReasonPhraseextension.One gap:
ProxyHandlerdrops extensions, so users ofProxyHandlerwill still not be able to access extensions associated with the request. This is one-sided: the response extensions are not stripped, so a response given to a guest and returned from the guest will preserve extensions. I am happy to open up a follow-up PR to address this gap.
sw17ch removed the review request for wasmtime-wasi-reviewers from PR #15225.
sw17ch requested dicej for a review on PR #15225.
sw17ch requested wasmtime-wasi-reviewers for a review on PR #15225.
sw17ch requested wasmtime-core-reviewers for a review on PR #15225.
sw17ch edited PR #15225:
Add a public
extensionsfield to the p3RequestandResponsetypes.This allows embedders to attach host-side data to a request or response and to retrieve it through the
Resource. For example, this allows the host to stash information associated with the request or response without placing it in headers. This change does not allow the guest to observe or construct extensions. Requests and responses created by the guest start with an empty set of extensions.My specific use case is that I need to associate metadata with a request that came in with a header, but I want to strip this header from the request before forwarding it to the guest. The guest is able to use host calls to interact with this metadata, but should not be able to observe the value directly. By putting this in the extensions, I can reach the metadata through the
Resourcehandle rather than having to rely on something like the address of a reachableArcthat should be unique to theRequestor `Response.I had considered and rejected several alternatives:
- Keying off of
Resource::rep()- if the guest drops the request and creates a new one, it may reuse theu32id- Tracking with
TaskGroupHook- trackingguest->hostandhost->guestcalls cannot handle the case where a request or response migrates to a different taskWorkerState::RequestData- does not work with custom worlds usingwasi:httptypes, and is only available viaWorkerState::on_request_startforbidden_header_filter()and re-parse the header on host calls - forbidden headers are stripped before entering the guest viaFieldMap::new_immutable; additionally, this is expensive for my use caseThere is a behavior change: extensions that were previously dropped when converting between
httpandp3types now pass through the guest. A concrete example is that hyper's client records non-canonical HTTP/1 reason phrases as an extension. If the guest returns this response and the host forwards it through to a hyper HTTP/1 server, that server will now write that non-canonical phrase to its client.New tests verify that extensions survive a guest forwarding a request or response unchanged, and that the reason phrase from the hyper client survives as a
hyper::ext::ReasonPhraseextension.One gap:
ProxyHandlerdrops extensions, so users ofProxyHandlerwill still not be able to access extensions associated with the request. This is one-sided: the response extensions are not stripped, so a response given to a guest and returned from the guest will preserve extensions. I am happy to open up a follow-up PR to address this gap.
sw17ch edited PR #15225:
Add a public
extensionsfield to the p3RequestandResponsetypes.This allows embedders to attach host-side data to a request or response and to retrieve it through the
Resource. For example, this allows the host to stash information associated with the request or response without placing it in headers. This change does not allow the guest to observe or construct extensions. Requests and responses created by the guest start with an empty set of extensions.My specific use case is that I need to associate metadata with a request that came in with a header, but I want to strip this header from the request before forwarding it to the guest. The guest is able to use host calls to interact with this metadata, but should not be able to observe the value directly. By putting this in the extensions, I can reach the metadata through the
Resourcehandle rather than having to rely on something like the address of a reachableArcthat should be unique to theRequestorResponse.I had considered and rejected several alternatives:
- Keying off of
Resource::rep()- if the guest drops the request and creates a new one, it may reuse theu32id- Tracking with
TaskGroupHook- trackingguest->hostandhost->guestcalls cannot handle the case where a request or response migrates to a different taskWorkerState::RequestData- does not work with custom worlds usingwasi:httptypes, and is only available viaWorkerState::on_request_startforbidden_header_filter()and re-parse the header on host calls - forbidden headers are stripped before entering the guest viaFieldMap::new_immutable; additionally, this is expensive for my use caseThere is a behavior change: extensions that were previously dropped when converting between
httpandp3types now pass through the guest. A concrete example is that hyper's client records non-canonical HTTP/1 reason phrases as an extension. If the guest returns this response and the host forwards it through to a hyper HTTP/1 server, that server will now write that non-canonical phrase to its client.New tests verify that extensions survive a guest forwarding a request or response unchanged, and that the reason phrase from the hyper client survives as a
hyper::ext::ReasonPhraseextension.One gap:
ProxyHandlerdrops extensions, so users ofProxyHandlerwill still not be able to access extensions associated with the request. This is one-sided: the response extensions are not stripped, so a response given to a guest and returned from the guest will preserve extensions. I am happy to open up a follow-up PR to address this gap.
:thumbs_up: pchickey submitted PR review:
This is sensible and straightforward. Lets fill the ProxyHandler gap and use the Extensions there, and exercise that as well, rather than wait for a follow-up PR.
sw17ch commented on PR #15225:
Closing the gap is a 3 line diff, but that doesn't include test infrastructure. There don't appear to be any existing tests for
ProxyHandler, so I'm trying to figure out what to do there. Would we accept closing the gap without a demonstration that the extensions reach end to end?
pchickey commented on PR #15225:
Ah yeah if ProxyHandler is untested as an embedding (vs as part of wasmtime-cli) then I'll accept those trivial 3 lines without a test. If you're using ProxyHandler in your embedding and dont mind contributing some tests in a follow up, thats appreciated but not something that should block this PR.
sw17ch updated PR #15225.
sw17ch commented on PR #15225:
I have pushed eb25ef942d608762775699071389a4ebf8d49ca9 which closes the gap with a small patch. I have the start of a test, but I think it's worth spending a little more time on it before including it in this work. Thank you.
sw17ch edited PR #15225:
Add a public
extensionsfield to the p3RequestandResponsetypes.This allows embedders to attach host-side data to a request or response and to retrieve it through the
Resource. For example, this allows the host to stash information associated with the request or response without placing it in headers. This change does not allow the guest to observe or construct extensions. Requests and responses created by the guest start with an empty set of extensions.My specific use case is that I need to associate metadata with a request that came in with a header, but I want to strip this header from the request before forwarding it to the guest. The guest is able to use host calls to interact with this metadata, but should not be able to observe the value directly. By putting this in the extensions, I can reach the metadata through the
Resourcehandle rather than having to rely on something like the address of a reachableArcthat should be unique to theRequestorResponse.I had considered and rejected several alternatives:
- Keying off of
Resource::rep()- if the guest drops the request and creates a new one, it may reuse theu32id- Tracking with
TaskGroupHook- trackingguest->hostandhost->guestcalls cannot handle the case where a request or response migrates to a different taskWorkerState::RequestData- does not work with custom worlds usingwasi:httptypes, and is only available viaWorkerState::on_request_startforbidden_header_filter()and re-parse the header on host calls - forbidden headers are stripped before entering the guest viaFieldMap::new_immutable; additionally, this is expensive for my use caseThere is a behavior change: extensions that were previously dropped when converting between
httpandp3types now pass through the guest. A concrete example is that hyper's client records non-canonical HTTP/1 reason phrases as an extension. If the guest returns this response and the host forwards it through to a hyper HTTP/1 server, that server will now write that non-canonical phrase to its client.New tests verify that extensions survive a guest forwarding a request or response unchanged, and that the reason phrase from the hyper client survives as a
hyper::ext::ReasonPhraseextension.~One gap:
ProxyHandlerdrops extensions, so users ofProxyHandlerwill still not be able to access extensions associated with the request. This is one-sided: the response extensions are not stripped, so a response given to a guest and returned from the guest will preserve extensions. I am happy to open up a follow-up PR to address this gap.~Gap closed with eb25ef942d608762775699071389a4ebf8d49ca9.
pchickey added PR #15225 wasi-http: expose http::Extensions on p3 Request and Response to the merge queue
pchickey commented on PR #15225:
Thanks John, more like this always appreciated
:check: pchickey merged PR #15225.
pchickey removed PR #15225 wasi-http: expose http::Extensions on p3 Request and Response from the merge queue
Last updated: Nov 19 2026 at 20:05 UTC