Skip to main content

fastly_sys/
lib.rs

1// TODO ACF 2020-12-01: remove once this is fixed: https://github.com/rust-lang/rust/issues/79581
2#![allow(clashing_extern_declarations)]
3#![allow(unknown_lints)] // Remove once min version is 1.99
4#![allow(suspicious_runtime_symbol_definitions)]
5#![allow(invalid_runtime_symbol_definitions)]
6
7//! FFI bindings to the Fastly Compute ABI.
8//!
9//! This is a low-level package; the [`fastly`](https://docs.rs/fastly) crate wraps these functions
10//! in a much friendlier, Rust-like interface. You should not have to depend on this crate
11//! explicitly in your `Cargo.toml`.
12//!
13//! # Versioning and compatibility
14//!
15//! The Cargo version of this package was previously set according to compatibility with the
16//! Compute platform. Since the [`v0.25.0` release of the Fastly
17//! CLI](https://github.com/fastly/cli/releases/tag/v0.25.0), the CLI is configured with the range
18//! of `fastly-sys` versions that are currently compatible with the Compute platform. The Cargo
19//! version of this package since `0.4.0` instead follows the [Cargo SemVer compatibility
20//! guidelines](https://doc.rust-lang.org/cargo/reference/semver.html).
21use fastly_shared::FastlyStatus;
22
23pub mod fastly_cache;
24pub mod fastly_config_store;
25pub mod fastly_http_cache;
26
27// The following type aliases are used for readability of definitions in this module. They should
28// not be confused with types of similar names in the `fastly` crate which are used to provide safe
29// wrappers around these definitions.
30
31pub type AclHandle = u32;
32pub type AsyncItemHandle = u32;
33pub type BodyHandle = u32;
34pub type DictionaryHandle = u32;
35pub type KVStoreHandle = u32;
36pub type PendingObjectStoreDeleteHandle = u32;
37pub type PendingObjectStoreInsertHandle = u32;
38pub type PendingObjectStoreListHandle = u32;
39pub type PendingObjectStoreLookupHandle = u32;
40pub type PendingRequestHandle = u32;
41pub type RequestHandle = u32;
42pub type RequestPromiseHandle = u32;
43pub type ResponseHandle = u32;
44pub type SecretHandle = u32;
45pub type SecretStoreHandle = u32;
46
47#[repr(C)]
48pub struct DynamicBackendConfig {
49    pub host_override: *const u8,
50    pub host_override_len: u32,
51    pub connect_timeout_ms: u32,
52    pub first_byte_timeout_ms: u32,
53    pub between_bytes_timeout_ms: u32,
54    pub ssl_min_version: u32,
55    pub ssl_max_version: u32,
56    pub cert_hostname: *const u8,
57    pub cert_hostname_len: u32,
58    pub ca_cert: *const u8,
59    pub ca_cert_len: u32,
60    pub ciphers: *const u8,
61    pub ciphers_len: u32,
62    pub sni_hostname: *const u8,
63    pub sni_hostname_len: u32,
64    pub client_certificate: *const u8,
65    pub client_certificate_len: u32,
66    pub client_key: SecretHandle,
67    pub http_keepalive_time_ms: u32,
68    pub tcp_keepalive_enable: u32,
69    pub tcp_keepalive_interval_secs: u32,
70    pub tcp_keepalive_probes: u32,
71    pub tcp_keepalive_time_secs: u32,
72    pub max_connections: u32,
73    pub max_use: u32,
74    pub max_lifetime_ms: u32,
75    pub healthcheck: *const HealthcheckConfig,
76}
77
78impl Default for DynamicBackendConfig {
79    fn default() -> Self {
80        DynamicBackendConfig {
81            host_override: std::ptr::null(),
82            host_override_len: 0,
83            connect_timeout_ms: 0,
84            first_byte_timeout_ms: 0,
85            between_bytes_timeout_ms: 0,
86            ssl_min_version: 0,
87            ssl_max_version: 0,
88            cert_hostname: std::ptr::null(),
89            cert_hostname_len: 0,
90            ca_cert: std::ptr::null(),
91            ca_cert_len: 0,
92            ciphers: std::ptr::null(),
93            ciphers_len: 0,
94            sni_hostname: std::ptr::null(),
95            sni_hostname_len: 0,
96            client_certificate: std::ptr::null(),
97            client_certificate_len: 0,
98            client_key: 0,
99            http_keepalive_time_ms: 0,
100            tcp_keepalive_enable: 0,
101            tcp_keepalive_interval_secs: 0,
102            tcp_keepalive_probes: 0,
103            tcp_keepalive_time_secs: 0,
104            max_connections: 0,
105            max_use: 0,
106            max_lifetime_ms: 0,
107            healthcheck: std::ptr::null(),
108        }
109    }
110}
111
112#[repr(C)]
113pub struct HealthcheckConfig {
114    pub interval_ms: u64,
115    pub timeout_ms: u64,
116
117    pub host: *const u8,
118    pub host_len: u32,
119    pub method: *const u8,
120    pub method_len: u32,
121    pub path: *const u8,
122    pub path_len: u32,
123    pub expected_status: u32,
124    pub window: u32,
125    pub threshold: u32,
126    pub initial: u32,
127}
128
129/// Selects the behavior for an insert when the new key matches an existing key.
130///
131/// A KV store maintains the property that its keys are unique from each other. If an insert
132/// has a key that doesn't match any key already in the store, then the pair of the key and the
133/// new value is inserted into the store. However, if the insert's key does match a key already
134/// in the store, then no new key-value pair is inserted, and the insert's mode
135/// determines what it does instead.
136#[repr(C)]
137#[derive(Default, Clone, Copy)]
138pub enum InsertMode {
139    /// Updates the existing key's value by overwriting it with the new value.
140    ///
141    /// This is the default mode.
142    #[default]
143    Overwrite,
144
145    /// Fails, leaving the existing key's value unmodified.
146    ///
147    /// With this mode, the insert fails with a “precondition failed” error, and
148    /// does not modify the existing value. Inserts with this mode will only “add” new key-value
149    /// pairs; they are prevented from modifying any existing ones.
150    Add,
151
152    /// Updates the existing key's value by appending the new value to it.
153    Append,
154
155    /// Updates the existing key's value by prepending the new value to it.
156    Prepend,
157}
158
159#[repr(C)]
160pub struct InsertConfig {
161    pub mode: InsertMode,
162    pub unused: u32,
163    pub metadata: *const u8,
164    pub metadata_len: u32,
165    pub time_to_live_sec: u32,
166    pub if_generation_match: u64,
167}
168
169impl Default for InsertConfig {
170    fn default() -> Self {
171        InsertConfig {
172            mode: InsertMode::Overwrite,
173            unused: 0,
174            metadata: std::ptr::null(),
175            metadata_len: 0,
176            time_to_live_sec: 0,
177            if_generation_match: 0,
178        }
179    }
180}
181
182/// Modes of KV Store list operations.
183///
184/// This type serves to facilitate alternative methods of cache interactions with list operations.
185#[repr(C)]
186#[derive(Default, Clone)]
187pub enum ListMode {
188    /// The default method of listing. Performs an un-cached list on every invocation.
189    #[default]
190    Strong,
191    /// Returns a cached list response to improve performance.
192    ///
193    /// The data may be slightly out of sync with the store, but repeated calls are faster.
194    ///
195    /// The word “eventual” here refers to eventual consistency.
196    Eventual,
197    /// Handles unexpected or unknown list modes returned by the upstream API.
198    ///
199    /// This variant is a catch-all and should not be constructed manually by SDK consumers.
200    Other(String),
201}
202
203#[repr(C)]
204#[derive(Default, Clone)]
205pub enum ListModeInternal {
206    #[default]
207    Strong,
208    Eventual,
209}
210
211#[repr(C)]
212pub struct ListConfig {
213    pub mode: ListModeInternal,
214    pub cursor: *const u8,
215    pub cursor_len: u32,
216    pub limit: u32,
217    pub prefix: *const u8,
218    pub prefix_len: u32,
219}
220
221impl Default for ListConfig {
222    fn default() -> Self {
223        ListConfig {
224            mode: ListModeInternal::Strong,
225            cursor: std::ptr::null(),
226            cursor_len: 0,
227            limit: 0,
228            prefix: std::ptr::null(),
229            prefix_len: 0,
230        }
231    }
232}
233
234#[repr(C)]
235#[derive(Default)]
236pub struct LookupConfig {
237    // reserved is just a placeholder,
238    // can be removed when something real is added
239    reserved: u32,
240}
241
242#[repr(C)]
243#[derive(Default)]
244pub struct DeleteConfig {
245    // reserved is just a placeholder,
246    // can be removed when something real is added
247    reserved: u32,
248}
249
250bitflags::bitflags! {
251    /// `Content-Encoding` codings.
252    #[derive(Default)]
253    #[repr(transparent)]
254    pub struct ContentEncodings: u32 {
255        const GZIP = 1 << 0;
256    }
257}
258
259bitflags::bitflags! {
260    /// A bit field used to tell the host which fields are used when setting the cache override,
261    /// for guest caching.
262    ///
263    /// If the `PASS` bit is set, all other bits are ignored.
264    pub struct CacheOverrideTag: u32 {
265        const PASS = 1 << 0;
266        const TTL = 1 << 1;
267        const STALE_WHILE_REVALIDATE = 1 << 2;
268        const PCI = 1 << 3;
269        const LOOKUP_TIMEOUT = 1 << 4;
270    }
271}
272
273/// Fields that can be overridden for guest caching.
274#[repr(C)]
275#[derive(Default)]
276pub struct CacheOverride {
277    pub ttl: u32,
278    pub stale_while_revalidate: u32,
279    pub surrogate_keys: *const u8,
280    pub surrogate_keys_len: u32,
281    pub lookup_timeout_ms: u32,
282}
283
284bitflags::bitflags! {
285    /// `BackendConfigOptions` codings.
286    #[derive(Default)]
287    #[repr(transparent)]
288    pub struct BackendConfigOptions: u32 {
289        const RESERVED = 1 << 0;
290        const HOST_OVERRIDE = 1 << 1;
291        const CONNECT_TIMEOUT = 1 << 2;
292        const FIRST_BYTE_TIMEOUT = 1 << 3;
293        const BETWEEN_BYTES_TIMEOUT = 1 << 4;
294        const USE_SSL = 1 << 5;
295        const SSL_MIN_VERSION = 1 << 6;
296        const SSL_MAX_VERSION = 1 << 7;
297        const CERT_HOSTNAME = 1 << 8;
298        const CA_CERT = 1 << 9;
299        const CIPHERS = 1 << 10;
300        const SNI_HOSTNAME = 1 << 11;
301        const DONT_POOL = 1 << 12;
302        const CLIENT_CERT = 1 << 13;
303        const GRPC = 1 << 14;
304        const KEEPALIVE = 1 << 15;
305        const POOLING_LIMITS = 1 << 16;
306        const PREFER_IPV4 = 1 << 17;
307        const HEALTHCHECK = 1 << 18;
308    }
309    /// `InsertConfigOptions` codings.
310    #[derive(Default)]
311    #[repr(transparent)]
312    pub struct InsertConfigOptions: u32 {
313        const RESERVED = 1 << 0;
314        const BACKGROUND_FETCH = 1 << 1;
315        const RESERVED_2 = 1 << 2;
316        const METADATA = 1 << 3;
317        const TIME_TO_LIVE_SEC = 1 << 4;
318        const IF_GENERATION_MATCH = 1 << 5;
319    }
320    /// `ListConfigOptions` codings.
321    #[derive(Default)]
322    #[repr(transparent)]
323    pub struct ListConfigOptions: u32 {
324        const RESERVED = 1 << 0;
325        const CURSOR = 1 << 1;
326        const LIMIT = 1 << 2;
327        const PREFIX = 1 << 3;
328    }
329    /// `LookupConfigOptions` codings.
330    #[derive(Default)]
331    #[repr(transparent)]
332    pub struct LookupConfigOptions: u32 {
333        const RESERVED = 1 << 0;
334    }
335    /// `DeleteConfigOptions` codings.
336    #[derive(Default)]
337    #[repr(transparent)]
338    pub struct DeleteConfigOptions: u32 {
339        const RESERVED = 1 << 0;
340    }
341}
342
343pub mod fastly_abi {
344    use super::*;
345
346    #[link(wasm_import_module = "fastly_abi")]
347    extern "C" {
348        #[link_name = "init"]
349        /// Tell the runtime what ABI version this program is using (FASTLY_ABI_VERSION)
350        pub fn init(abi_version: u64) -> FastlyStatus;
351    }
352}
353
354#[deprecated(since = "0.11.6")]
355pub mod fastly_uap {
356    use super::*;
357
358    #[link(wasm_import_module = "fastly_uap")]
359    extern "C" {
360        #[link_name = "parse"]
361        pub fn parse(
362            user_agent: *const u8,
363            user_agent_max_len: usize,
364            family: *mut u8,
365            family_max_len: usize,
366            family_written: *mut usize,
367            major: *mut u8,
368            major_max_len: usize,
369            major_written: *mut usize,
370            minor: *mut u8,
371            minor_max_len: usize,
372            minor_written: *mut usize,
373            patch: *mut u8,
374            patch_max_len: usize,
375            patch_written: *mut usize,
376        ) -> FastlyStatus;
377    }
378}
379
380pub mod fastly_http_body {
381    use super::*;
382
383    #[link(wasm_import_module = "fastly_http_body")]
384    extern "C" {
385        #[link_name = "append"]
386        pub fn append(dst_handle: BodyHandle, src_handle: BodyHandle) -> FastlyStatus;
387
388        #[link_name = "new"]
389        pub fn new(handle_out: *mut BodyHandle) -> FastlyStatus;
390
391        #[link_name = "read"]
392        pub fn read(
393            body_handle: BodyHandle,
394            buf: *mut u8,
395            buf_len: usize,
396            nread_out: *mut usize,
397        ) -> FastlyStatus;
398
399        // overeager warning for extern declarations is a rustc bug: https://github.com/rust-lang/rust/issues/79581
400        #[allow(clashing_extern_declarations)]
401        #[link_name = "write"]
402        pub fn write(
403            body_handle: BodyHandle,
404            buf: *const u8,
405            buf_len: usize,
406            end: fastly_shared::BodyWriteEnd,
407            nwritten_out: *mut usize,
408        ) -> FastlyStatus;
409
410        /// Close a body, freeing its resources and causing any sends to finish.
411        #[link_name = "close"]
412        pub fn close(body_handle: BodyHandle) -> FastlyStatus;
413
414        /// Abandon a streaming body, freeing its resources and informing the peer that the stream
415        /// is incomplete.
416        #[link_name = "abandon"]
417        pub fn abandon(body_handle: BodyHandle) -> FastlyStatus;
418
419        #[link_name = "trailer_append"]
420        pub fn trailer_append(
421            body_handle: BodyHandle,
422            name: *const u8,
423            name_len: usize,
424            value: *const u8,
425            value_len: usize,
426        ) -> FastlyStatus;
427
428        #[link_name = "trailer_names_get"]
429        pub fn trailer_names_get(
430            body_handle: BodyHandle,
431            buf: *mut u8,
432            buf_len: usize,
433            cursor: u32,
434            ending_cursor: *mut i64,
435            nwritten: *mut usize,
436        ) -> FastlyStatus;
437
438        #[link_name = "trailer_value_get"]
439        pub fn trailer_value_get(
440            body_handle: BodyHandle,
441            name: *const u8,
442            name_len: usize,
443            value: *mut u8,
444            value_max_len: usize,
445            nwritten: *mut usize,
446        ) -> FastlyStatus;
447
448        #[link_name = "trailer_values_get"]
449        pub fn trailer_values_get(
450            body_handle: BodyHandle,
451            name: *const u8,
452            name_len: usize,
453            buf: *mut u8,
454            buf_len: usize,
455            cursor: u32,
456            ending_cursor: *mut i64,
457            nwritten: *mut usize,
458        ) -> FastlyStatus;
459
460        #[link_name = "known_length"]
461        pub fn known_length(body_handle: BodyHandle, length_out: *mut u64) -> FastlyStatus;
462    }
463}
464
465pub mod fastly_log {
466    use super::*;
467
468    #[link(wasm_import_module = "fastly_log")]
469    extern "C" {
470        #[link_name = "endpoint_get"]
471        pub fn endpoint_get(
472            name: *const u8,
473            name_len: usize,
474            endpoint_handle_out: *mut u32,
475        ) -> FastlyStatus;
476
477        // overeager warning for extern declarations is a rustc bug: https://github.com/rust-lang/rust/issues/79581
478        #[allow(clashing_extern_declarations)]
479        #[link_name = "write"]
480        pub fn write(
481            endpoint_handle: u32,
482            msg: *const u8,
483            msg_len: usize,
484            nwritten_out: *mut usize,
485        ) -> FastlyStatus;
486
487    }
488}
489
490pub mod fastly_http_downstream {
491    use super::*;
492
493    #[derive(Default)]
494    #[repr(C)]
495    pub struct NextRequestOptions {
496        pub timeout_ms: u64,
497    }
498
499    bitflags::bitflags! {
500        /// Request options.
501        #[derive(Default)]
502        #[repr(transparent)]
503        pub struct NextRequestOptionsMask: u32 {
504            const RESERVED = 1 << 0;
505            const TIMEOUT = 1 << 1;
506        }
507    }
508
509    #[link(wasm_import_module = "fastly_http_downstream")]
510    extern "C" {
511        #[link_name = "next_request"]
512        pub fn next_request(
513            options_mask: NextRequestOptionsMask,
514            options: *const NextRequestOptions,
515            handle_out: *mut RequestPromiseHandle,
516        ) -> FastlyStatus;
517
518        #[link_name = "next_request_wait"]
519        pub fn next_request_wait(
520            handle: RequestPromiseHandle,
521            req_handle_out: *mut RequestHandle,
522            body_handle_out: *mut BodyHandle,
523        ) -> FastlyStatus;
524
525        #[link_name = "next_request_abandon"]
526        pub fn next_request_abandon(handle: RequestPromiseHandle) -> FastlyStatus;
527
528        #[link_name = "downstream_original_header_names"]
529        pub fn downstream_original_header_names(
530            req_handle: RequestHandle,
531            buf: *mut u8,
532            buf_len: usize,
533            cursor: u32,
534            ending_cursor: *mut i64,
535            nwritten: *mut usize,
536        ) -> FastlyStatus;
537
538        #[link_name = "downstream_original_header_count"]
539        pub fn downstream_original_header_count(
540            req_handle: RequestHandle,
541            count_out: *mut u32,
542        ) -> FastlyStatus;
543
544        #[link_name = "downstream_client_ip_addr"]
545        pub fn downstream_client_ip_addr(
546            req_handle: RequestHandle,
547            addr_octets_out: *mut u8,
548            nwritten_out: *mut usize,
549        ) -> FastlyStatus;
550
551        #[link_name = "downstream_server_ip_addr"]
552        pub fn downstream_server_ip_addr(
553            req_handle: RequestHandle,
554            addr_octets_out: *mut u8,
555            nwritten_out: *mut usize,
556        ) -> FastlyStatus;
557
558        #[link_name = "downstream_client_h2_fingerprint"]
559        pub fn downstream_client_h2_fingerprint(
560            req_handle: RequestHandle,
561            h2fp_out: *mut u8,
562            h2fp_max_len: usize,
563            nwritten: *mut usize,
564        ) -> FastlyStatus;
565
566        #[link_name = "downstream_client_request_id"]
567        pub fn downstream_client_request_id(
568            req_handle: RequestHandle,
569            reqid_out: *mut u8,
570            reqid_max_len: usize,
571            nwritten: *mut usize,
572        ) -> FastlyStatus;
573
574        #[link_name = "downstream_client_oh_fingerprint"]
575        pub fn downstream_client_oh_fingerprint(
576            req_handle: RequestHandle,
577            ohfp_out: *mut u8,
578            ohfp_max_len: usize,
579            nwritten: *mut usize,
580        ) -> FastlyStatus;
581
582        #[link_name = "downstream_client_ddos_detected"]
583        pub fn downstream_client_ddos_detected(
584            req_handle: RequestHandle,
585            ddos_detected_out: *mut u32,
586        ) -> FastlyStatus;
587
588        #[link_name = "downstream_tls_cipher_openssl_name"]
589        pub fn downstream_tls_cipher_openssl_name(
590            req_handle: RequestHandle,
591            cipher_out: *mut u8,
592            cipher_max_len: usize,
593            nwritten: *mut usize,
594        ) -> FastlyStatus;
595
596        #[link_name = "downstream_tls_protocol"]
597        pub fn downstream_tls_protocol(
598            req_handle: RequestHandle,
599            protocol_out: *mut u8,
600            protocol_max_len: usize,
601            nwritten: *mut usize,
602        ) -> FastlyStatus;
603
604        #[link_name = "downstream_tls_client_hello"]
605        pub fn downstream_tls_client_hello(
606            req_handle: RequestHandle,
607            client_hello_out: *mut u8,
608            client_hello_max_len: usize,
609            nwritten: *mut usize,
610        ) -> FastlyStatus;
611
612        #[link_name = "downstream_tls_client_servername"]
613        pub fn downstream_tls_client_servername(
614            req_handle: RequestHandle,
615            sni_out: *mut u8,
616            sni_max_len: usize,
617            nwritten: *mut usize,
618        ) -> FastlyStatus;
619
620        #[link_name = "downstream_tls_ja3_md5"]
621        pub fn downstream_tls_ja3_md5(
622            req_handle: RequestHandle,
623            ja3_md5_out: *mut u8,
624            nwritten_out: *mut usize,
625        ) -> FastlyStatus;
626
627        #[link_name = "downstream_tls_ja4"]
628        pub fn downstream_tls_ja4(
629            req_handle: RequestHandle,
630            ja4_out: *mut u8,
631            ja4_max_len: usize,
632            nwritten: *mut usize,
633        ) -> FastlyStatus;
634
635        #[link_name = "downstream_compliance_region"]
636        pub fn downstream_compliance_region(
637            req_handle: RequestHandle,
638            region_out: *mut u8,
639            region_max_len: usize,
640            nwritten: *mut usize,
641        ) -> FastlyStatus;
642
643        #[link_name = "downstream_tls_raw_client_certificate"]
644        pub fn downstream_tls_raw_client_certificate(
645            req_handle: RequestHandle,
646            client_hello_out: *mut u8,
647            client_hello_max_len: usize,
648            nwritten: *mut usize,
649        ) -> FastlyStatus;
650
651        #[link_name = "downstream_tls_client_cert_verify_result"]
652        pub fn downstream_tls_client_cert_verify_result(
653            req_handle: RequestHandle,
654            verify_result_out: *mut u32,
655        ) -> FastlyStatus;
656
657        #[link_name = "fastly_key_is_valid"]
658        pub fn fastly_key_is_valid(
659            req_handle: RequestHandle,
660            is_valid_out: *mut u32,
661        ) -> FastlyStatus;
662
663        #[link_name = "downstream_bot_analyzed"]
664        pub fn downstream_bot_analyzed(
665            req_handle: RequestHandle,
666            bot_analyzed_out: *mut u32,
667        ) -> FastlyStatus;
668
669        #[link_name = "downstream_bot_detected"]
670        pub fn downstream_bot_detected(
671            req_handle: RequestHandle,
672            bot_detected_out: *mut u32,
673        ) -> FastlyStatus;
674
675        #[link_name = "downstream_bot_name"]
676        pub fn downstream_bot_name(
677            req_handle: RequestHandle,
678            bot_name_out: *mut u8,
679            bot_name_max_len: usize,
680            nwritten: *mut usize,
681        ) -> FastlyStatus;
682
683        #[link_name = "downstream_bot_category"]
684        pub fn downstream_bot_category(
685            req_handle: RequestHandle,
686            bot_category_out: *mut u8,
687            bot_category_max_len: usize,
688            nwritten: *mut usize,
689        ) -> FastlyStatus;
690
691        #[link_name = "downstream_bot_category_kind"]
692        pub fn downstream_bot_category_kind(
693            req_handle: RequestHandle,
694            bot_category_kind_out: *mut u32,
695        ) -> FastlyStatus;
696
697        #[link_name = "downstream_bot_verified"]
698        pub fn downstream_bot_verified(
699            req_handle: RequestHandle,
700            bot_verified_out: *mut u32,
701        ) -> FastlyStatus;
702
703        #[link_name = "downstream_resvpnproxy_is_anonymous"]
704        pub fn downstream_resvpnproxy_is_anonymous(
705            req_handle: RequestHandle,
706            result_out: *mut u32,
707        ) -> FastlyStatus;
708
709        #[link_name = "downstream_resvpnproxy_is_anonymous_vpn"]
710        pub fn downstream_resvpnproxy_is_anonymous_vpn(
711            req_handle: RequestHandle,
712            result_out: *mut u32,
713        ) -> FastlyStatus;
714
715        #[link_name = "downstream_resvpnproxy_is_hosting_provider"]
716        pub fn downstream_resvpnproxy_is_hosting_provider(
717            req_handle: RequestHandle,
718            result_out: *mut u32,
719        ) -> FastlyStatus;
720
721        #[link_name = "downstream_resvpnproxy_is_proxy_over_vpn"]
722        pub fn downstream_resvpnproxy_is_proxy_over_vpn(
723            req_handle: RequestHandle,
724            result_out: *mut u32,
725        ) -> FastlyStatus;
726
727        #[link_name = "downstream_resvpnproxy_is_public_proxy"]
728        pub fn downstream_resvpnproxy_is_public_proxy(
729            req_handle: RequestHandle,
730            result_out: *mut u32,
731        ) -> FastlyStatus;
732
733        #[link_name = "downstream_resvpnproxy_is_relay_proxy"]
734        pub fn downstream_resvpnproxy_is_relay_proxy(
735            req_handle: RequestHandle,
736            result_out: *mut u32,
737        ) -> FastlyStatus;
738
739        #[link_name = "downstream_resvpnproxy_is_residential_proxy"]
740        pub fn downstream_resvpnproxy_is_residential_proxy(
741            req_handle: RequestHandle,
742            result_out: *mut u32,
743        ) -> FastlyStatus;
744
745        #[link_name = "downstream_resvpnproxy_is_smart_dns_proxy"]
746        pub fn downstream_resvpnproxy_is_smart_dns_proxy(
747            req_handle: RequestHandle,
748            result_out: *mut u32,
749        ) -> FastlyStatus;
750
751        #[link_name = "downstream_resvpnproxy_is_tor_exit_node"]
752        pub fn downstream_resvpnproxy_is_tor_exit_node(
753            req_handle: RequestHandle,
754            result_out: *mut u32,
755        ) -> FastlyStatus;
756
757        #[link_name = "downstream_resvpnproxy_is_vpn_datacenter"]
758        pub fn downstream_resvpnproxy_is_vpn_datacenter(
759            req_handle: RequestHandle,
760            result_out: *mut u32,
761        ) -> FastlyStatus;
762
763        #[link_name = "downstream_resvpnproxy_vpn_service_name"]
764        pub fn downstream_resvpnproxy_vpn_service_name(
765            req_handle: RequestHandle,
766            name_out: *mut u8,
767            name_max_len: usize,
768            nwritten: *mut usize,
769        ) -> FastlyStatus;
770    }
771}
772
773pub mod fastly_http_req {
774    use super::*;
775
776    bitflags::bitflags! {
777        #[derive(Default)]
778        #[repr(transparent)]
779        pub struct SendErrorDetailMask: u32 {
780            const RESERVED = 1 << 0;
781            const DNS_ERROR_RCODE = 1 << 1;
782            const DNS_ERROR_INFO_CODE = 1 << 2;
783            const TLS_ALERT_ID = 1 << 3;
784            const H2_ERROR = 1 << 4;
785        }
786    }
787
788    /// What types of responses to a `PendingRequestHandle` a queued operation
789    /// should apply to.
790    #[repr(u32)]
791    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
792    pub enum PendingResponseKind {
793        /// Apply the change to any response, regardless of whether it's a real one
794        /// or a synthetic response generated after a request error.
795        #[default]
796        Any = 0,
797
798        /// Only apply the change to an actual response, and skip synthetic responses.  
799        Response = 1,
800
801        /// Only apply the change to a synthetic error response, and skip real responses.
802        Error = 2,
803    }
804
805    #[repr(u32)]
806    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
807    #[non_exhaustive]
808    pub enum SendErrorDetailTag {
809        Uninitialized,
810        Ok,
811        DnsTimeout,
812        DnsError,
813        DestinationNotFound,
814        DestinationUnavailable,
815        DestinationIpUnroutable,
816        ConnectionRefused,
817        ConnectionTerminated,
818        ConnectionTimeout,
819        ConnectionLimitReached,
820        TlsCertificateError,
821        TlsConfigurationError,
822        HttpIncompleteResponse,
823        HttpResponseHeaderSectionTooLarge,
824        HttpResponseBodyTooLarge,
825        HttpResponseTimeout,
826        HttpResponseStatusInvalid,
827        HttpUpgradeFailed,
828        HttpProtocolError,
829        HttpRequestCacheKeyInvalid,
830        HttpRequestUriInvalid,
831        InternalError,
832        TlsAlertReceived,
833        TlsProtocolError,
834        H2Error,
835    }
836
837    #[repr(C)]
838    #[derive(Clone, Debug, PartialEq, Eq)]
839    #[non_exhaustive]
840    pub struct SendErrorDetail {
841        pub tag: SendErrorDetailTag,
842        pub mask: SendErrorDetailMask,
843        pub dns_error_rcode: u16,
844        pub dns_error_info_code: u16,
845        pub tls_alert_id: u8,
846        pub h2_error_frame: u8,
847        pub h2_error_code: u32,
848    }
849
850    impl SendErrorDetail {
851        pub fn uninitialized_all() -> Self {
852            Self {
853                tag: SendErrorDetailTag::Uninitialized,
854                mask: SendErrorDetailMask::all(),
855                dns_error_rcode: Default::default(),
856                dns_error_info_code: Default::default(),
857                tls_alert_id: Default::default(),
858                h2_error_frame: Default::default(),
859                h2_error_code: Default::default(),
860            }
861        }
862    }
863
864    bitflags::bitflags! {
865        #[repr(transparent)]
866        pub struct InspectInfoMask: u32 {
867            const RESERVED = 1 << 0;
868            const CORP = 1 << 1;
869            const WORKSPACE = 1 << 2;
870            const OVERRIDE_CLIENT_IP = 1 << 3;
871        }
872    }
873
874    #[repr(C)]
875    pub struct InspectInfo {
876        pub corp: *const u8,
877        pub corp_len: u32,
878        pub workspace: *const u8,
879        pub workspace_len: u32,
880        pub override_client_ip_ptr: *const u8,
881        pub override_client_ip_len: u32,
882    }
883
884    impl Default for InspectInfo {
885        fn default() -> Self {
886            InspectInfo {
887                corp: std::ptr::null(),
888                corp_len: 0,
889                workspace: std::ptr::null(),
890                workspace_len: 0,
891                override_client_ip_ptr: std::ptr::null(),
892                override_client_ip_len: 0,
893            }
894        }
895    }
896
897    #[link(wasm_import_module = "fastly_http_req")]
898    extern "C" {
899        #[link_name = "body_downstream_get"]
900        pub fn body_downstream_get(
901            req_handle_out: *mut RequestHandle,
902            body_handle_out: *mut BodyHandle,
903        ) -> FastlyStatus;
904
905        #[link_name = "cache_override_set"]
906        pub fn cache_override_set(
907            req_handle: RequestHandle,
908            tag: u32,
909            ttl: u32,
910            swr: u32,
911        ) -> FastlyStatus;
912
913        #[link_name = "cache_override_v2_set"]
914        pub fn cache_override_v2_set(
915            req_handle: RequestHandle,
916            tag: u32,
917            ttl: u32,
918            swr: u32,
919            sk: *const u8,
920            sk_len: usize,
921        ) -> FastlyStatus;
922
923        #[link_name = "cache_override_v3_set"]
924        pub fn cache_override_v3_set(
925            req_handle: RequestHandle,
926            tag: u32,
927            cache_override_ptr: *const CacheOverride,
928        ) -> FastlyStatus;
929
930        #[link_name = "framing_headers_mode_set"]
931        pub fn framing_headers_mode_set(
932            req_handle: RequestHandle,
933            mode: fastly_shared::FramingHeadersMode,
934        ) -> FastlyStatus;
935
936        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
937        #[link_name = "downstream_client_ip_addr"]
938        pub fn downstream_client_ip_addr(
939            addr_octets_out: *mut u8,
940            nwritten_out: *mut usize,
941        ) -> FastlyStatus;
942
943        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
944        #[link_name = "downstream_server_ip_addr"]
945        pub fn downstream_server_ip_addr(
946            addr_octets_out: *mut u8,
947            nwritten_out: *mut usize,
948        ) -> FastlyStatus;
949
950        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
951        #[link_name = "downstream_client_h2_fingerprint"]
952        pub fn downstream_client_h2_fingerprint(
953            h2fp_out: *mut u8,
954            h2fp_max_len: usize,
955            nwritten: *mut usize,
956        ) -> FastlyStatus;
957
958        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
959        #[link_name = "downstream_client_request_id"]
960        pub fn downstream_client_request_id(
961            reqid_out: *mut u8,
962            reqid_max_len: usize,
963            nwritten: *mut usize,
964        ) -> FastlyStatus;
965
966        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
967        #[link_name = "downstream_client_oh_fingerprint"]
968        pub fn downstream_client_oh_fingerprint(
969            ohfp_out: *mut u8,
970            ohfp_max_len: usize,
971            nwritten: *mut usize,
972        ) -> FastlyStatus;
973
974        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
975        #[link_name = "downstream_client_ddos_detected"]
976        pub fn downstream_client_ddos_detected(ddos_detected_out: *mut u32) -> FastlyStatus;
977
978        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
979        #[link_name = "downstream_tls_cipher_openssl_name"]
980        pub fn downstream_tls_cipher_openssl_name(
981            cipher_out: *mut u8,
982            cipher_max_len: usize,
983            nwritten: *mut usize,
984        ) -> FastlyStatus;
985
986        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
987        #[link_name = "downstream_tls_protocol"]
988        pub fn downstream_tls_protocol(
989            protocol_out: *mut u8,
990            protocol_max_len: usize,
991            nwritten: *mut usize,
992        ) -> FastlyStatus;
993
994        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
995        #[link_name = "downstream_tls_client_hello"]
996        pub fn downstream_tls_client_hello(
997            client_hello_out: *mut u8,
998            client_hello_max_len: usize,
999            nwritten: *mut usize,
1000        ) -> FastlyStatus;
1001
1002        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
1003        #[link_name = "downstream_tls_ja3_md5"]
1004        pub fn downstream_tls_ja3_md5(
1005            ja3_md5_out: *mut u8,
1006            nwritten_out: *mut usize,
1007        ) -> FastlyStatus;
1008
1009        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
1010        #[link_name = "downstream_tls_ja4"]
1011        pub fn downstream_tls_ja4(
1012            ja4_out: *mut u8,
1013            ja4_max_len: usize,
1014            nwritten: *mut usize,
1015        ) -> FastlyStatus;
1016
1017        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
1018        #[link_name = "downstream_compliance_region"]
1019        pub fn downstream_compliance_region(
1020            region_out: *mut u8,
1021            region_max_len: usize,
1022            nwritten: *mut usize,
1023        ) -> FastlyStatus;
1024
1025        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
1026        #[link_name = "downstream_tls_raw_client_certificate"]
1027        pub fn downstream_tls_raw_client_certificate(
1028            client_hello_out: *mut u8,
1029            client_hello_max_len: usize,
1030            nwritten: *mut usize,
1031        ) -> FastlyStatus;
1032
1033        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
1034        #[link_name = "downstream_tls_client_cert_verify_result"]
1035        pub fn downstream_tls_client_cert_verify_result(
1036            verify_result_out: *mut u32,
1037        ) -> FastlyStatus;
1038
1039        #[link_name = "header_append"]
1040        pub fn header_append(
1041            req_handle: RequestHandle,
1042            name: *const u8,
1043            name_len: usize,
1044            value: *const u8,
1045            value_len: usize,
1046        ) -> FastlyStatus;
1047
1048        #[link_name = "header_insert"]
1049        pub fn header_insert(
1050            req_handle: RequestHandle,
1051            name: *const u8,
1052            name_len: usize,
1053            value: *const u8,
1054            value_len: usize,
1055        ) -> FastlyStatus;
1056
1057        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
1058        #[link_name = "original_header_names_get"]
1059        pub fn original_header_names_get(
1060            buf: *mut u8,
1061            buf_len: usize,
1062            cursor: u32,
1063            ending_cursor: *mut i64,
1064            nwritten: *mut usize,
1065        ) -> FastlyStatus;
1066
1067        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
1068        #[link_name = "original_header_count"]
1069        pub fn original_header_count(count_out: *mut u32) -> FastlyStatus;
1070
1071        #[link_name = "header_names_get"]
1072        pub fn header_names_get(
1073            req_handle: RequestHandle,
1074            buf: *mut u8,
1075            buf_len: usize,
1076            cursor: u32,
1077            ending_cursor: *mut i64,
1078            nwritten: *mut usize,
1079        ) -> FastlyStatus;
1080
1081        #[link_name = "header_values_get"]
1082        pub fn header_values_get(
1083            req_handle: RequestHandle,
1084            name: *const u8,
1085            name_len: usize,
1086            buf: *mut u8,
1087            buf_len: usize,
1088            cursor: u32,
1089            ending_cursor: *mut i64,
1090            nwritten: *mut usize,
1091        ) -> FastlyStatus;
1092
1093        #[link_name = "header_values_set"]
1094        pub fn header_values_set(
1095            req_handle: RequestHandle,
1096            name: *const u8,
1097            name_len: usize,
1098            values: *const u8,
1099            values_len: usize,
1100        ) -> FastlyStatus;
1101
1102        #[link_name = "header_value_get"]
1103        pub fn header_value_get(
1104            req_handle: RequestHandle,
1105            name: *const u8,
1106            name_len: usize,
1107            value: *mut u8,
1108            value_max_len: usize,
1109            nwritten: *mut usize,
1110        ) -> FastlyStatus;
1111
1112        #[link_name = "header_remove"]
1113        pub fn header_remove(
1114            req_handle: RequestHandle,
1115            name: *const u8,
1116            name_len: usize,
1117        ) -> FastlyStatus;
1118
1119        #[link_name = "method_get"]
1120        pub fn method_get(
1121            req_handle: RequestHandle,
1122            method: *mut u8,
1123            method_max_len: usize,
1124            nwritten: *mut usize,
1125        ) -> FastlyStatus;
1126
1127        #[link_name = "method_set"]
1128        pub fn method_set(
1129            req_handle: RequestHandle,
1130            method: *const u8,
1131            method_len: usize,
1132        ) -> FastlyStatus;
1133
1134        #[link_name = "new"]
1135        pub fn new(req_handle_out: *mut RequestHandle) -> FastlyStatus;
1136
1137        #[link_name = "send_v2"]
1138        pub fn send_v2(
1139            req_handle: RequestHandle,
1140            body_handle: BodyHandle,
1141            backend: *const u8,
1142            backend_len: usize,
1143            error_detail: *mut SendErrorDetail,
1144            resp_handle_out: *mut ResponseHandle,
1145            resp_body_handle_out: *mut BodyHandle,
1146        ) -> FastlyStatus;
1147
1148        #[link_name = "send_v3"]
1149        pub fn send_v3(
1150            req_handle: RequestHandle,
1151            body_handle: BodyHandle,
1152            backend: *const u8,
1153            backend_len: usize,
1154            error_detail: *mut SendErrorDetail,
1155            resp_handle_out: *mut ResponseHandle,
1156            resp_body_handle_out: *mut BodyHandle,
1157        ) -> FastlyStatus;
1158
1159        #[link_name = "send_async"]
1160        pub fn send_async(
1161            req_handle: RequestHandle,
1162            body_handle: BodyHandle,
1163            backend: *const u8,
1164            backend_len: usize,
1165            pending_req_handle_out: *mut PendingRequestHandle,
1166        ) -> FastlyStatus;
1167
1168        #[link_name = "send_async_streaming"]
1169        pub fn send_async_streaming(
1170            req_handle: RequestHandle,
1171            body_handle: BodyHandle,
1172            backend: *const u8,
1173            backend_len: usize,
1174            pending_req_handle_out: *mut PendingRequestHandle,
1175        ) -> FastlyStatus;
1176
1177        #[link_name = "send_async_v2"]
1178        pub fn send_async_v2(
1179            req_handle: RequestHandle,
1180            body_handle: BodyHandle,
1181            backend: *const u8,
1182            backend_len: usize,
1183            streaming: u32,
1184            pending_req_handle_out: *mut PendingRequestHandle,
1185        ) -> FastlyStatus;
1186
1187        #[link_name = "upgrade_websocket"]
1188        pub fn upgrade_websocket(backend: *const u8, backend_len: usize) -> FastlyStatus;
1189
1190        #[link_name = "redirect_to_websocket_proxy_v2"]
1191        pub fn redirect_to_websocket_proxy_v2(
1192            req: RequestHandle,
1193            backend: *const u8,
1194            backend_len: usize,
1195        ) -> FastlyStatus;
1196
1197        #[link_name = "redirect_to_grip_proxy_v2"]
1198        pub fn redirect_to_grip_proxy_v2(
1199            req: RequestHandle,
1200            backend: *const u8,
1201            backend_len: usize,
1202        ) -> FastlyStatus;
1203
1204        #[link_name = "register_dynamic_backend"]
1205        pub fn register_dynamic_backend(
1206            name_prefix: *const u8,
1207            name_prefix_len: usize,
1208            target: *const u8,
1209            target_len: usize,
1210            config_mask: BackendConfigOptions,
1211            config: *const DynamicBackendConfig,
1212        ) -> FastlyStatus;
1213
1214        #[link_name = "uri_get"]
1215        pub fn uri_get(
1216            req_handle: RequestHandle,
1217            uri: *mut u8,
1218            uri_max_len: usize,
1219            nwritten: *mut usize,
1220        ) -> FastlyStatus;
1221
1222        #[link_name = "uri_set"]
1223        pub fn uri_set(req_handle: RequestHandle, uri: *const u8, uri_len: usize) -> FastlyStatus;
1224
1225        #[link_name = "version_get"]
1226        pub fn version_get(req_handle: RequestHandle, version: *mut u32) -> FastlyStatus;
1227
1228        #[link_name = "version_set"]
1229        pub fn version_set(req_handle: RequestHandle, version: u32) -> FastlyStatus;
1230
1231        #[link_name = "pending_req_header_append"]
1232        pub fn pending_req_header_append(
1233            pending_req_handle: PendingRequestHandle,
1234            name: *const u8,
1235            name_len: usize,
1236            value: *const u8,
1237            value_len: usize,
1238            target: PendingResponseKind,
1239        ) -> FastlyStatus;
1240
1241        #[link_name = "pending_req_header_insert"]
1242        pub fn pending_req_header_insert(
1243            pending_req_handle: PendingRequestHandle,
1244            name: *const u8,
1245            name_len: usize,
1246            value: *const u8,
1247            value_len: usize,
1248            target: PendingResponseKind,
1249        ) -> FastlyStatus;
1250
1251        #[link_name = "pending_req_header_remove"]
1252        pub fn pending_req_header_remove(
1253            pending_req_handle: PendingRequestHandle,
1254            name: *const u8,
1255            name_len: usize,
1256            target: PendingResponseKind,
1257        ) -> FastlyStatus;
1258
1259        #[link_name = "pending_req_poll_v2"]
1260        pub fn pending_req_poll_v2(
1261            pending_req_handle: PendingRequestHandle,
1262            error_detail: *mut SendErrorDetail,
1263            is_done_out: *mut i32,
1264            resp_handle_out: *mut ResponseHandle,
1265            resp_body_handle_out: *mut BodyHandle,
1266        ) -> FastlyStatus;
1267
1268        #[link_name = "pending_req_select_v2"]
1269        pub fn pending_req_select_v2(
1270            pending_req_handles: *const PendingRequestHandle,
1271            pending_req_handles_len: usize,
1272            error_detail: *mut SendErrorDetail,
1273            done_index_out: *mut i32,
1274            resp_handle_out: *mut ResponseHandle,
1275            resp_body_handle_out: *mut BodyHandle,
1276        ) -> FastlyStatus;
1277
1278        #[link_name = "pending_req_wait_v2"]
1279        pub fn pending_req_wait_v2(
1280            pending_req_handle: PendingRequestHandle,
1281            error_detail: *mut SendErrorDetail,
1282            resp_handle_out: *mut ResponseHandle,
1283            resp_body_handle_out: *mut BodyHandle,
1284        ) -> FastlyStatus;
1285
1286        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
1287        #[link_name = "fastly_key_is_valid"]
1288        pub fn fastly_key_is_valid(is_valid_out: *mut u32) -> FastlyStatus;
1289
1290        #[link_name = "close"]
1291        pub fn close(req_handle: RequestHandle) -> FastlyStatus;
1292
1293        #[link_name = "auto_decompress_response_set"]
1294        pub fn auto_decompress_response_set(
1295            req_handle: RequestHandle,
1296            encodings: ContentEncodings,
1297        ) -> FastlyStatus;
1298
1299        #[link_name = "inspect"]
1300        pub fn inspect(
1301            request_handle: RequestHandle,
1302            body_handle: BodyHandle,
1303            add_info_mask: InspectInfoMask,
1304            add_info: *const InspectInfo,
1305            buf: *mut u8,
1306            buf_len: usize,
1307            nwritten: *mut usize,
1308        ) -> FastlyStatus;
1309
1310        #[link_name = "on_behalf_of"]
1311        pub fn on_behalf_of(
1312            request_handle: RequestHandle,
1313            service: *const u8,
1314            service_len: usize,
1315        ) -> FastlyStatus;
1316    }
1317}
1318
1319pub mod fastly_http_resp {
1320    use super::*;
1321
1322    #[link(wasm_import_module = "fastly_http_resp")]
1323    extern "C" {
1324        #[link_name = "header_append"]
1325        pub fn header_append(
1326            resp_handle: ResponseHandle,
1327            name: *const u8,
1328            name_len: usize,
1329            value: *const u8,
1330            value_len: usize,
1331        ) -> FastlyStatus;
1332
1333        #[link_name = "header_insert"]
1334        pub fn header_insert(
1335            resp_handle: ResponseHandle,
1336            name: *const u8,
1337            name_len: usize,
1338            value: *const u8,
1339            value_len: usize,
1340        ) -> FastlyStatus;
1341
1342        #[link_name = "header_names_get"]
1343        pub fn header_names_get(
1344            resp_handle: ResponseHandle,
1345            buf: *mut u8,
1346            buf_len: usize,
1347            cursor: u32,
1348            ending_cursor: *mut i64,
1349            nwritten: *mut usize,
1350        ) -> FastlyStatus;
1351
1352        #[link_name = "header_value_get"]
1353        pub fn header_value_get(
1354            resp_handle: ResponseHandle,
1355            name: *const u8,
1356            name_len: usize,
1357            value: *mut u8,
1358            value_max_len: usize,
1359            nwritten: *mut usize,
1360        ) -> FastlyStatus;
1361
1362        #[link_name = "header_values_get"]
1363        pub fn header_values_get(
1364            resp_handle: ResponseHandle,
1365            name: *const u8,
1366            name_len: usize,
1367            buf: *mut u8,
1368            buf_len: usize,
1369            cursor: u32,
1370            ending_cursor: *mut i64,
1371            nwritten: *mut usize,
1372        ) -> FastlyStatus;
1373
1374        #[link_name = "header_values_set"]
1375        pub fn header_values_set(
1376            resp_handle: ResponseHandle,
1377            name: *const u8,
1378            name_len: usize,
1379            values: *const u8,
1380            values_len: usize,
1381        ) -> FastlyStatus;
1382
1383        #[link_name = "header_remove"]
1384        pub fn header_remove(
1385            resp_handle: ResponseHandle,
1386            name: *const u8,
1387            name_len: usize,
1388        ) -> FastlyStatus;
1389
1390        #[link_name = "new"]
1391        pub fn new(resp_handle_out: *mut ResponseHandle) -> FastlyStatus;
1392
1393        #[link_name = "send_downstream"]
1394        pub fn send_downstream(
1395            resp_handle: ResponseHandle,
1396            body_handle: BodyHandle,
1397            streaming: u32,
1398        ) -> FastlyStatus;
1399
1400        #[link_name = "send_downstream_pending"]
1401        pub fn send_downstream_pending(pending_req_handle: PendingRequestHandle) -> FastlyStatus;
1402
1403        #[link_name = "status_get"]
1404        pub fn status_get(resp_handle: ResponseHandle, status: *mut u16) -> FastlyStatus;
1405
1406        #[link_name = "status_set"]
1407        pub fn status_set(resp_handle: ResponseHandle, status: u16) -> FastlyStatus;
1408
1409        #[link_name = "reason_phrase_get"]
1410        pub fn reason_phrase_get(
1411            resp_handle: ResponseHandle,
1412            reason_phrase_out: *mut u8,
1413            reason_phrase_max_len: usize,
1414            nwritten_out: *mut usize,
1415        ) -> FastlyStatus;
1416
1417        #[link_name = "version_get"]
1418        pub fn version_get(resp_handle: ResponseHandle, version: *mut u32) -> FastlyStatus;
1419
1420        #[link_name = "version_set"]
1421        pub fn version_set(resp_handle: ResponseHandle, version: u32) -> FastlyStatus;
1422
1423        #[link_name = "framing_headers_mode_set"]
1424        pub fn framing_headers_mode_set(
1425            resp_handle: ResponseHandle,
1426            mode: fastly_shared::FramingHeadersMode,
1427        ) -> FastlyStatus;
1428
1429        #[doc(hidden)]
1430        #[link_name = "http_keepalive_mode_set"]
1431        pub fn http_keepalive_mode_set(
1432            resp_handle: ResponseHandle,
1433            mode: fastly_shared::HttpKeepaliveMode,
1434        ) -> FastlyStatus;
1435
1436        #[link_name = "close"]
1437        pub fn close(resp_handle: ResponseHandle) -> FastlyStatus;
1438
1439        #[link_name = "get_addr_dest_ip"]
1440        pub fn get_addr_dest_ip(
1441            resp_handle: ResponseHandle,
1442            addr_octets_out: *mut u8,
1443            nwritten_out: *mut usize,
1444        ) -> FastlyStatus;
1445
1446        #[link_name = "get_addr_dest_port"]
1447        pub fn get_addr_dest_port(resp_handle: ResponseHandle, port_out: *mut u16) -> FastlyStatus;
1448    }
1449}
1450
1451pub mod fastly_dictionary {
1452    use super::*;
1453
1454    #[link(wasm_import_module = "fastly_dictionary")]
1455    extern "C" {
1456        #[link_name = "open"]
1457        pub fn open(
1458            name: *const u8,
1459            name_len: usize,
1460            dict_handle_out: *mut DictionaryHandle,
1461        ) -> FastlyStatus;
1462
1463        #[link_name = "get"]
1464        pub fn get(
1465            dict_handle: DictionaryHandle,
1466            key: *const u8,
1467            key_len: usize,
1468            value: *mut u8,
1469            value_max_len: usize,
1470            nwritten: *mut usize,
1471        ) -> FastlyStatus;
1472    }
1473}
1474
1475pub mod fastly_geo {
1476    use super::*;
1477
1478    #[link(wasm_import_module = "fastly_geo")]
1479    extern "C" {
1480        #[link_name = "lookup"]
1481        pub fn lookup(
1482            addr_octets: *const u8,
1483            addr_len: usize,
1484            buf: *mut u8,
1485            buf_len: usize,
1486            nwritten_out: *mut usize,
1487        ) -> FastlyStatus;
1488    }
1489}
1490
1491pub mod fastly_device_detection {
1492    use super::*;
1493
1494    #[link(wasm_import_module = "fastly_device_detection")]
1495    extern "C" {
1496        #[link_name = "lookup"]
1497        pub fn lookup(
1498            user_agent: *const u8,
1499            user_agent_max_len: usize,
1500            buf: *mut u8,
1501            buf_len: usize,
1502            nwritten_out: *mut usize,
1503        ) -> FastlyStatus;
1504    }
1505}
1506
1507pub mod fastly_erl {
1508    use super::*;
1509
1510    #[link(wasm_import_module = "fastly_erl")]
1511    extern "C" {
1512        #[link_name = "check_rate"]
1513        pub fn check_rate(
1514            rc: *const u8,
1515            rc_max_len: usize,
1516            entry: *const u8,
1517            entry_max_len: usize,
1518            delta: u32,
1519            window: u32,
1520            limit: u32,
1521            pb: *const u8,
1522            pb_max_len: usize,
1523            ttl: u32,
1524            value: *mut u32,
1525        ) -> FastlyStatus;
1526
1527        #[link_name = "ratecounter_increment"]
1528        pub fn ratecounter_increment(
1529            rc: *const u8,
1530            rc_max_len: usize,
1531            entry: *const u8,
1532            entry_max_len: usize,
1533            delta: u32,
1534        ) -> FastlyStatus;
1535
1536        #[link_name = "ratecounter_lookup_rate"]
1537        pub fn ratecounter_lookup_rate(
1538            rc: *const u8,
1539            rc_max_len: usize,
1540            entry: *const u8,
1541            entry_max_len: usize,
1542            window: u32,
1543            value: *mut u32,
1544        ) -> FastlyStatus;
1545
1546        #[link_name = "ratecounter_lookup_count"]
1547        pub fn ratecounter_lookup_count(
1548            rc: *const u8,
1549            rc_max_len: usize,
1550            entry: *const u8,
1551            entry_max_len: usize,
1552            duration: u32,
1553            value: *mut u32,
1554        ) -> FastlyStatus;
1555
1556        #[link_name = "penaltybox_add"]
1557        pub fn penaltybox_add(
1558            pb: *const u8,
1559            pb_max_len: usize,
1560            entry: *const u8,
1561            entry_max_len: usize,
1562            ttl: u32,
1563        ) -> FastlyStatus;
1564
1565        #[link_name = "penaltybox_has"]
1566        pub fn penaltybox_has(
1567            pb: *const u8,
1568            pb_max_len: usize,
1569            entry: *const u8,
1570            entry_max_len: usize,
1571            value: *mut u32,
1572        ) -> FastlyStatus;
1573    }
1574}
1575
1576pub mod fastly_kv_store {
1577    use super::*;
1578
1579    #[repr(u32)]
1580    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
1581    pub enum KvError {
1582        Uninitialized,
1583        Ok,
1584        BadRequest,
1585        NotFound,
1586        PreconditionFailed,
1587        PayloadTooLarge,
1588        InternalError,
1589    }
1590
1591    // TODO ACF 2023-04-11: keep the object store name here until the ABI is updated
1592    #[link(wasm_import_module = "fastly_object_store")]
1593    extern "C" {
1594        #[link_name = "open"]
1595        pub fn open(
1596            name_ptr: *const u8,
1597            name_len: usize,
1598            kv_store_handle_out: *mut KVStoreHandle,
1599        ) -> FastlyStatus;
1600
1601        #[deprecated(note = "kept for backward compatibility")]
1602        #[link_name = "lookup"]
1603        pub fn lookup(
1604            kv_store_handle: KVStoreHandle,
1605            key_ptr: *const u8,
1606            key_len: usize,
1607            body_handle_out: *mut BodyHandle,
1608        ) -> FastlyStatus;
1609
1610        #[deprecated(note = "kept for backward compatibility")]
1611        #[link_name = "lookup_async"]
1612        pub fn lookup_async(
1613            kv_store_handle: KVStoreHandle,
1614            key_ptr: *const u8,
1615            key_len: usize,
1616            pending_body_handle_out: *mut PendingObjectStoreLookupHandle,
1617        ) -> FastlyStatus;
1618
1619        #[deprecated(note = "kept for backward compatibility")]
1620        #[link_name = "pending_lookup_wait"]
1621        pub fn pending_lookup_wait(
1622            pending_handle: PendingObjectStoreLookupHandle,
1623            body_handle_out: *mut BodyHandle,
1624        ) -> FastlyStatus;
1625
1626        #[deprecated(note = "kept for backward compatibility")]
1627        #[link_name = "insert"]
1628        pub fn insert(
1629            kv_store_handle: KVStoreHandle,
1630            key_ptr: *const u8,
1631            key_len: usize,
1632            body_handle: BodyHandle,
1633        ) -> FastlyStatus;
1634
1635        #[deprecated(note = "kept for backward compatibility")]
1636        #[link_name = "insert_async"]
1637        pub fn insert_async(
1638            kv_store_handle: KVStoreHandle,
1639            key_ptr: *const u8,
1640            key_len: usize,
1641            body_handle: BodyHandle,
1642            pending_body_handle_out: *mut PendingObjectStoreInsertHandle,
1643        ) -> FastlyStatus;
1644
1645        #[deprecated(note = "kept for backward compatibility")]
1646        #[link_name = "pending_insert_wait"]
1647        pub fn pending_insert_wait(
1648            pending_body_handle: PendingObjectStoreInsertHandle,
1649            kv_error_out: *mut KvError,
1650        ) -> FastlyStatus;
1651
1652        #[deprecated(note = "kept for backward compatibility")]
1653        #[link_name = "delete_async"]
1654        pub fn delete_async(
1655            kv_store_handle: KVStoreHandle,
1656            key_ptr: *const u8,
1657            key_len: usize,
1658            pending_body_handle_out: *mut PendingObjectStoreDeleteHandle,
1659        ) -> FastlyStatus;
1660
1661        #[deprecated(note = "kept for backward compatibility")]
1662        #[link_name = "pending_delete_wait"]
1663        pub fn pending_delete_wait(
1664            pending_body_handle: PendingObjectStoreDeleteHandle,
1665        ) -> FastlyStatus;
1666    }
1667
1668    #[link(wasm_import_module = "fastly_kv_store")]
1669    extern "C" {
1670        #[link_name = "open"]
1671        pub fn open_v2(
1672            name_ptr: *const u8,
1673            name_len: usize,
1674            kv_store_handle_out: *mut KVStoreHandle,
1675        ) -> FastlyStatus;
1676
1677        #[link_name = "lookup"]
1678        pub fn lookup_v2(
1679            kv_store_handle: KVStoreHandle,
1680            key_ptr: *const u8,
1681            key_len: usize,
1682            lookup_config_mask: LookupConfigOptions,
1683            lookup_config: *const LookupConfig,
1684            pending_body_handle_out: *mut PendingObjectStoreLookupHandle,
1685        ) -> FastlyStatus;
1686
1687        #[link_name = "lookup_wait"]
1688        pub fn pending_lookup_wait_v2(
1689            pending_handle: PendingObjectStoreLookupHandle,
1690            body_handle_out: *mut BodyHandle,
1691            metadata_buf: *mut u8,
1692            metadata_buf_len: usize,
1693            nwritten_out: *mut usize,
1694            generation_out: *mut u32,
1695            kv_error_out: *mut KvError,
1696        ) -> FastlyStatus;
1697
1698        #[link_name = "lookup_wait_v2"]
1699        pub fn lookup_wait_v2(
1700            pending_handle: PendingObjectStoreLookupHandle,
1701            body_handle_out: *mut BodyHandle,
1702            metadata_buf: *mut u8,
1703            metadata_buf_len: usize,
1704            nwritten_out: *mut usize,
1705            generation_out: *mut u64,
1706            kv_error_out: *mut KvError,
1707        ) -> FastlyStatus;
1708
1709        #[link_name = "insert"]
1710        pub fn insert_v2(
1711            kv_store_handle: KVStoreHandle,
1712            key_ptr: *const u8,
1713            key_len: usize,
1714            body_handle: BodyHandle,
1715            insert_config_mask: InsertConfigOptions,
1716            insert_config: *const InsertConfig,
1717            pending_body_handle_out: *mut PendingObjectStoreInsertHandle,
1718        ) -> FastlyStatus;
1719
1720        #[link_name = "insert_wait"]
1721        pub fn pending_insert_wait_v2(
1722            pending_body_handle: PendingObjectStoreInsertHandle,
1723            kv_error_out: *mut KvError,
1724        ) -> FastlyStatus;
1725
1726        #[link_name = "delete"]
1727        pub fn delete_v2(
1728            kv_store_handle: KVStoreHandle,
1729            key_ptr: *const u8,
1730            key_len: usize,
1731            delete_config_mask: DeleteConfigOptions,
1732            delete_config: *const DeleteConfig,
1733            pending_body_handle_out: *mut PendingObjectStoreDeleteHandle,
1734        ) -> FastlyStatus;
1735
1736        #[link_name = "delete_wait"]
1737        pub fn pending_delete_wait_v2(
1738            pending_body_handle: PendingObjectStoreDeleteHandle,
1739            kv_error_out: *mut KvError,
1740        ) -> FastlyStatus;
1741
1742        #[link_name = "list"]
1743        pub fn list_v2(
1744            kv_store_handle: KVStoreHandle,
1745            list_config_mask: ListConfigOptions,
1746            list_config: *const ListConfig,
1747            pending_body_handle_out: *mut PendingObjectStoreListHandle,
1748        ) -> FastlyStatus;
1749
1750        #[link_name = "list_wait"]
1751        pub fn pending_list_wait_v2(
1752            pending_body_handle: PendingObjectStoreListHandle,
1753            body_handle_out: *mut BodyHandle,
1754            kv_error_out: *mut KvError,
1755        ) -> FastlyStatus;
1756    }
1757}
1758
1759pub mod fastly_secret_store {
1760    use super::*;
1761
1762    #[link(wasm_import_module = "fastly_secret_store")]
1763    extern "C" {
1764        #[link_name = "open"]
1765        pub fn open(
1766            secret_store_name_ptr: *const u8,
1767            secret_store_name_len: usize,
1768            secret_store_handle_out: *mut SecretStoreHandle,
1769        ) -> FastlyStatus;
1770
1771        #[link_name = "get"]
1772        pub fn get(
1773            secret_store_handle: SecretStoreHandle,
1774            secret_name_ptr: *const u8,
1775            secret_name_len: usize,
1776            secret_handle_out: *mut SecretHandle,
1777        ) -> FastlyStatus;
1778
1779        #[link_name = "plaintext"]
1780        pub fn plaintext(
1781            secret_handle: SecretHandle,
1782            plaintext_buf: *mut u8,
1783            plaintext_max_len: usize,
1784            nwritten_out: *mut usize,
1785        ) -> FastlyStatus;
1786
1787        #[link_name = "from_bytes"]
1788        pub fn from_bytes(
1789            plaintext_buf: *const u8,
1790            plaintext_len: usize,
1791            secret_handle_out: *mut SecretHandle,
1792        ) -> FastlyStatus;
1793    }
1794}
1795
1796pub mod fastly_backend {
1797    use super::*;
1798
1799    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
1800    #[repr(u32)]
1801    pub enum BackendHealth {
1802        Unknown,
1803        Healthy,
1804        Unhealthy,
1805    }
1806
1807    #[link(wasm_import_module = "fastly_backend")]
1808    extern "C" {
1809        #[link_name = "exists"]
1810        pub fn exists(
1811            backend_ptr: *const u8,
1812            backend_len: usize,
1813            backend_exists_out: *mut u32,
1814        ) -> FastlyStatus;
1815
1816        #[link_name = "is_healthy"]
1817        pub fn is_healthy(
1818            backend_ptr: *const u8,
1819            backend_len: usize,
1820            backend_health_out: *mut BackendHealth,
1821        ) -> FastlyStatus;
1822
1823        #[link_name = "is_dynamic"]
1824        pub fn is_dynamic(
1825            backend_ptr: *const u8,
1826            backend_len: usize,
1827            value: *mut u32,
1828        ) -> FastlyStatus;
1829
1830        #[link_name = "get_host"]
1831        pub fn get_host(
1832            backend_ptr: *const u8,
1833            backend_len: usize,
1834            value: *mut u8,
1835            value_max_len: usize,
1836            nwritten: *mut usize,
1837        ) -> FastlyStatus;
1838
1839        #[link_name = "get_override_host"]
1840        pub fn get_override_host(
1841            backend_ptr: *const u8,
1842            backend_len: usize,
1843            value: *mut u8,
1844            value_max_len: usize,
1845            nwritten: *mut usize,
1846        ) -> FastlyStatus;
1847
1848        #[link_name = "get_port"]
1849        pub fn get_port(
1850            backend_ptr: *const u8,
1851            backend_len: usize,
1852            value: *mut u16,
1853        ) -> FastlyStatus;
1854
1855        #[link_name = "get_connect_timeout_ms"]
1856        pub fn get_connect_timeout_ms(
1857            backend_ptr: *const u8,
1858            backend_len: usize,
1859            value: *mut u32,
1860        ) -> FastlyStatus;
1861
1862        #[link_name = "get_first_byte_timeout_ms"]
1863        pub fn get_first_byte_timeout_ms(
1864            backend_ptr: *const u8,
1865            backend_len: usize,
1866            value: *mut u32,
1867        ) -> FastlyStatus;
1868
1869        #[link_name = "get_between_bytes_timeout_ms"]
1870        pub fn get_between_bytes_timeout_ms(
1871            backend_ptr: *const u8,
1872            backend_len: usize,
1873            value: *mut u32,
1874        ) -> FastlyStatus;
1875
1876        #[link_name = "get_http_keepalive_time"]
1877        pub fn get_http_keepalive_time(
1878            backend_ptr: *const u8,
1879            backend_len: usize,
1880            value: *mut u32,
1881        ) -> FastlyStatus;
1882
1883        #[link_name = "get_tcp_keepalive_enable"]
1884        pub fn get_tcp_keepalive_enable(
1885            backend_ptr: *const u8,
1886            backend_len: usize,
1887            value: *mut u32,
1888        ) -> FastlyStatus;
1889
1890        #[link_name = "get_tcp_keepalive_interval"]
1891        pub fn get_tcp_keepalive_interval(
1892            backend_ptr: *const u8,
1893            backend_len: usize,
1894            value: *mut u32,
1895        ) -> FastlyStatus;
1896
1897        #[link_name = "get_tcp_keepalive_probes"]
1898        pub fn get_tcp_keepalive_probes(
1899            backend_ptr: *const u8,
1900            backend_len: usize,
1901            value: *mut u32,
1902        ) -> FastlyStatus;
1903
1904        #[link_name = "get_tcp_keepalive_time"]
1905        pub fn get_tcp_keepalive_time(
1906            backend_ptr: *const u8,
1907            backend_len: usize,
1908            value: *mut u32,
1909        ) -> FastlyStatus;
1910
1911        #[link_name = "is_ssl"]
1912        pub fn is_ssl(backend_ptr: *const u8, backend_len: usize, value: *mut u32) -> FastlyStatus;
1913
1914        #[link_name = "get_ssl_min_version"]
1915        pub fn get_ssl_min_version(
1916            backend_ptr: *const u8,
1917            backend_len: usize,
1918            value: *mut u32,
1919        ) -> FastlyStatus;
1920
1921        #[link_name = "get_ssl_max_version"]
1922        pub fn get_ssl_max_version(
1923            backend_ptr: *const u8,
1924            backend_len: usize,
1925            value: *mut u32,
1926        ) -> FastlyStatus;
1927    }
1928}
1929
1930pub mod fastly_async_io {
1931    use super::*;
1932
1933    #[link(wasm_import_module = "fastly_async_io")]
1934    extern "C" {
1935        #[link_name = "select"]
1936        pub fn select(
1937            async_item_handles: *const AsyncItemHandle,
1938            async_item_handles_len: usize,
1939            timeout_ms: u32,
1940            done_index_out: *mut u32,
1941        ) -> FastlyStatus;
1942
1943        #[link_name = "is_ready"]
1944        pub fn is_ready(async_item_handle: AsyncItemHandle, ready_out: *mut u32) -> FastlyStatus;
1945    }
1946}
1947
1948pub mod fastly_image_optimizer {
1949    use super::*;
1950
1951    bitflags::bitflags! {
1952        #[repr(transparent)]
1953        pub struct ImageOptimizerTransformConfigOptions: u32 {
1954            const RESERVED = 1 << 0;
1955            const SDK_CLAIMS_OPTS = 1 << 1;
1956        }
1957    }
1958
1959    #[repr(C, align(8))]
1960    pub struct ImageOptimizerTransformConfig {
1961        pub sdk_claims_opts: *const u8,
1962        pub sdk_claims_opts_len: u32,
1963    }
1964
1965    impl Default for ImageOptimizerTransformConfig {
1966        fn default() -> Self {
1967            ImageOptimizerTransformConfig {
1968                sdk_claims_opts: std::ptr::null(),
1969                sdk_claims_opts_len: 0,
1970            }
1971        }
1972    }
1973
1974    #[repr(u32)]
1975    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
1976    pub enum ImageOptimizerErrorTag {
1977        Uninitialized,
1978        Ok,
1979        Error,
1980        Warning,
1981    }
1982
1983    #[repr(C, align(8))]
1984    #[derive(Clone, Debug, PartialEq, Eq)]
1985    pub struct ImageOptimizerErrorDetail {
1986        pub tag: ImageOptimizerErrorTag,
1987        pub message: *const u8,
1988        pub message_len: usize,
1989    }
1990
1991    impl ImageOptimizerErrorDetail {
1992        pub fn uninitialized() -> Self {
1993            Self {
1994                tag: ImageOptimizerErrorTag::Uninitialized,
1995                message: std::ptr::null(),
1996                message_len: 0,
1997            }
1998        }
1999    }
2000
2001    #[link(wasm_import_module = "fastly_image_optimizer")]
2002    extern "C" {
2003        #[link_name = "transform_image_optimizer_request"]
2004        pub fn transform_image_optimizer_request(
2005            origin_image_request: RequestHandle,
2006            origin_image_request_body: BodyHandle,
2007            origin_image_backend: *const u8,
2008            origin_image_backend_len: usize,
2009            io_transform_config_options: ImageOptimizerTransformConfigOptions,
2010            io_transform_config: *const ImageOptimizerTransformConfig,
2011            io_error_detail: *mut ImageOptimizerErrorDetail,
2012            resp_handle_out: *mut ResponseHandle,
2013            resp_body_handle_out: *mut BodyHandle,
2014        ) -> FastlyStatus;
2015    }
2016}
2017
2018pub mod fastly_purge {
2019    use super::*;
2020
2021    bitflags::bitflags! {
2022        #[derive(Default)]
2023        #[repr(transparent)]
2024        pub struct PurgeOptionsMask: u32 {
2025            const SOFT_PURGE = 1 << 0;
2026            const RET_BUF = 1 << 1;
2027        }
2028    }
2029
2030    #[derive(Debug)]
2031    #[repr(C)]
2032    pub struct PurgeOptions {
2033        pub ret_buf_ptr: *mut u8,
2034        pub ret_buf_len: usize,
2035        pub ret_buf_nwritten_out: *mut usize,
2036    }
2037
2038    #[link(wasm_import_module = "fastly_purge")]
2039    extern "C" {
2040        #[link_name = "purge_surrogate_key"]
2041        pub fn purge_surrogate_key(
2042            surrogate_key_ptr: *const u8,
2043            surrogate_key_len: usize,
2044            options_mask: PurgeOptionsMask,
2045            options: *mut PurgeOptions,
2046        ) -> FastlyStatus;
2047    }
2048}
2049
2050pub mod fastly_compute_runtime {
2051    use super::*;
2052
2053    #[link(wasm_import_module = "fastly_compute_runtime")]
2054    extern "C" {
2055        #[link_name = "get_vcpu_ms"]
2056        pub fn get_vcpu_ms(ms_out: *mut u64) -> FastlyStatus;
2057    }
2058
2059    #[link(wasm_import_module = "fastly_compute_runtime")]
2060    extern "C" {
2061        #[link_name = "get_heap_mib"]
2062        pub fn get_heap_mib(mb_out: *mut u32) -> fastly_shared::FastlyStatus;
2063    }
2064
2065    #[link(wasm_import_module = "fastly_compute_runtime")]
2066    extern "C" {
2067        #[link_name = "has_domain_inspector"]
2068        pub fn has_domain_inspector(mb_out: *mut u32) -> fastly_shared::FastlyStatus;
2069    }
2070
2071    #[link(wasm_import_module = "fastly_compute_runtime")]
2072    extern "C" {
2073        #[link_name = "has_image_optimizer"]
2074        pub fn has_image_optimizer(mb_out: *mut u32) -> fastly_shared::FastlyStatus;
2075    }
2076
2077    #[link(wasm_import_module = "fastly_compute_runtime")]
2078    extern "C" {
2079        #[link_name = "has_origin_inspector"]
2080        pub fn has_origin_inspector(mb_out: *mut u32) -> fastly_shared::FastlyStatus;
2081    }
2082}
2083
2084pub mod fastly_acl {
2085    use super::*;
2086
2087    #[repr(u32)]
2088    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
2089    pub enum AclError {
2090        Uninitialized,
2091        Ok,
2092        NoContent,
2093        TooManyRequests,
2094    }
2095
2096    #[link(wasm_import_module = "fastly_acl")]
2097    extern "C" {
2098        #[link_name = "open"]
2099        pub fn open(
2100            acl_name_ptr: *const u8,
2101            acl_name_len: usize,
2102            acl_handle_out: *mut AclHandle,
2103        ) -> FastlyStatus;
2104
2105        #[link_name = "lookup"]
2106        pub fn lookup(
2107            acl_handle: AclHandle,
2108            ip_octets: *const u8,
2109            ip_len: usize,
2110            body_handle_out: *mut BodyHandle,
2111            acl_error_out: *mut AclError,
2112        ) -> FastlyStatus;
2113    }
2114}
2115
2116pub mod fastly_shielding {
2117    use super::*;
2118
2119    bitflags::bitflags! {
2120        #[derive(Default)]
2121        #[repr(transparent)]
2122        pub struct ShieldBackendOptions: u32 {
2123            const RESERVED = 1 << 0;
2124            const CACHE_KEY = 1 << 1;
2125            const FIRST_BYTE_TIMEOUT = 1 << 2;
2126            const BETWEEN_BYTES_TIMEOUT = 1 << 3;
2127        }
2128    }
2129
2130    #[repr(C)]
2131    pub struct ShieldBackendConfig {
2132        pub cache_key: *const u8,
2133        pub cache_key_len: u32,
2134        pub first_byte_timeout_ms: u32,
2135        pub between_bytes_timeout_ms: u32,
2136    }
2137
2138    impl Default for ShieldBackendConfig {
2139        fn default() -> Self {
2140            ShieldBackendConfig {
2141                cache_key: std::ptr::null(),
2142                cache_key_len: 0,
2143                first_byte_timeout_ms: 0,
2144                between_bytes_timeout_ms: 0,
2145            }
2146        }
2147    }
2148
2149    //   (@interface func (export "shield_info")
2150    //     (param $name string)
2151    //     (param $info_block (@witx pointer (@witx char8)))
2152    //     (param $info_block_max_len (@witx usize))
2153    //     (result $err (expected $num_bytes (error $fastly_status)))
2154    //   )
2155
2156    #[link(wasm_import_module = "fastly_shielding")]
2157    extern "C" {
2158
2159        /// Get information about the given shield in the Fastly network
2160        #[link_name = "shield_info"]
2161        pub fn shield_info(
2162            name: *const u8,
2163            name_len: usize,
2164            info_block: *mut u8,
2165            info_block_len: usize,
2166            nwritten_out: *mut u32,
2167        ) -> FastlyStatus;
2168
2169        /// Turn a pop name into a backend that we can send requests to.
2170        #[link_name = "backend_for_shield"]
2171        pub fn backend_for_shield(
2172            name: *const u8,
2173            name_len: usize,
2174            options_mask: ShieldBackendOptions,
2175            options: *const ShieldBackendConfig,
2176            backend_name: *mut u8,
2177            backend_name_len: usize,
2178            nwritten_out: *mut u32,
2179        ) -> FastlyStatus;
2180    }
2181}
2182
2183/// WIT for the Fastly APIs in the `fastly:compute/service@0.1.0` world.
2184#[cfg(not(target_env = "p1"))]
2185pub mod service_0_1;
2186
2187#[cfg(not(target_env = "p1"))]
2188impl From<service_0_1::fastly::compute::types::Error> for fastly_shared::FastlyStatus {
2189    fn from(error: service_0_1::fastly::compute::types::Error) -> Self {
2190        use service_0_1::fastly::compute::types::Error;
2191        match error {
2192            Error::InvalidArgument => Self::INVAL,
2193            Error::Unsupported => Self::UNSUPPORTED,
2194            Error::LimitExceeded => Self::LIMITEXCEEDED,
2195            Error::GenericError => Self::ERROR,
2196            Error::BufferLen(_) => Self::BUFLEN,
2197            Error::CannotRead => Self::NONE,
2198            Error::AuxiliaryError => Self::BADF,
2199            Error::HttpInvalid => Self::HTTPINVALID,
2200            Error::HttpUser => Self::HTTPUSER,
2201            Error::HttpIncomplete => Self::HTTPINCOMPLETE,
2202            Error::HttpHeadTooLarge => Self::HTTPHEADTOOLARGE,
2203            Error::HttpInvalidStatus => Self::HTTPINVALIDSTATUS,
2204        }
2205    }
2206}
2207
2208#[cfg(not(target_env = "p1"))]
2209impl From<std::net::IpAddr> for service_0_1::fastly::compute::types::IpAddress {
2210    fn from(addr: std::net::IpAddr) -> Self {
2211        use std::net::IpAddr;
2212        match addr {
2213            IpAddr::V4(v4) => Self::Ipv4(v4.octets().into()),
2214            IpAddr::V6(v6) => Self::Ipv6(v6.segments().into()),
2215        }
2216    }
2217}
2218
2219#[cfg(not(target_env = "p1"))]
2220impl From<service_0_1::fastly::compute::types::IpAddress> for std::net::IpAddr {
2221    fn from(addr: service_0_1::fastly::compute::types::IpAddress) -> Self {
2222        use service_0_1::fastly::compute::types::IpAddress;
2223        match addr {
2224            IpAddress::Ipv4(v4) => Self::V4(<[u8; 4]>::from(v4).into()),
2225            IpAddress::Ipv6(v6) => Self::V6(<[u16; 8]>::from(v6).into()),
2226        }
2227    }
2228}
2229
2230#[cfg(not(target_env = "p1"))]
2231impl From<service_0_1::fastly::compute::http_types::HttpVersion> for http::version::Version {
2232    fn from(version: service_0_1::fastly::compute::http_types::HttpVersion) -> Self {
2233        use service_0_1::fastly::compute::http_types::HttpVersion;
2234        match version {
2235            HttpVersion::Http09 => Self::HTTP_09,
2236            HttpVersion::Http10 => Self::HTTP_10,
2237            HttpVersion::Http11 => Self::HTTP_11,
2238            HttpVersion::H2 => Self::HTTP_2,
2239            HttpVersion::H3 => Self::HTTP_3,
2240        }
2241    }
2242}
2243
2244#[cfg(not(target_env = "p1"))]
2245impl TryFrom<http::version::Version> for service_0_1::fastly::compute::http_types::HttpVersion {
2246    type Error = ();
2247
2248    fn try_from(version: http::version::Version) -> Result<Self, Self::Error> {
2249        use http::version::Version;
2250        Ok(match version {
2251            Version::HTTP_09 => Self::Http09,
2252            Version::HTTP_10 => Self::Http10,
2253            Version::HTTP_11 => Self::Http11,
2254            Version::HTTP_2 => Self::H2,
2255            Version::HTTP_3 => Self::H3,
2256            _ => return Err(()),
2257        })
2258    }
2259}
2260
2261#[cfg(not(target_env = "p1"))]
2262impl From<fastly_shared::FramingHeadersMode>
2263    for service_0_1::fastly::compute::http_types::FramingHeadersMode
2264{
2265    fn from(mode: fastly_shared::FramingHeadersMode) -> Self {
2266        use fastly_shared::FramingHeadersMode;
2267        match mode {
2268            FramingHeadersMode::Automatic => Self::Automatic,
2269            FramingHeadersMode::ManuallyFromHeaders => Self::ManuallyFromHeaders,
2270        }
2271    }
2272}
2273
2274#[cfg(not(target_env = "p1"))]
2275impl From<service_0_1::fastly::compute::http_types::FramingHeadersMode>
2276    for fastly_shared::FramingHeadersMode
2277{
2278    fn from(mode: service_0_1::fastly::compute::http_types::FramingHeadersMode) -> Self {
2279        use service_0_1::fastly::compute::http_types::FramingHeadersMode;
2280        match mode {
2281            FramingHeadersMode::Automatic => Self::Automatic,
2282            FramingHeadersMode::ManuallyFromHeaders => Self::ManuallyFromHeaders,
2283        }
2284    }
2285}
2286
2287#[cfg(not(target_env = "p1"))]
2288impl From<fastly_shared::HttpKeepaliveMode>
2289    for service_0_1::fastly::compute::http_resp::KeepaliveMode
2290{
2291    fn from(mode: fastly_shared::HttpKeepaliveMode) -> Self {
2292        use fastly_shared::HttpKeepaliveMode;
2293        match mode {
2294            HttpKeepaliveMode::Automatic => Self::Automatic,
2295            HttpKeepaliveMode::NoKeepalive => Self::NoKeepalive,
2296        }
2297    }
2298}
2299
2300#[cfg(not(target_env = "p1"))]
2301impl From<service_0_1::fastly::compute::http_resp::KeepaliveMode>
2302    for fastly_shared::HttpKeepaliveMode
2303{
2304    fn from(mode: service_0_1::fastly::compute::http_resp::KeepaliveMode) -> Self {
2305        use service_0_1::fastly::compute::http_resp::KeepaliveMode;
2306        match mode {
2307            KeepaliveMode::Automatic => Self::Automatic,
2308            KeepaliveMode::NoKeepalive => Self::NoKeepalive,
2309        }
2310    }
2311}