Skip to content

Commit e38ca0c

Browse files
Update to the latest WITs and adapter.
Changes: - Add more values to `content-encodings`. - Change `tls-version` to a `u16`. - Give `kv-error` an `extra` arm for extensibility. - Bump `fastly:compute` to version number 0.1.0.
1 parent 3091bb6 commit e38ca0c

File tree

7 files changed

+125
-69
lines changed

7 files changed

+125
-69
lines changed

src/component/compute/kv_store.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,9 @@ impl kv_store::HostExtraListOptions for ComponentCtx {
331331
Ok(())
332332
}
333333
}
334+
335+
impl kv_store::HostExtraKvError for ComponentCtx {
336+
fn drop(&mut self, _options: Resource<kv_store::ExtraKvError>) -> wasmtime::Result<()> {
337+
Ok(())
338+
}
339+
}

wasm_abi/adapter/src/fastly/core.rs

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,16 @@ pub mod fastly_http_req {
13281328
}
13291329
}
13301330

1331+
fn encode_tls_version(val: u32) -> Result<http_types::TlsVersion, ()> {
1332+
match val {
1333+
0 => Ok(0x0301), // TLS 1.0
1334+
1 => Ok(0x0302), // TLS 1.1
1335+
2 => Ok(0x0303), // TLS 1.2
1336+
3 => Ok(0x0304), // TLS 1.3
1337+
_ => Err(()),
1338+
}
1339+
}
1340+
13311341
#[export_name = "fastly_http_req#body_downstream_get"]
13321342
pub fn body_downstream_get(
13331343
req_handle_out: *mut RequestHandle,
@@ -2105,11 +2115,11 @@ pub mod fastly_http_req {
21052115
let sni_hostname = make_str!(sni_hostname, sni_hostname_len);
21062116
let client_cert = make_str!(client_certificate, client_certificate_len);
21072117

2108-
let tls_version_min = match unsafe { (*config).ssl_min_version }.try_into() {
2118+
let tls_version_min = match encode_tls_version(unsafe { (*config).ssl_min_version }) {
21092119
Ok(tls_version_min) => tls_version_min,
21102120
Err(_) => return FastlyStatus::INVALID_ARGUMENT,
21112121
};
2112-
let tls_version_max = match unsafe { (*config).ssl_max_version }.try_into() {
2122+
let tls_version_max = match encode_tls_version(unsafe { (*config).ssl_max_version }) {
21132123
Ok(tls_version_max) => tls_version_max,
21142124
Err(_) => return FastlyStatus::INVALID_ARGUMENT,
21152125
};
@@ -3443,7 +3453,7 @@ pub mod fastly_kv_store {
34433453
PayloadTooLarge => Self::PayloadTooLarge,
34443454
InternalError => Self::InternalError,
34453455
TooManyRequests => Self::TooManyRequests,
3446-
GenericError => Self::Uninitialized,
3456+
GenericError | Extra(_) => Self::Uninitialized,
34473457
}
34483458
}
34493459
}
@@ -4010,28 +4020,13 @@ pub mod fastly_backend {
40104020
}
40114021
}
40124022

4013-
impl From<http_types::TlsVersion> for u32 {
4014-
fn from(val: http_types::TlsVersion) -> Self {
4015-
match val {
4016-
http_types::TlsVersion::Tls1 => 0,
4017-
http_types::TlsVersion::Tls11 => 1,
4018-
http_types::TlsVersion::Tls12 => 2,
4019-
http_types::TlsVersion::Tls13 => 3,
4020-
}
4021-
}
4022-
}
4023-
4024-
impl TryFrom<u32> for http_types::TlsVersion {
4025-
type Error = u32;
4026-
4027-
fn try_from(val: u32) -> Result<Self, Self::Error> {
4028-
match val {
4029-
0 => Ok(http_types::TlsVersion::Tls1),
4030-
1 => Ok(http_types::TlsVersion::Tls11),
4031-
2 => Ok(http_types::TlsVersion::Tls12),
4032-
3 => Ok(http_types::TlsVersion::Tls13),
4033-
_ => Err(val),
4034-
}
4023+
fn decode_tls_version(val: http_types::TlsVersion) -> Result<u32, ()> {
4024+
match val {
4025+
0x0301 => Ok(0), // TLS 1.0
4026+
0x0302 => Ok(1), // TLS 1.1
4027+
0x0303 => Ok(2), // TLS 1.2
4028+
0x0304 => Ok(3), // TLS 1.3
4029+
_ => Err(()),
40354030
}
40364031
}
40374032

@@ -4214,12 +4209,15 @@ pub mod fastly_backend {
42144209
) -> FastlyStatus {
42154210
let backend = crate::make_str!(unsafe_main_ptr!(backend_ptr), backend_len);
42164211
match adapter_backend::get_tls_min_version(backend) {
4217-
Ok(Some(res)) => {
4218-
unsafe {
4219-
*main_ptr!(value) = u32::from(res);
4212+
Ok(Some(res)) => match decode_tls_version(res) {
4213+
Ok(decoded) => {
4214+
unsafe {
4215+
*main_ptr!(value) = decoded;
4216+
}
4217+
FastlyStatus::OK
42204218
}
4221-
FastlyStatus::OK
4222-
}
4219+
Err(()) => FastlyStatus::UNSUPPORTED,
4220+
},
42234221
Ok(None) => FastlyStatus::NONE,
42244222
Err(e) => e.into(),
42254223
}
@@ -4233,12 +4231,15 @@ pub mod fastly_backend {
42334231
) -> FastlyStatus {
42344232
let backend = crate::make_str!(unsafe_main_ptr!(backend_ptr), backend_len);
42354233
match adapter_backend::get_tls_max_version(backend) {
4236-
Ok(Some(res)) => {
4237-
unsafe {
4238-
*main_ptr!(value) = u32::from(res);
4234+
Ok(Some(res)) => match decode_tls_version(res) {
4235+
Ok(decoded) => {
4236+
unsafe {
4237+
*main_ptr!(value) = decoded;
4238+
}
4239+
FastlyStatus::OK
42394240
}
4240-
FastlyStatus::OK
4241-
}
4241+
Err(()) => FastlyStatus::UNSUPPORTED,
4242+
},
42424243
Ok(None) => FastlyStatus::NONE,
42434244
Err(e) => e.into(),
42444245
}
@@ -4828,7 +4829,7 @@ mod fastly_image_optimizer {
48284829
/// allocation to convert a `&[Resource]` to a `&[u32]`.
48294830
fn select_wrapper(hs: &[u32]) -> u32 {
48304831
unsafe {
4831-
#[link(wasm_import_module = "fastly:compute/async-io@0.0.0-prerelease.1")]
4832+
#[link(wasm_import_module = "fastly:compute/async-io@0.1.0")]
48324833
extern "C" {
48334834
#[link_name = "select"]
48344835
fn wit_import(_: *const u32, _: usize) -> u32;
@@ -4847,7 +4848,7 @@ fn select_with_timeout_wrapper(hs: &[u32], timeout_ms: u32) -> Option<u32> {
48474848
struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
48484849
let mut ret_area = RetArea([::core::mem::MaybeUninit::uninit(); 8]);
48494850
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
4850-
#[link(wasm_import_module = "fastly:compute/async-io@0.0.0-prerelease.1")]
4851+
#[link(wasm_import_module = "fastly:compute/async-io@0.1.0")]
48514852
extern "C" {
48524853
#[link_name = "select-with-timeout"]
48534854
fn wit_import(_: *const u32, _: usize, _: u32, _: *mut u8);

wasm_abi/adapter/src/fastly/error.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ impl From<crate::bindings::fastly::compute::kv_store::KvError> for FastlyStatus
7373
KvError::BadRequest | KvError::PreconditionFailed | KvError::PayloadTooLarge => {
7474
std::hint::black_box(FastlyStatus::INVALID_ARGUMENT)
7575
}
76-
KvError::GenericError | KvError::InternalError => FastlyStatus::UNKNOWN_ERROR,
76+
KvError::GenericError | KvError::InternalError | KvError::Extra(_) => {
77+
FastlyStatus::UNKNOWN_ERROR
78+
}
7779
KvError::TooManyRequests => FastlyStatus::LIMITEXCEEDED,
7880
}
7981
}

wasm_abi/adapter/src/fastly/http_cache.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ mod http_cache {
150150
STALE_WHILE_REVALIDATE_NS,
151151
(*options).stale_while_revalidate_ns
152152
),
153+
stale_if_error_ns: None,
153154
surrogate_keys,
154155
length: when_enabled!(LENGTH, (*options).length),
155156
sensitive_data: mask.contains(HttpCacheWriteOptionsMask::SENSITIVE_DATA),
-1.72 KB
Binary file not shown.

wasm_abi/wit/deps/fastly-adapter/adapter.wit

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ interface adapter-abi {
1313
/// `http-downstream` interface which do the same thing but take an explicit
1414
/// `request` handle.
1515
interface adapter-http-req {
16-
use fastly:compute/types@0.0.0-prerelease.1.{error, ip-address};
17-
use fastly:compute/http-req@0.0.0-prerelease.1.{
16+
use fastly:compute/types@0.1.0.{error, ip-address};
17+
use fastly:compute/http-req@0.1.0.{
1818
client-cert-verify-result, request, body, response-with-body, error-with-detail,
1919
pending-response
2020
};
@@ -119,7 +119,7 @@ interface adapter-http-req {
119119

120120
/// Deprecated; these functions take `backend` as a string.
121121
interface adapter-backend {
122-
use fastly:compute/backend@0.0.0-prerelease.1.{
122+
use fastly:compute/backend@0.1.0.{
123123
backend-health, error, timeout-ms, tls-version, timeout-secs, probe-count,
124124
dynamic-backend-options,
125125
};
@@ -164,7 +164,7 @@ interface adapter-backend {
164164

165165
/// Deprecated functions formerly of `fastly:compute/image-optimizer`.
166166
interface adapter-image-optimizer {
167-
use fastly:compute/image-optimizer@0.0.0-prerelease.1.{
167+
use fastly:compute/image-optimizer@0.1.0.{
168168
body, request, image-optimizer-transform-options, response-with-body, error
169169
};
170170

@@ -178,8 +178,8 @@ interface adapter-image-optimizer {
178178
}
179179

180180
interface adapter-http-downstream {
181-
use fastly:compute/types@0.0.0-prerelease.1.{error};
182-
use fastly:compute/http-req@0.0.0-prerelease.1.{request};
181+
use fastly:compute/types@0.1.0.{error};
182+
use fastly:compute/http-req@0.1.0.{request};
183183

184184
/// Deprecated, because it doesn't return `none` on an empty certificate.
185185
downstream-tls-raw-client-certificate-deprecated: func(
@@ -190,9 +190,9 @@ interface adapter-http-downstream {
190190

191191
/// Deprecated functions formerly of `fastly:compute/http-cache`.
192192
interface adapter-http-cache {
193-
use fastly:compute/types@0.0.0-prerelease.1.{error};
194-
use fastly:compute/http-req@0.0.0-prerelease.1.{request};
195-
use fastly:compute/http-cache@0.0.0-prerelease.1.{entry};
193+
use fastly:compute/types@0.1.0.{error};
194+
use fastly:compute/http-req@0.1.0.{request};
195+
use fastly:compute/http-cache@0.1.0.{entry};
196196

197197
/// Deprecated; use `transaction-lookup` instead.
198198
lookup: func(
@@ -217,8 +217,8 @@ interface adapter-http-cache {
217217

218218
/// Adapter Core Cache functions.
219219
interface adapter-cache {
220-
use fastly:compute/types@0.0.0-prerelease.1.{error};
221-
use fastly:compute/cache@0.0.0-prerelease.1.{
220+
use fastly:compute/types@0.1.0.{error};
221+
use fastly:compute/cache@0.1.0.{
222222
extra-lookup-options, extra-write-options, extra-replace-options
223223
};
224224

@@ -243,7 +243,7 @@ interface adapter-cache {
243243

244244
/// User-agent string parsing (deprecated).
245245
interface adapter-uap {
246-
use fastly:compute/types@0.0.0-prerelease.1.{error};
246+
use fastly:compute/types@0.1.0.{error};
247247

248248
resource user-agent {
249249
family: func(max-len: u64) -> result<string, error>;
@@ -258,7 +258,7 @@ interface adapter-uap {
258258

259259
/// Deprecated functions formerly of `fastly:compute/erl`.
260260
interface adapter-erl {
261-
use fastly:compute/types@0.0.0-prerelease.1.{error};
261+
use fastly:compute/types@0.1.0.{error};
262262

263263
check-rate: func(
264264
rate-counter: string,
@@ -302,8 +302,8 @@ interface adapter-erl {
302302

303303
/// Deprecated functions formerly of `fastly:compute/shielding`.
304304
interface adapter-shielding {
305-
use fastly:compute/types@0.0.0-prerelease.1.{error};
306-
use fastly:compute/shielding@0.0.0-prerelease.1.{shield-backend-options};
305+
use fastly:compute/types@0.1.0.{error};
306+
use fastly:compute/shielding@0.1.0.{shield-backend-options};
307307

308308
/// Deprecated; this function returns the backend as a `string`.
309309
backend-for-shield: func(
@@ -331,7 +331,7 @@ world adapter-imports {
331331
/// The `fastly:compute/service` world plus the deprecated interfaces.
332332
world adapter-service {
333333
// Make this world a superset of the public `service` world.
334-
include fastly:compute/service@0.0.0-prerelease.1;
334+
include fastly:compute/service@0.1.0;
335335

336336
// And, add all the deprecated interfaces.
337337
include adapter-imports;
@@ -341,6 +341,6 @@ world adapter-service {
341341
/// exports (`http-incoming.handle`), so that it can be used by library components
342342
/// that don't have their own `main` function.
343343
world adapter-service-imports {
344-
include fastly:compute/service-imports@0.0.0-prerelease.1;
344+
include fastly:compute/service-imports@0.1.0;
345345
include adapter-imports;
346346
}

0 commit comments

Comments
 (0)