diff --git a/crates/adapter/src/fastly/core.rs b/crates/adapter/src/fastly/core.rs index 493d3cc0..e613905e 100644 --- a/crates/adapter/src/fastly/core.rs +++ b/crates/adapter/src/fastly/core.rs @@ -995,9 +995,7 @@ pub mod fastly_http_req { nwritten: *mut usize, ) -> FastlyStatus { alloc_result!(region_out, region_max_len, nwritten, { - fastly::api::http_req::downstream_compliance_region( - u64::try_from(region_max_len).trapping_unwrap(), - ) + fastly::api::http_req::downstream_compliance_region() }) } diff --git a/lib/compute-at-edge-abi/compute-at-edge.witx b/lib/compute-at-edge-abi/compute-at-edge.witx index 3306aac3..5aa0731d 100644 --- a/lib/compute-at-edge-abi/compute-at-edge.witx +++ b/lib/compute-at-edge-abi/compute-at-edge.witx @@ -242,7 +242,14 @@ (param $ja4_max_len (@witx usize)) (param $nwritten_out (@witx pointer (@witx usize))) (result $err (expected (error $fastly_status))) - ) + ) + + (@interface func (export "downstream_compliance_region") + (param $region_out (@witx pointer (@witx char8))) + (param $region_max_len (@witx usize)) + (param $nwritten_out (@witx pointer (@witx usize))) + (result $err (expected (error $fastly_status))) + ) (@interface func (export "new") (result $err (expected $request_handle (error $fastly_status))) diff --git a/lib/src/component/http_req.rs b/lib/src/component/http_req.rs index 9e64fa47..902e9fd9 100644 --- a/lib/src/component/http_req.rs +++ b/lib/src/component/http_req.rs @@ -808,11 +808,8 @@ impl http_req::Host for Session { Err(Error::NotAvailable("Client TLS JA4 hash").into()) } - async fn downstream_compliance_region( - &mut self, - _max_len: u64, - ) -> Result, types::Error> { - Err(Error::NotAvailable("Client TLS JA4 hash").into()) + async fn downstream_compliance_region(&mut self) -> Result, types::Error> { + Ok(Vec::from(b"none")) } async fn original_header_names_get( diff --git a/lib/src/wiggle_abi/req_impl.rs b/lib/src/wiggle_abi/req_impl.rs index 8af66e2e..954923bc 100644 --- a/lib/src/wiggle_abi/req_impl.rs +++ b/lib/src/wiggle_abi/req_impl.rs @@ -300,6 +300,33 @@ impl FastlyHttpReq for Session { Err(Error::NotAvailable("Client TLS JA4 hash")) } + fn downstream_compliance_region( + &mut self, + memory: &mut GuestMemory<'_>, + // Must be a 16-byte array: + region_out: GuestPtr, + region_max_len: u32, + nwritten_out: GuestPtr, + ) -> Result<(), Error> { + const REGION_NONE: &[u8] = b"none"; + const REGION_NONE_LEN: u32 = 4; + + if region_max_len < REGION_NONE_LEN { + // Let the guest know how much we want to write. + memory.write(nwritten_out, REGION_NONE_LEN)?; + + return Err(Error::BufferLengthError { + buf: "region_out", + len: "region_max_len", + }); + } + + memory.copy_from_slice(REGION_NONE, region_out.as_array(region_max_len))?; + memory.write(nwritten_out, REGION_NONE_LEN)?; + + Ok(()) + } + fn framing_headers_mode_set( &mut self, _memory: &mut GuestMemory<'_>, diff --git a/lib/wit/deps/fastly/compute.wit b/lib/wit/deps/fastly/compute.wit index a7dcb7ce..d52a8be3 100644 --- a/lib/wit/deps/fastly/compute.wit +++ b/lib/wit/deps/fastly/compute.wit @@ -323,7 +323,7 @@ interface http-req { downstream-tls-ja4: func(max-len: u64) -> result, error>; - downstream-compliance-region: func(max-len: u64) -> result, error>; + downstream-compliance-region: func() -> result, error>; new: func() -> result;