Skip to content

Commit 649f765

Browse files
Merge pull request #564 from fastly/dgohman-fastly/update
Update to the latest WITs and adapter.
2 parents 8c011f3 + 58ea791 commit 649f765

30 files changed

+1820
-805
lines changed

src/component.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ pub(crate) mod bindings {
1010
imports: {
1111
default: tracing,
1212

13+
"fastly:adapter/adapter-backend/register-dynamic-backend": async | tracing,
14+
"fastly:adapter/adapter-http-req/send": async | tracing,
15+
"fastly:adapter/adapter-http-req/send-async": async | tracing,
16+
"fastly:adapter/adapter-http-req/send-async-streaming": async | tracing,
17+
"fastly:adapter/adapter-http-req/send-async-uncached": async | tracing,
18+
"fastly:adapter/adapter-http-req/send-async-uncached-streaming": async | tracing,
19+
"fastly:adapter/adapter-http-req/send-uncached": async | tracing,
20+
1321
"fastly:compute/backend/[constructor]dynamic-backend-options": tracing | trappable,
1422
"fastly:compute/shielding/[constructor]shield-backend-options": tracing | trappable,
1523
"fastly:compute/cache/[constructor]extra-lookup-options": tracing | trappable,
@@ -111,6 +119,9 @@ pub(crate) mod bindings {
111119
"fastly:adapter/adapter-uap/user-agent": super::adapter::uap::UserAgent,
112120
"fastly:compute/kv-store/entry": super::compute::kv_store::Entry,
113121
"fastly:compute/backend/dynamic-backend-options": super::compute::backend::BackendBuilder,
122+
"fastly:compute/backend/backend": String,
123+
"fastly:compute/erl/rate-counter": String,
124+
"fastly:compute/erl/penalty-box": String,
114125
},
115126

116127
trappable_error_type: {
@@ -130,6 +141,11 @@ pub fn link_host_functions(linker: &mut component::Linker<ComponentCtx>) -> anyh
130141
}
131142

132143
pub mod adapter;
144+
pub mod backend;
133145
pub mod compute;
146+
pub mod erl;
134147
pub mod handles;
148+
pub mod http_req;
149+
pub mod image_optimizer;
150+
pub mod shielding;
135151
pub mod wasi;

src/component/adapter.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
//! Implementations for `fastly:adapter` interfaces.
22
3+
pub mod abi;
4+
pub mod backend;
35
pub mod cache;
6+
pub mod erl;
47
pub mod http_cache;
58
pub mod http_downstream;
69
pub mod http_req;
10+
pub mod image_optimizer;
11+
pub mod shielding;
712
pub mod uap;

src/component/adapter/abi.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use crate::component::bindings::fastly::adapter::adapter_abi;
2+
use crate::linking::ComponentCtx;
3+
4+
impl adapter_abi::Host for ComponentCtx {
5+
fn init(&mut self) {}
6+
}

src/component/adapter/backend.rs

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
use crate::component::{
2+
bindings::fastly::adapter::adapter_backend,
3+
bindings::fastly::compute::{http_types, types},
4+
};
5+
use crate::linking::ComponentCtx;
6+
use wasmtime::component::Resource;
7+
8+
impl adapter_backend::Host for ComponentCtx {
9+
async fn register_dynamic_backend(
10+
&mut self,
11+
name: String,
12+
origin: String,
13+
config_handle: Resource<adapter_backend::DynamicBackendOptions>,
14+
) -> Result<(), types::Error> {
15+
// Discard the handle for this API, as we register the backend
16+
// in a namespace that other adapter APIs access by name.
17+
crate::component::backend::register_dynamic_backend(
18+
&mut self.session,
19+
&mut self.wasi_table,
20+
name,
21+
origin,
22+
config_handle,
23+
)
24+
.await
25+
.map(|_| ())
26+
}
27+
28+
fn exists(&mut self, name: String) -> Result<bool, types::Error> {
29+
Ok(crate::component::backend::exists(&mut self.session, &name))
30+
}
31+
32+
fn is_healthy(&mut self, name: String) -> Result<adapter_backend::BackendHealth, types::Error> {
33+
crate::component::backend::is_healthy(&mut self.session, &name)
34+
}
35+
36+
fn is_dynamic(&mut self, name: String) -> Result<bool, types::Error> {
37+
crate::component::backend::is_dynamic(&mut self.session, &name)
38+
}
39+
40+
fn get_host(&mut self, name: String, max_len: u64) -> Result<String, types::Error> {
41+
crate::component::backend::get_host(&mut self.session, &name, max_len)
42+
}
43+
44+
fn get_override_host(
45+
&mut self,
46+
name: String,
47+
max_len: u64,
48+
) -> Result<Option<Vec<u8>>, types::Error> {
49+
crate::component::backend::get_override_host(&mut self.session, &name, max_len)
50+
}
51+
52+
fn get_port(&mut self, backend: String) -> Result<u16, types::Error> {
53+
crate::component::backend::get_port(&mut self.session, &backend)
54+
}
55+
56+
fn get_connect_timeout_ms(&mut self, backend: String) -> Result<u32, types::Error> {
57+
crate::component::backend::get_connect_timeout_ms(&mut self.session, &backend)
58+
}
59+
60+
fn get_first_byte_timeout_ms(&mut self, backend: String) -> Result<u32, types::Error> {
61+
crate::component::backend::get_first_byte_timeout_ms(&mut self.session, &backend)
62+
}
63+
64+
fn get_between_bytes_timeout_ms(&mut self, backend: String) -> Result<u32, types::Error> {
65+
crate::component::backend::get_between_bytes_timeout_ms(&mut self.session, &backend)
66+
}
67+
68+
fn get_http_keepalive_time(
69+
&mut self,
70+
backend: String,
71+
) -> Result<adapter_backend::TimeoutMs, types::Error> {
72+
crate::component::backend::get_http_keepalive_time(&mut self.session, &backend)
73+
}
74+
75+
fn get_tcp_keepalive_enable(&mut self, backend: String) -> Result<bool, types::Error> {
76+
crate::component::backend::get_tcp_keepalive_enable(&mut self.session, &backend)
77+
}
78+
79+
fn get_tcp_keepalive_interval(
80+
&mut self,
81+
backend: String,
82+
) -> Result<adapter_backend::TimeoutSecs, types::Error> {
83+
crate::component::backend::get_tcp_keepalive_interval(&mut self.session, &backend)
84+
}
85+
86+
fn get_tcp_keepalive_probes(
87+
&mut self,
88+
backend: String,
89+
) -> Result<adapter_backend::ProbeCount, types::Error> {
90+
crate::component::backend::get_tcp_keepalive_probes(&mut self.session, &backend)
91+
}
92+
93+
fn get_tcp_keepalive_time(
94+
&mut self,
95+
backend: String,
96+
) -> Result<adapter_backend::TimeoutSecs, types::Error> {
97+
crate::component::backend::get_tcp_keepalive_time(&mut self.session, &backend)
98+
}
99+
100+
fn is_tls(&mut self, backend: String) -> Result<bool, types::Error> {
101+
crate::component::backend::is_tls(&mut self.session, &backend)
102+
}
103+
104+
fn get_tls_min_version(
105+
&mut self,
106+
backend: String,
107+
) -> Result<Option<http_types::TlsVersion>, types::Error> {
108+
crate::component::backend::get_tls_min_version(&mut self.session, &backend)
109+
}
110+
111+
fn get_tls_max_version(
112+
&mut self,
113+
backend: String,
114+
) -> Result<Option<http_types::TlsVersion>, types::Error> {
115+
crate::component::backend::get_tls_max_version(&mut self.session, &backend)
116+
}
117+
}

src/component/adapter/erl.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use crate::component::{bindings::fastly::adapter::adapter_erl, bindings::fastly::compute::types};
2+
use crate::linking::ComponentCtx;
3+
4+
impl adapter_erl::Host for ComponentCtx {
5+
fn check_rate(
6+
&mut self,
7+
rc: String,
8+
entry: String,
9+
delta: u32,
10+
window: u32,
11+
limit: u32,
12+
pb: String,
13+
ttl: u32,
14+
) -> Result<bool, types::Error> {
15+
crate::component::erl::check_rate(
16+
&mut self.session,
17+
&rc,
18+
entry,
19+
delta,
20+
window,
21+
limit,
22+
&pb,
23+
ttl,
24+
)
25+
}
26+
27+
fn ratecounter_increment(
28+
&mut self,
29+
rc: String,
30+
entry: String,
31+
delta: u32,
32+
) -> Result<(), types::Error> {
33+
crate::component::erl::ratecounter_increment(&mut self.session, &rc, entry, delta)
34+
}
35+
36+
fn ratecounter_lookup_rate(
37+
&mut self,
38+
rc: String,
39+
entry: String,
40+
window: u32,
41+
) -> Result<u32, types::Error> {
42+
crate::component::erl::ratecounter_lookup_rate(&mut self.session, &rc, entry, window)
43+
}
44+
45+
fn ratecounter_lookup_count(
46+
&mut self,
47+
rc: String,
48+
entry: String,
49+
duration: u32,
50+
) -> Result<u32, types::Error> {
51+
crate::component::erl::ratecounter_lookup_count(&mut self.session, &rc, entry, duration)
52+
}
53+
54+
fn penaltybox_add(&mut self, pb: String, entry: String, ttl: u32) -> Result<(), types::Error> {
55+
crate::component::erl::penaltybox_add(&mut self.session, &pb, entry, ttl)
56+
}
57+
58+
fn penaltybox_has(&mut self, pb: String, entry: String) -> Result<bool, types::Error> {
59+
crate::component::erl::penaltybox_has(&mut self.session, &pb, entry)
60+
}
61+
}

src/component/adapter/http_cache.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,31 @@ impl adapter_http_cache::Host for ComponentCtx {
1111
fn lookup(
1212
&mut self,
1313
_req_handle: Resource<http_cache::Request>,
14-
_options: http_cache::LookupOptions,
14+
_options: adapter_http_cache::LookupOptions,
1515
) -> Result<Resource<http_cache::Entry>, types::Error> {
1616
Err(Error::Unsupported {
1717
msg: "HTTP Cache API primitives not yet supported",
1818
}
1919
.into())
2020
}
21+
22+
fn transaction_lookup(
23+
&mut self,
24+
_req_handle: Resource<http_cache::Request>,
25+
_options: adapter_http_cache::LookupOptions,
26+
) -> Result<Resource<http_cache::Entry>, types::Error> {
27+
Err(Error::Unsupported {
28+
msg: "HTTP Cache API primitives not yet supported",
29+
}
30+
.into())
31+
}
32+
}
33+
34+
impl adapter_http_cache::HostExtraLookupOptions for ComponentCtx {
35+
fn drop(
36+
&mut self,
37+
_h: Resource<adapter_http_cache::ExtraLookupOptions>,
38+
) -> wasmtime::Result<()> {
39+
Ok(())
40+
}
2141
}

src/component/adapter/http_req.rs

Lines changed: 89 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use {
22
crate::component::bindings::{
33
fastly::adapter::adapter_http_req,
44
fastly::compute::http_downstream::Host as HttpDownstream,
5-
fastly::compute::{http_req, types},
5+
fastly::compute::{http_body, http_req, http_resp, types},
66
},
77
crate::{
88
error::Error,
@@ -28,14 +28,14 @@ impl adapter_http_req::Host for ComponentCtx {
2828
HttpDownstream::fastly_key_is_valid(self, self.ds_req_handle())
2929
}
3030

31-
fn redirect_to_websocket_proxy_deprecated(
31+
fn redirect_to_websocket_proxy_norequest(
3232
&mut self,
3333
_backend: String,
3434
) -> Result<(), types::Error> {
3535
Err(Error::NotAvailable("Redirect to WebSocket proxy").into())
3636
}
3737

38-
fn redirect_to_grip_proxy_deprecated(
38+
fn redirect_to_grip_proxy_norequest(
3939
&mut self,
4040
backend_name: String,
4141
) -> Result<(), types::Error> {
@@ -155,4 +155,90 @@ impl adapter_http_req::Host for ComponentCtx {
155155
}
156156
.into())
157157
}
158+
159+
fn redirect_to_websocket_proxy(
160+
&mut self,
161+
handle: Resource<http_req::Request>,
162+
backend: String,
163+
) -> Result<(), types::Error> {
164+
crate::component::http_req::redirect_to_websocket_proxy(&mut self.session, handle, &backend)
165+
}
166+
167+
fn redirect_to_grip_proxy(
168+
&mut self,
169+
req_handle: Resource<http_req::Request>,
170+
backend_name: String,
171+
) -> Result<(), types::Error> {
172+
crate::component::http_req::redirect_to_grip_proxy(
173+
&mut self.session,
174+
req_handle,
175+
&backend_name,
176+
)
177+
}
178+
179+
fn upgrade_websocket(&mut self, backend: String) -> Result<(), types::Error> {
180+
crate::component::http_req::upgrade_websocket(&mut self.session, &backend)
181+
}
182+
183+
async fn send(
184+
&mut self,
185+
h: Resource<http_req::Request>,
186+
b: Resource<http_body::Body>,
187+
backend_name: String,
188+
) -> Result<http_resp::ResponseWithBody, http_req::ErrorWithDetail> {
189+
crate::component::http_req::send(&mut self.session, h, b, &backend_name).await
190+
}
191+
192+
async fn send_uncached(
193+
&mut self,
194+
h: Resource<http_req::Request>,
195+
b: Resource<http_body::Body>,
196+
backend_name: String,
197+
) -> Result<http_resp::ResponseWithBody, http_req::ErrorWithDetail> {
198+
crate::component::http_req::send_uncached(&mut self.session, h, b, &backend_name).await
199+
}
200+
201+
async fn send_async(
202+
&mut self,
203+
h: Resource<http_req::Request>,
204+
b: Resource<http_body::Body>,
205+
backend_name: String,
206+
) -> Result<Resource<http_req::PendingRequest>, types::Error> {
207+
crate::component::http_req::send_async(&mut self.session, h, b, &backend_name).await
208+
}
209+
210+
async fn send_async_uncached(
211+
&mut self,
212+
h: Resource<http_req::Request>,
213+
b: Resource<http_body::Body>,
214+
backend_name: String,
215+
) -> Result<Resource<http_req::PendingRequest>, types::Error> {
216+
crate::component::http_req::send_async_uncached(&mut self.session, h, b, &backend_name)
217+
.await
218+
}
219+
220+
async fn send_async_uncached_streaming(
221+
&mut self,
222+
h: Resource<http_req::Request>,
223+
b: Resource<http_body::Body>,
224+
backend_name: String,
225+
) -> Result<Resource<http_req::PendingRequest>, types::Error> {
226+
crate::component::http_req::send_async_uncached_streaming(
227+
&mut self.session,
228+
h,
229+
b,
230+
&backend_name,
231+
)
232+
.await
233+
}
234+
235+
async fn send_async_streaming(
236+
&mut self,
237+
h: Resource<http_req::Request>,
238+
b: Resource<http_body::Body>,
239+
backend_name: String,
240+
) -> Result<Resource<http_req::PendingRequest>, types::Error> {
241+
crate::component::http_req::send_async_streaming(&mut self.session, h, b, &backend_name)
242+
.await
243+
}
158244
}

0 commit comments

Comments
 (0)