Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/wasi-http/src/p3/proxy.rs
3071 views
1
use crate::p3::WasiHttpView;
2
use crate::p3::bindings::Service;
3
use crate::p3::bindings::http::types::{ErrorCode, Request, Response};
4
use wasmtime::component::{Accessor, TaskExit};
5
use wasmtime::error::Context as _;
6
7
impl Service {
8
/// Call `wasi:http/handler#handle` on [Service] getting a [Response] back.
9
pub async fn handle(
10
&self,
11
store: &Accessor<impl WasiHttpView>,
12
req: impl Into<Request>,
13
) -> wasmtime::Result<Result<(Response, TaskExit), ErrorCode>> {
14
let req = store.with(|mut store| {
15
store
16
.data_mut()
17
.http()
18
.table
19
.push(req.into())
20
.context("failed to push request to table")
21
})?;
22
match self.wasi_http_handler().call_handle(store, req).await? {
23
(Ok(res), task) => {
24
let res = store.with(|mut store| {
25
store
26
.data_mut()
27
.http()
28
.table
29
.delete(res)
30
.context("failed to delete response from table")
31
})?;
32
Ok(Ok((res, task)))
33
}
34
(Err(err), _) => Ok(Err(err)),
35
}
36
}
37
}
38
39