fastly-sys 0.12.0

Fastly Compute ABI Bindings
Documentation
use crate::{
    fastly_cache::{CacheDurationNs, CacheHitCount, CacheLookupState, CacheObjectLength},
    BodyHandle, RequestHandle, ResponseHandle,
};
use fastly_shared::FastlyStatus;

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

pub const INVALID_HTTP_CACHE_HANDLE: HttpCacheHandle = HttpCacheHandle::MAX - 1;

#[repr(u32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
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,
    pub backend_name_ptr: *const u8,
    pub backend_name_len: usize,
}

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

#[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;
    }
}

#[link(wasm_import_module = "fastly_http_cache")]
extern "C" {
    #[link_name = "is_request_cacheable"]
    pub fn is_request_cacheable(
        req_handle: RequestHandle,
        is_cacheable_out: *mut IsCacheable,
    ) -> FastlyStatus;

    #[link_name = "lookup"]
    #[deprecated]
    pub fn lookup(
        req_handle: RequestHandle,
        options_mask: HttpCacheLookupOptionsMask,
        options: *const HttpCacheLookupOptions,
        cache_handle_out: *mut HttpCacheHandle,
    ) -> FastlyStatus;

    #[link_name = "transaction_lookup"]
    pub fn transaction_lookup(
        req_handle: RequestHandle,
        options_mask: HttpCacheLookupOptionsMask,
        options: *const HttpCacheLookupOptions,
        cache_handle_out: *mut HttpCacheHandle,
    ) -> FastlyStatus;

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

    #[link_name = "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;

    #[link_name = "transaction_update"]
    pub fn transaction_update(
        handle: HttpCacheHandle,
        resp_handle: ResponseHandle,
        options_mask: HttpCacheWriteOptionsMask,
        options: *const HttpCacheWriteOptions,
    ) -> FastlyStatus;

    #[link_name = "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;

    #[link_name = "transaction_record_not_cacheable"]
    pub fn transaction_record_not_cacheable(
        handle: HttpCacheHandle,
        options_mask: HttpCacheWriteOptionsMask,
        options: *const HttpCacheWriteOptions,
    ) -> FastlyStatus;

    #[link_name = "transaction_abandon"]
    pub fn transaction_abandon(handle: HttpCacheHandle) -> FastlyStatus;

    #[link_name = "close"]
    pub fn close(handle: HttpCacheHandle) -> FastlyStatus;

    #[link_name = "get_suggested_backend_request"]
    pub fn get_suggested_backend_request(
        handle: HttpCacheHandle,
        req_handle_out: *mut RequestHandle,
    ) -> FastlyStatus;

    #[link_name = "get_suggested_cache_options"]
    pub fn get_suggested_cache_options(
        handle: HttpCacheHandle,
        resp_handle: ResponseHandle,
        options_mask: HttpCacheWriteOptionsMask,
        options: *const HttpCacheWriteOptions,
        options_mask_out: *mut HttpCacheWriteOptionsMask,
        options_out: *mut HttpCacheWriteOptions,
    ) -> FastlyStatus;

    #[link_name = "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;

    #[link_name = "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;

    #[link_name = "get_state"]
    pub fn get_state(
        handle: HttpCacheHandle,
        cache_lookup_state_out: *mut CacheLookupState,
    ) -> FastlyStatus;

    #[link_name = "get_length"]
    pub fn get_length(handle: HttpCacheHandle, length_out: *mut CacheObjectLength) -> FastlyStatus;

    #[link_name = "get_max_age_ns"]
    pub fn get_max_age_ns(
        handle: HttpCacheHandle,
        duration_out: *mut CacheDurationNs,
    ) -> FastlyStatus;

    #[link_name = "get_stale_while_revalidate_ns"]
    pub fn get_stale_while_revalidate_ns(
        handle: HttpCacheHandle,
        duration_out: *mut CacheDurationNs,
    ) -> FastlyStatus;

    #[link_name = "get_age_ns"]
    pub fn get_age_ns(handle: HttpCacheHandle, duration_out: *mut CacheDurationNs) -> FastlyStatus;

    #[link_name = "get_hits"]
    pub fn get_hits(handle: HttpCacheHandle, hits_out: *mut CacheHitCount) -> FastlyStatus;

    #[link_name = "get_sensitive_data"]
    pub fn get_sensitive_data(
        handle: HttpCacheHandle,
        sensitive_data_out: *mut IsSensitive,
    ) -> FastlyStatus;

    #[link_name = "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;

    #[link_name = "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;
}