fastly_sys/
fastly_http_cache.rs

1use crate::{
2    fastly_cache::{CacheDurationNs, CacheHitCount, CacheLookupState, CacheObjectLength},
3    BodyHandle, RequestHandle, ResponseHandle,
4};
5use fastly_shared::FastlyStatus;
6
7pub type HttpCacheHandle = u32;
8pub type IsCacheable = u32;
9pub type IsSensitive = u32;
10
11pub const INVALID_HTTP_CACHE_HANDLE: HttpCacheHandle = HttpCacheHandle::MAX - 1;
12
13#[repr(u32)]
14#[derive(Clone, Copy, Debug, PartialEq, Eq)]
15pub enum HttpStorageAction {
16    Insert,
17    Update,
18    DoNotStore,
19    RecordUncacheable,
20}
21
22#[repr(C)]
23#[derive(Clone, Copy, Debug, PartialEq, Eq)]
24pub struct HttpCacheLookupOptions {
25    pub override_key_ptr: *const u8,
26    pub override_key_len: usize,
27    pub backend_name_ptr: *const u8,
28    pub backend_name_len: usize,
29}
30
31bitflags::bitflags! {
32    #[repr(transparent)]
33    pub struct HttpCacheLookupOptionsMask: u32 {
34        const _RESERVED = 1 << 0;
35        const OVERRIDE_KEY = 1 << 1;
36        const BACKEND_NAME = 1 << 2;
37    }
38}
39
40#[repr(C)]
41#[derive(Clone, Copy, Debug, PartialEq, Eq)]
42pub struct HttpCacheWriteOptions {
43    pub max_age_ns: CacheDurationNs,
44    pub vary_rule_ptr: *const u8,
45    pub vary_rule_len: usize,
46    pub initial_age_ns: CacheDurationNs,
47    pub stale_while_revalidate_ns: CacheDurationNs,
48    pub surrogate_keys_ptr: *const u8,
49    pub surrogate_keys_len: usize,
50    pub length: CacheObjectLength,
51}
52
53bitflags::bitflags! {
54    #[repr(transparent)]
55    pub struct HttpCacheWriteOptionsMask: u32 {
56        const _RESERVED = 1 << 0;
57        const VARY_RULE = 1 << 1;
58        const INITIAL_AGE_NS = 1 << 2;
59        const STALE_WHILE_REVALIDATE_NS = 1 << 3;
60        const SURROGATE_KEYS = 1 << 4;
61        const LENGTH = 1 << 5;
62        const SENSITIVE_DATA = 1 << 6;
63    }
64}
65
66#[link(wasm_import_module = "fastly_http_cache")]
67extern "C" {
68    #[link_name = "is_request_cacheable"]
69    pub fn is_request_cacheable(
70        req_handle: RequestHandle,
71        is_cacheable_out: *mut IsCacheable,
72    ) -> FastlyStatus;
73
74    #[link_name = "lookup"]
75    #[deprecated]
76    pub fn lookup(
77        req_handle: RequestHandle,
78        options_mask: HttpCacheLookupOptionsMask,
79        options: *const HttpCacheLookupOptions,
80        cache_handle_out: *mut HttpCacheHandle,
81    ) -> FastlyStatus;
82
83    #[link_name = "transaction_lookup"]
84    pub fn transaction_lookup(
85        req_handle: RequestHandle,
86        options_mask: HttpCacheLookupOptionsMask,
87        options: *const HttpCacheLookupOptions,
88        cache_handle_out: *mut HttpCacheHandle,
89    ) -> FastlyStatus;
90
91    #[link_name = "transaction_insert"]
92    pub fn transaction_insert(
93        handle: HttpCacheHandle,
94        resp_handle: ResponseHandle,
95        options_mask: HttpCacheWriteOptionsMask,
96        options: *const HttpCacheWriteOptions,
97        body_handle_out: *mut BodyHandle,
98    ) -> FastlyStatus;
99
100    #[link_name = "transaction_insert_and_stream_back"]
101    pub fn transaction_insert_and_stream_back(
102        handle: HttpCacheHandle,
103        resp_handle: ResponseHandle,
104        options_mask: HttpCacheWriteOptionsMask,
105        options: *const HttpCacheWriteOptions,
106        body_handle_out: *mut BodyHandle,
107        cache_handle_out: *mut HttpCacheHandle,
108    ) -> FastlyStatus;
109
110    #[link_name = "transaction_update"]
111    pub fn transaction_update(
112        handle: HttpCacheHandle,
113        resp_handle: ResponseHandle,
114        options_mask: HttpCacheWriteOptionsMask,
115        options: *const HttpCacheWriteOptions,
116    ) -> FastlyStatus;
117
118    #[link_name = "transaction_update_and_return_fresh"]
119    pub fn transaction_update_and_return_fresh(
120        handle: HttpCacheHandle,
121        resp_handle: ResponseHandle,
122        options_mask: HttpCacheWriteOptionsMask,
123        options: *const HttpCacheWriteOptions,
124        cache_handle_out: *mut HttpCacheHandle,
125    ) -> FastlyStatus;
126
127    #[link_name = "transaction_record_not_cacheable"]
128    pub fn transaction_record_not_cacheable(
129        handle: HttpCacheHandle,
130        options_mask: HttpCacheWriteOptionsMask,
131        options: *const HttpCacheWriteOptions,
132    ) -> FastlyStatus;
133
134    #[link_name = "transaction_abandon"]
135    pub fn transaction_abandon(handle: HttpCacheHandle) -> FastlyStatus;
136
137    #[link_name = "close"]
138    pub fn close(handle: HttpCacheHandle) -> FastlyStatus;
139
140    #[link_name = "get_suggested_backend_request"]
141    pub fn get_suggested_backend_request(
142        handle: HttpCacheHandle,
143        req_handle_out: *mut RequestHandle,
144    ) -> FastlyStatus;
145
146    #[link_name = "get_suggested_cache_options"]
147    pub fn get_suggested_cache_options(
148        handle: HttpCacheHandle,
149        resp_handle: ResponseHandle,
150        options_mask: HttpCacheWriteOptionsMask,
151        options: *const HttpCacheWriteOptions,
152        options_mask_out: *mut HttpCacheWriteOptionsMask,
153        options_out: *mut HttpCacheWriteOptions,
154    ) -> FastlyStatus;
155
156    #[link_name = "prepare_response_for_storage"]
157    pub fn prepare_response_for_storage(
158        handle: HttpCacheHandle,
159        resp_handle: ResponseHandle,
160        http_storage_action_out: *mut HttpStorageAction,
161        resp_handle_out: *mut ResponseHandle,
162    ) -> FastlyStatus;
163
164    #[link_name = "get_found_response"]
165    pub fn get_found_response(
166        handle: HttpCacheHandle,
167        transform_for_client: u32,
168        resp_handle_out: *mut ResponseHandle,
169        body_handle_out: *mut BodyHandle,
170    ) -> FastlyStatus;
171
172    #[link_name = "get_state"]
173    pub fn get_state(
174        handle: HttpCacheHandle,
175        cache_lookup_state_out: *mut CacheLookupState,
176    ) -> FastlyStatus;
177
178    #[link_name = "get_length"]
179    pub fn get_length(handle: HttpCacheHandle, length_out: *mut CacheObjectLength) -> FastlyStatus;
180
181    #[link_name = "get_max_age_ns"]
182    pub fn get_max_age_ns(
183        handle: HttpCacheHandle,
184        duration_out: *mut CacheDurationNs,
185    ) -> FastlyStatus;
186
187    #[link_name = "get_stale_while_revalidate_ns"]
188    pub fn get_stale_while_revalidate_ns(
189        handle: HttpCacheHandle,
190        duration_out: *mut CacheDurationNs,
191    ) -> FastlyStatus;
192
193    #[link_name = "get_age_ns"]
194    pub fn get_age_ns(handle: HttpCacheHandle, duration_out: *mut CacheDurationNs) -> FastlyStatus;
195
196    #[link_name = "get_hits"]
197    pub fn get_hits(handle: HttpCacheHandle, hits_out: *mut CacheHitCount) -> FastlyStatus;
198
199    #[link_name = "get_sensitive_data"]
200    pub fn get_sensitive_data(
201        handle: HttpCacheHandle,
202        sensitive_data_out: *mut IsSensitive,
203    ) -> FastlyStatus;
204
205    #[link_name = "get_surrogate_keys"]
206    pub fn get_surrogate_keys(
207        handle: HttpCacheHandle,
208        surrogate_keys_out_ptr: *mut u8,
209        surrogate_keys_out_len: usize,
210        nwritten_out: *mut usize,
211    ) -> FastlyStatus;
212
213    #[link_name = "get_vary_rule"]
214    pub fn get_vary_rule(
215        handle: HttpCacheHandle,
216        vary_rule_out_ptr: *mut u8,
217        vary_rule_out_len: usize,
218        nwritten_out: *mut usize,
219    ) -> FastlyStatus;
220}