Skip to content

Commit

Permalink
Add downstream_compliance_region hostcall
Browse files Browse the repository at this point in the history
  • Loading branch information
ulyssa committed Jul 26, 2024
1 parent 0596f51 commit 9ab65ba
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
4 changes: 1 addition & 3 deletions crates/adapter/src/fastly/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
}

Expand Down
9 changes: 8 additions & 1 deletion lib/compute-at-edge-abi/compute-at-edge.witx
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
7 changes: 2 additions & 5 deletions lib/src/component/http_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<u8>, types::Error> {
Err(Error::NotAvailable("Client TLS JA4 hash").into())
async fn downstream_compliance_region(&mut self) -> Result<Vec<u8>, types::Error> {
Ok(Vec::from(b"none"))
}

async fn original_header_names_get(
Expand Down
27 changes: 27 additions & 0 deletions lib/src/wiggle_abi/req_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u8>,
region_max_len: u32,
nwritten_out: GuestPtr<u32>,
) -> 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<'_>,
Expand Down
2 changes: 1 addition & 1 deletion lib/wit/deps/fastly/compute.wit
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ interface http-req {

downstream-tls-ja4: func(max-len: u64) -> result<list<u8>, error>;

downstream-compliance-region: func(max-len: u64) -> result<list<u8>, error>;
downstream-compliance-region: func() -> result<list<u8>, error>;

new: func() -> result<request-handle, error>;

Expand Down

0 comments on commit 9ab65ba

Please sign in to comment.