Skip to content

Commit 0eb3681

Browse files
Merge pull request #534 from fastly/dgohman-fastly/update
Update to the latest WITs and adapter.
2 parents 25f6df9 + 194775d commit 0eb3681

File tree

19 files changed

+605
-319
lines changed

19 files changed

+605
-319
lines changed

src/component.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,24 @@ pub(crate) mod bindings {
1010
imports: {
1111
default: tracing,
1212

13-
"fastly:compute/backend/[constructor]dynamic-backend-options": trappable,
13+
"fastly:compute/backend/[constructor]dynamic-backend-options": tracing | trappable,
14+
"fastly:compute/shielding/[constructor]shield-backend-options": tracing | trappable,
15+
"fastly:compute/cache/[constructor]extra-lookup-options": tracing | trappable,
16+
"fastly:compute/cache/[constructor]extra-replace-options": tracing | trappable,
17+
"fastly:compute/cache/[constructor]extra-write-options": tracing | trappable,
1418

1519
// The trap-test test depends on being able to induce an artificial
1620
// trap in `get-header-values`.
17-
"fastly:compute/http-resp/[method]response.get-header-values": trappable,
21+
"fastly:compute/http-resp/[method]response.get-header-values": tracing | trappable,
1822

1923
"fastly:compute/http-body/append": async | tracing,
2024
"fastly:compute/kv-store/await-delete": async | tracing,
2125
"fastly:compute/cache/await-entry": async | tracing,
2226
"fastly:compute/kv-store/await-insert": async | tracing,
2327
"fastly:compute/kv-store/await-list": async | tracing,
2428
"fastly:compute/kv-store/await-lookup": async | tracing | trappable,
25-
"fastly:compute/http-downstream/await-next-request": async | tracing,
26-
"fastly:compute/http-req/await-request": async | tracing,
29+
"fastly:compute/http-downstream/await-request": async | tracing,
30+
"fastly:compute/http-req/await-response": async | tracing,
2731
"fastly:compute/cache/close-entry": async | tracing,
2832
"fastly:compute/cache/insert": async | tracing,
2933
"fastly:compute/cache/replace": async | tracing,

src/component/adapter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Implementations for `fastly:adapter` interfaces.
22
3+
pub mod cache;
34
pub mod http_cache;
45
pub mod http_downstream;
56
pub mod http_req;

src/component/adapter/cache.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use crate::component::bindings::fastly::adapter::adapter_cache;
2+
use crate::component::bindings::fastly::compute::{cache, types};
3+
use crate::linking::ComponentCtx;
4+
use crate::Error;
5+
use wasmtime::component::Resource;
6+
7+
impl adapter_cache::Host for ComponentCtx {
8+
fn set_lookup_service_id_deprecated(
9+
&mut self,
10+
_options: Resource<cache::ExtraLookupOptions>,
11+
_service_id: String,
12+
) -> Result<(), types::Error> {
13+
Err(Error::Unsupported {
14+
msg: "adapter-cache.set-lookup-service-id-deprecated is not supported on Viceroy.",
15+
}
16+
.into())
17+
}
18+
19+
fn set_write_service_id_deprecated(
20+
&mut self,
21+
_options: Resource<cache::ExtraWriteOptions>,
22+
_service_id: String,
23+
) -> Result<(), types::Error> {
24+
Err(Error::Unsupported {
25+
msg: "adapter-cache.set-write-service-id-deprecated is not supported on Viceroy.",
26+
}
27+
.into())
28+
}
29+
30+
fn set_replace_service_id_deprecated(
31+
&mut self,
32+
_options: Resource<cache::ExtraReplaceOptions>,
33+
_service_id: String,
34+
) -> Result<(), types::Error> {
35+
Err(Error::Unsupported {
36+
msg: "adapter-cache.set-replace-service-id-deprecated is not supported on Viceroy.",
37+
}
38+
.into())
39+
}
40+
}

src/component/adapter/http_req.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,4 +144,15 @@ impl adapter_http_req::Host for ComponentCtx {
144144
fn downstream_tls_ja3_md5(&mut self) -> Result<Option<Vec<u8>>, types::Error> {
145145
HttpDownstream::downstream_tls_ja3_md5(self, self.ds_req_handle())
146146
}
147+
148+
fn on_behalf_of_deprecated(
149+
&mut self,
150+
_: Resource<http_req::Request>,
151+
_: String,
152+
) -> Result<(), types::Error> {
153+
Err(Error::Unsupported {
154+
msg: "http-req.on-behalf-of is not supported in Viceroy",
155+
}
156+
.into())
157+
}
147158
}

src/component/compute/cache.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ fn load_write_options(options: &api::WriteOptions) -> Result<WriteOptions, Error
5757
let length = options.length;
5858
let sensitive_data = options.sensitive_data;
5959

60-
// SERVICE_ID differences are observable- but we don't implement that behavior. Error explicitly.
61-
if options.service_id.is_some() {
62-
return Err(Error::Unsupported {
63-
msg: "cache on_behalf_of is not supported in Viceroy",
64-
});
65-
}
66-
6760
let edge_max_age = if let Some(edge_max_age_ns) = options.edge_max_age_ns {
6861
Duration::from_nanos(edge_max_age_ns)
6962
} else {
@@ -588,6 +581,10 @@ impl api::HostEntry for ComponentCtx {
588581
}
589582

590583
impl api::HostExtraReplaceOptions for ComponentCtx {
584+
fn new(&mut self) -> wasmtime::Result<Resource<api::ExtraReplaceOptions>> {
585+
Ok(Resource::<api::ExtraReplaceOptions>::new_own(0))
586+
}
587+
591588
fn drop(&mut self, _options: Resource<api::ExtraReplaceOptions>) -> wasmtime::Result<()> {
592589
Ok(())
593590
}
@@ -600,12 +597,20 @@ impl api::HostExtraGetBodyOptions for ComponentCtx {
600597
}
601598

602599
impl api::HostExtraWriteOptions for ComponentCtx {
600+
fn new(&mut self) -> wasmtime::Result<Resource<api::ExtraWriteOptions>> {
601+
Ok(Resource::<api::ExtraWriteOptions>::new_own(0))
602+
}
603+
603604
fn drop(&mut self, _options: Resource<api::ExtraWriteOptions>) -> wasmtime::Result<()> {
604605
Ok(())
605606
}
606607
}
607608

608609
impl api::HostExtraLookupOptions for ComponentCtx {
610+
fn new(&mut self) -> wasmtime::Result<Resource<api::ExtraLookupOptions>> {
611+
Ok(Resource::<api::ExtraLookupOptions>::new_own(0))
612+
}
613+
609614
fn drop(&mut self, _options: Resource<api::ExtraLookupOptions>) -> wasmtime::Result<()> {
610615
Ok(())
611616
}

src/component/compute/http_body.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl http_body::Host for ComponentCtx {
162162
h: Resource<http_body::Body>,
163163
max_len: u64,
164164
cursor: u32,
165-
) -> Result<(String, Option<u32>), types::Error> {
165+
) -> Result<(String, Option<u32>), http_body::TrailerError> {
166166
let h = h.into();
167167

168168
// Read operations are not allowed on streaming bodies.
@@ -172,7 +172,7 @@ impl http_body::Host for ComponentCtx {
172172

173173
let body = self.session_mut().body_mut(h)?;
174174
if !body.trailers_ready {
175-
return Err(Error::Again.into());
175+
return Err(http_body::TrailerError::NotAvailableYet);
176176
}
177177

178178
let trailers = &body.trailers;
@@ -186,7 +186,7 @@ impl http_body::Host for ComponentCtx {
186186
h: Resource<http_body::Body>,
187187
name: String,
188188
max_len: u64,
189-
) -> Result<Option<Vec<u8>>, types::Error> {
189+
) -> Result<Option<Vec<u8>>, http_body::TrailerError> {
190190
let h = h.into();
191191

192192
// Read operations are not allowed on streaming bodies.
@@ -196,7 +196,7 @@ impl http_body::Host for ComponentCtx {
196196

197197
let body = self.session_mut().body_mut(h)?;
198198
if !body.trailers_ready {
199-
return Err(Error::Again.into());
199+
return Err(http_body::TrailerError::NotAvailableYet);
200200
}
201201

202202
let trailers = &mut body.trailers;
@@ -230,17 +230,17 @@ impl http_body::Host for ComponentCtx {
230230
name: String,
231231
max_len: u64,
232232
cursor: u32,
233-
) -> Result<(Vec<u8>, Option<u32>), types::Error> {
233+
) -> Result<(Vec<u8>, Option<u32>), http_body::TrailerError> {
234234
let h = h.into();
235235

236236
// Read operations are not allowed on streaming bodies.
237237
if self.session().is_streaming_body(h) {
238238
return Err(Error::InvalidArgument.into());
239239
}
240240

241-
let body = self.session_mut().body_mut(h)?;
241+
let body = self.session_mut().body_mut(h).unwrap();
242242
if !body.trailers_ready {
243-
return Err(Error::Again.into());
243+
return Err(http_body::TrailerError::NotAvailableYet);
244244
}
245245

246246
let trailers = &mut body.trailers;
@@ -249,3 +249,9 @@ impl http_body::Host for ComponentCtx {
249249
Ok((buf, next))
250250
}
251251
}
252+
253+
impl<T: Into<types::Error>> From<T> for http_body::TrailerError {
254+
fn from(err: T) -> Self {
255+
Self::Error(err.into())
256+
}
257+
}

src/component/compute/http_downstream.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl http_downstream::Host for ComponentCtx {
1212
async fn next_request(
1313
&mut self,
1414
options: http_downstream::NextRequestOptions,
15-
) -> Result<Resource<http_downstream::RequestPromise>, types::Error> {
15+
) -> Result<Resource<http_downstream::PendingRequest>, types::Error> {
1616
let timeout = options.timeout_ms.map(Duration::from_millis);
1717
let handle = self
1818
.session_mut()
@@ -26,16 +26,16 @@ impl http_downstream::Host for ComponentCtx {
2626

2727
fn next_request_abandon(
2828
&mut self,
29-
handle: Resource<http_downstream::RequestPromise>,
29+
handle: Resource<http_downstream::PendingRequest>,
3030
) -> Result<(), types::Error> {
3131
let handle = RequestPromiseHandle::from(handle).into();
3232
self.session_mut().abandon_pending_downstream_req(handle)?;
3333
Ok(())
3434
}
3535

36-
async fn await_next_request(
36+
async fn await_request(
3737
&mut self,
38-
handle: Resource<http_downstream::RequestPromise>,
38+
handle: Resource<http_downstream::PendingRequest>,
3939
) -> Result<Option<(Resource<http_req::Request>, Resource<http_body::Body>)>, types::Error>
4040
{
4141
let handle = RequestPromiseHandle::from(handle).into();

src/component/compute/http_req.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ impl http_req::Host for ComponentCtx {
148148
Ok(self.session.insert_pending_request(task).into())
149149
}
150150

151-
async fn await_request(
151+
async fn await_response(
152152
&mut self,
153153
h: Resource<http_req::PendingRequest>,
154154
) -> Result<http_resp::ResponseWithBody, http_req::ErrorWithDetail> {
@@ -474,17 +474,6 @@ impl http_req::HostRequest for ComponentCtx {
474474
Ok(())
475475
}
476476

477-
fn on_behalf_of(
478-
&mut self,
479-
_: Resource<http_req::Request>,
480-
_: String,
481-
) -> Result<(), types::Error> {
482-
Err(Error::Unsupported {
483-
msg: "http-req.on-behalf-of is not supported in Viceroy",
484-
}
485-
.into())
486-
}
487-
488477
fn drop(&mut self, _request: Resource<http_req::Request>) -> wasmtime::Result<()> {
489478
Ok(())
490479
}

src/component/compute/secret_store.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl secret_store::HostSecret for ComponentCtx {
4646
&mut self,
4747
secret: Resource<secret_store::Secret>,
4848
max_len: u64,
49-
) -> Result<Option<Vec<u8>>, types::Error> {
49+
) -> Result<Vec<u8>, types::Error> {
5050
let secret = secret.into();
5151
let lookup = self
5252
.session()
@@ -83,7 +83,7 @@ impl secret_store::HostSecret for ComponentCtx {
8383
.into());
8484
}
8585

86-
Ok(Some(plaintext.to_owned()))
86+
Ok(plaintext.to_owned())
8787
}
8888

8989
fn from_bytes(

src/component/compute/shielding.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl shielding::Host for ComponentCtx {
5050
fn backend_for_shield(
5151
&mut self,
5252
name: String,
53-
_options: shielding::ShieldBackendOptions,
53+
_options: Option<Resource<shielding::ShieldBackendOptions>>,
5454
max_len: u64,
5555
) -> Result<String, types::Error> {
5656
let shield_uri = name;
@@ -88,10 +88,31 @@ impl shielding::Host for ComponentCtx {
8888
}
8989
}
9090

91-
impl shielding::HostExtraShieldBackendOptions for ComponentCtx {
91+
impl shielding::HostShieldBackendOptions for ComponentCtx {
92+
fn set_first_byte_timeout(
93+
&mut self,
94+
_resource: Resource<shielding::ShieldBackendOptions>,
95+
_timeout_ms: u32,
96+
) {
97+
}
98+
99+
fn set_cache_key(
100+
&mut self,
101+
_resource: Resource<shielding::ShieldBackendOptions>,
102+
_cache_key: String,
103+
) {
104+
}
105+
106+
fn new(&mut self) -> Result<Resource<shielding::ShieldBackendOptions>, anyhow::Error> {
107+
Err(Error::Unsupported {
108+
msg: "Shield backend options not yet supported in Viceroy",
109+
}
110+
.into())
111+
}
112+
92113
fn drop(
93114
&mut self,
94-
_options: Resource<shielding::ExtraShieldBackendOptions>,
115+
_options: Resource<shielding::ShieldBackendOptions>,
95116
) -> wasmtime::Result<()> {
96117
Ok(())
97118
}

0 commit comments

Comments
 (0)