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

Update Fastly crate from 0.10.4 to 0.11.1 #445

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
58 changes: 58 additions & 0 deletions crates/adapter/src/fastly/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,42 @@ pub mod fastly_http_req {
}
}

#[export_name = "fastly_http_req#send_v3"]
pub fn send_v3(
req_handle: RequestHandle,
body_handle: BodyHandle,
backend: *const u8,
backend_len: usize,
error_detail: *mut SendErrorDetail,
resp_handle_out: *mut ResponseHandle,
resp_body_handle_out: *mut BodyHandle,
) -> FastlyStatus {
let backend = unsafe { slice::from_raw_parts(backend, backend_len) };
match fastly::api::http_req::send_v3(req_handle, body_handle, backend) {
Ok((resp_handle, resp_body_handle)) => {
unsafe {
*error_detail = http_req::SendErrorDetailTag::Ok.into();
*resp_handle_out = resp_handle;
*resp_body_handle_out = resp_body_handle;
}

FastlyStatus::OK
}
Err(err) => {
unsafe {
*error_detail = err
.detail
.unwrap_or_else(|| http_req::SendErrorDetailTag::Uninitialized.into())
.into();
*resp_handle_out = INVALID_HANDLE;
*resp_body_handle_out = INVALID_HANDLE;
}

err.error.into()
}
}
}

#[export_name = "fastly_http_req#send_async"]
pub fn send_async(
req_handle: RequestHandle,
Expand All @@ -1503,6 +1539,28 @@ pub mod fastly_http_req {
}
}

#[export_name = "fastly_http_req#send_async_v2"]
pub fn send_async_v2(
req_handle: RequestHandle,
body_handle: BodyHandle,
backend: *const u8,
backend_len: usize,
pending_req_handle_out: *mut PendingRequestHandle,
streaming: bool,
) -> FastlyStatus {
let backend = unsafe { slice::from_raw_parts(backend, backend_len) };
match http_req::send_async_v2(req_handle, body_handle, backend, streaming) {
Ok(res) => {
unsafe {
*pending_req_handle_out = res;
}

FastlyStatus::OK
}
Err(e) => e.into(),
}
}

#[export_name = "fastly_http_req#send_async_streaming"]
pub fn send_async_streaming(
req_handle: RequestHandle,
Expand Down
1 change: 1 addition & 0 deletions crates/adapter/src/fastly/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ impl FastlyStatus {
pub const OK: Self = FastlyStatus(0);
pub const UNKNOWN_ERROR: Self = FastlyStatus(1);
pub const INVALID_ARGUMENT: Self = Self(2);
pub const UNSUPPORTED: Self = Self(5);
pub const NONE: Self = FastlyStatus(10);
}

Expand Down
273 changes: 273 additions & 0 deletions crates/adapter/src/fastly/http_cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
use super::{
BodyHandle, CacheDurationNs, CacheHitCount, CacheLookupState, CacheObjectLength, FastlyStatus,
RequestHandle, ResponseHandle,
};

pub type HttpCacheHandle = u32;
pub type IsCacheable = u32;
pub type IsSensitive = u32;

#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[allow(unused)]
pub enum HttpStorageAction {
Insert,
Update,
DoNotStore,
RecordUncacheable,
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct HttpCacheLookupOptions {
pub override_key_ptr: *const u8,
pub override_key_len: usize,
}

bitflags::bitflags! {
#[repr(transparent)]
pub struct HttpCacheLookupOptionsMask: u32 {
const _RESERVED = 1 << 0;
const OVERRIDE_KEY = 1 << 1;
}
}

#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct HttpCacheWriteOptions {
pub max_age_ns: CacheDurationNs,
pub vary_rule_ptr: *const u8,
pub vary_rule_len: usize,
pub initial_age_ns: CacheDurationNs,
pub stale_while_revalidate_ns: CacheDurationNs,
pub surrogate_keys_ptr: *const u8,
pub surrogate_keys_len: usize,
pub length: CacheObjectLength,
}

bitflags::bitflags! {
#[repr(transparent)]
pub struct HttpCacheWriteOptionsMask: u32 {
const _RESERVED = 1 << 0;
const VARY_RULE = 1 << 1;
const INITIAL_AGE_NS = 1 << 2;
const STALE_WHILE_REVALIDATE_NS = 1 << 3;
const SURROGATE_KEYS = 1 << 4;
const LENGTH = 1 << 5;
const SENSITIVE_DATA = 1 << 6;
}
}

#[allow(unused_variables)]
#[allow(clippy::module_inception)]
mod http_cache {
use super::*;

#[export_name = "fastly_http_cache#is_request_cacheable"]
pub fn is_request_cacheable(
req_handle: RequestHandle,
is_cacheable_out: *mut IsCacheable,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_suggested_cache_key"]
pub fn get_suggested_cache_key(
req_handle: RequestHandle,
key_out_ptr: *mut u8,
key_out_len: usize,
nwritten_out: *mut usize,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#lookup"]
pub fn lookup(
req_handle: RequestHandle,
options_mask: HttpCacheLookupOptionsMask,
options: *const HttpCacheLookupOptions,
cache_handle_out: *mut HttpCacheHandle,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#transaction_lookup"]
pub fn transaction_lookup(
req_handle: RequestHandle,
options_mask: HttpCacheLookupOptionsMask,
options: *const HttpCacheLookupOptions,
cache_handle_out: *mut HttpCacheHandle,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#transaction_insert"]
pub fn transaction_insert(
handle: HttpCacheHandle,
resp_handle: ResponseHandle,
options_mask: HttpCacheWriteOptionsMask,
options: *const HttpCacheWriteOptions,
body_handle_out: *mut BodyHandle,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#transaction_insert_and_stream_back"]
pub fn transaction_insert_and_stream_back(
handle: HttpCacheHandle,
resp_handle: ResponseHandle,
options_mask: HttpCacheWriteOptionsMask,
options: *const HttpCacheWriteOptions,
body_handle_out: *mut BodyHandle,
cache_handle_out: *mut HttpCacheHandle,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#transaction_update"]
pub fn transaction_update(
handle: HttpCacheHandle,
resp_handle: ResponseHandle,
options_mask: HttpCacheWriteOptionsMask,
options: *const HttpCacheWriteOptions,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#transaction_update_and_return_fresh"]
pub fn transaction_update_and_return_fresh(
handle: HttpCacheHandle,
resp_handle: ResponseHandle,
options_mask: HttpCacheWriteOptionsMask,
options: *const HttpCacheWriteOptions,
cache_handle_out: *mut HttpCacheHandle,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#transaction_record_not_cacheable"]
pub fn transaction_record_not_cacheable(
handle: HttpCacheHandle,
options_mask: HttpCacheWriteOptionsMask,
options: *const HttpCacheWriteOptions,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#transaction_abandon"]
pub fn transaction_abandon(handle: HttpCacheHandle) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#close"]
pub fn close(handle: HttpCacheHandle) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_suggested_backend_request"]
pub fn get_suggested_backend_request(
handle: HttpCacheHandle,
req_handle_out: *mut RequestHandle,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_suggested_cache_options"]
pub fn get_suggested_cache_options(
handle: HttpCacheHandle,
resp_handle: ResponseHandle,
requested: HttpCacheWriteOptionsMask,
options: *const HttpCacheWriteOptions,
options_mask_out: *mut HttpCacheWriteOptionsMask,
options_out: *mut HttpCacheWriteOptions,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#prepare_response_for_storage"]
pub fn prepare_response_for_storage(
handle: HttpCacheHandle,
resp_handle: ResponseHandle,
http_storage_action_out: *mut HttpStorageAction,
resp_handle_out: *mut ResponseHandle,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_found_response"]
pub fn get_found_response(
handle: HttpCacheHandle,
transform_for_client: u32,
resp_handle_out: *mut ResponseHandle,
body_handle_out: *mut BodyHandle,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_state"]
pub fn get_state(
handle: HttpCacheHandle,
cache_lookup_state_out: *mut CacheLookupState,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_length"]
pub fn get_length(handle: HttpCacheHandle, length_out: *mut CacheObjectLength) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_max_age_ns"]
pub fn get_max_age_ns(
handle: HttpCacheHandle,
duration_out: *mut CacheDurationNs,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_stale_while_revalidate_ns"]
pub fn get_stale_while_revalidate_ns(
handle: HttpCacheHandle,
duration_out: *mut CacheDurationNs,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_age_ns"]
pub fn get_age_ns(handle: HttpCacheHandle, duration_out: *mut CacheDurationNs) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_hits"]
pub fn get_hits(handle: HttpCacheHandle, hits_out: *mut CacheHitCount) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_sensitive_data"]
pub fn get_sensitive_data(
handle: HttpCacheHandle,
sensitive_data_out: *mut IsSensitive,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_surrogate_keys"]
pub fn get_surrogate_keys(
handle: HttpCacheHandle,
surrogate_keys_out_ptr: *mut u8,
surrogate_keys_out_len: usize,
nwritten_out: *mut usize,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}

#[export_name = "fastly_http_cache#get_vary_rule"]
pub fn get_vary_rule(
handle: HttpCacheHandle,
vary_rule_out_ptr: *mut u8,
vary_rule_out_len: usize,
nwritten_out: *mut usize,
) -> FastlyStatus {
FastlyStatus::UNSUPPORTED
}
}
2 changes: 2 additions & 0 deletions crates/adapter/src/fastly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ mod cache;
mod config_store;
mod core;
mod error;
mod http_cache;
mod macros;

pub(crate) use error::*;

pub use cache::*;
pub use config_store::*;
pub use core::*;
pub use http_cache::*;
Binary file modified lib/data/viceroy-component-adapter.wasm
Binary file not shown.
Loading
Loading