Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add downstream_compliance_region hostcall #403

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also add a check here that max_len >= 4?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 656a5a9.

}

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>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add max-len back in? It's to help with the adapter, as it's ensuring that the returned vector that will be placed in the guest-provided buffer will be large enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 656a5a9.


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

Expand Down
Loading