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 = "version_get"]
1410        pub fn version_get(resp_handle: ResponseHandle, version: *mut u32) -> FastlyStatus;
1411
1412        #[link_name = "version_set"]
1413        pub fn version_set(resp_handle: ResponseHandle, version: u32) -> FastlyStatus;
1414
1415        #[link_name = "framing_headers_mode_set"]
1416        pub fn framing_headers_mode_set(
1417            resp_handle: ResponseHandle,
1418            mode: fastly_shared::FramingHeadersMode,
1419        ) -> FastlyStatus;
1420
1421        #[doc(hidden)]
1422        #[link_name = "http_keepalive_mode_set"]
1423        pub fn http_keepalive_mode_set(
1424            resp_handle: ResponseHandle,
1425            mode: fastly_shared::HttpKeepaliveMode,
1426        ) -> FastlyStatus;
1427
1428        #[link_name = "close"]
1429        pub fn close(resp_handle: ResponseHandle) -> FastlyStatus;
1430
1431        #[link_name = "get_addr_dest_ip"]
1432        pub fn get_addr_dest_ip(
1433            resp_handle: ResponseHandle,
1434            addr_octets_out: *mut u8,
1435            nwritten_out: *mut usize,
1436        ) -> FastlyStatus;
1437
1438        #[link_name = "get_addr_dest_port"]
1439        pub fn get_addr_dest_port(resp_handle: ResponseHandle, port_out: *mut u16) -> FastlyStatus;
1440    }
1441}
1442
1443pub mod fastly_dictionary {
1444    use super::*;
1445
1446    #[link(wasm_import_module = "fastly_dictionary")]
1447    extern "C" {
1448        #[link_name = "open"]
1449        pub fn open(
1450            name: *const u8,
1451            name_len: usize,
1452            dict_handle_out: *mut DictionaryHandle,
1453        ) -> FastlyStatus;
1454
1455        #[link_name = "get"]
1456        pub fn get(
1457            dict_handle: DictionaryHandle,
1458            key: *const u8,
1459            key_len: usize,
1460            value: *mut u8,
1461            value_max_len: usize,
1462            nwritten: *mut usize,
1463        ) -> FastlyStatus;
1464    }
1465}
1466
1467pub mod fastly_geo {
1468    use super::*;
1469
1470    #[link(wasm_import_module = "fastly_geo")]
1471    extern "C" {
1472        #[link_name = "lookup"]
1473        pub fn lookup(
1474            addr_octets: *const u8,
1475            addr_len: usize,
1476            buf: *mut u8,
1477            buf_len: usize,
1478            nwritten_out: *mut usize,
1479        ) -> FastlyStatus;
1480    }
1481}
1482
1483pub mod fastly_device_detection {
1484    use super::*;
1485
1486    #[link(wasm_import_module = "fastly_device_detection")]
1487    extern "C" {
1488        #[link_name = "lookup"]
1489        pub fn lookup(
1490            user_agent: *const u8,
1491            user_agent_max_len: usize,
1492            buf: *mut u8,
1493            buf_len: usize,
1494            nwritten_out: *mut usize,
1495        ) -> FastlyStatus;
1496    }
1497}
1498
1499pub mod fastly_erl {
1500    use super::*;
1501
1502    #[link(wasm_import_module = "fastly_erl")]
1503    extern "C" {
1504        #[link_name = "check_rate"]
1505        pub fn check_rate(
1506            rc: *const u8,
1507            rc_max_len: usize,
1508            entry: *const u8,
1509            entry_max_len: usize,
1510            delta: u32,
1511            window: u32,
1512            limit: u32,
1513            pb: *const u8,
1514            pb_max_len: usize,
1515            ttl: u32,
1516            value: *mut u32,
1517        ) -> FastlyStatus;
1518
1519        #[link_name = "ratecounter_increment"]
1520        pub fn ratecounter_increment(
1521            rc: *const u8,
1522            rc_max_len: usize,
1523            entry: *const u8,
1524            entry_max_len: usize,
1525            delta: u32,
1526        ) -> FastlyStatus;
1527
1528        #[link_name = "ratecounter_lookup_rate"]
1529        pub fn ratecounter_lookup_rate(
1530            rc: *const u8,
1531            rc_max_len: usize,
1532            entry: *const u8,
1533            entry_max_len: usize,
1534            window: u32,
1535            value: *mut u32,
1536        ) -> FastlyStatus;
1537
1538        #[link_name = "ratecounter_lookup_count"]
1539        pub fn ratecounter_lookup_count(
1540            rc: *const u8,
1541            rc_max_len: usize,
1542            entry: *const u8,
1543            entry_max_len: usize,
1544            duration: u32,
1545            value: *mut u32,
1546        ) -> FastlyStatus;
1547
1548        #[link_name = "penaltybox_add"]
1549        pub fn penaltybox_add(
1550            pb: *const u8,
1551            pb_max_len: usize,
1552            entry: *const u8,
1553            entry_max_len: usize,
1554            ttl: u32,
1555        ) -> FastlyStatus;
1556
1557        #[link_name = "penaltybox_has"]
1558        pub fn penaltybox_has(
1559            pb: *const u8,
1560            pb_max_len: usize,
1561            entry: *const u8,
1562            entry_max_len: usize,
1563            value: *mut u32,
1564        ) -> FastlyStatus;
1565    }
1566}
1567
1568pub mod fastly_kv_store {
1569    use super::*;
1570
1571    #[repr(u32)]
1572    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
1573    pub enum KvError {
1574        Uninitialized,
1575        Ok,
1576        BadRequest,
1577        NotFound,
1578        PreconditionFailed,
1579        PayloadTooLarge,
1580        InternalError,
1581    }
1582
1583    // TODO ACF 2023-04-11: keep the object store name here until the ABI is updated
1584    #[link(wasm_import_module = "fastly_object_store")]
1585    extern "C" {
1586        #[link_name = "open"]
1587        pub fn open(
1588            name_ptr: *const u8,
1589            name_len: usize,
1590            kv_store_handle_out: *mut KVStoreHandle,
1591        ) -> FastlyStatus;
1592
1593        #[deprecated(note = "kept for backward compatibility")]
1594        #[link_name = "lookup"]
1595        pub fn lookup(
1596            kv_store_handle: KVStoreHandle,
1597            key_ptr: *const u8,
1598            key_len: usize,
1599            body_handle_out: *mut BodyHandle,
1600        ) -> FastlyStatus;
1601
1602        #[deprecated(note = "kept for backward compatibility")]
1603        #[link_name = "lookup_async"]
1604        pub fn lookup_async(
1605            kv_store_handle: KVStoreHandle,
1606            key_ptr: *const u8,
1607            key_len: usize,
1608            pending_body_handle_out: *mut PendingObjectStoreLookupHandle,
1609        ) -> FastlyStatus;
1610
1611        #[deprecated(note = "kept for backward compatibility")]
1612        #[link_name = "pending_lookup_wait"]
1613        pub fn pending_lookup_wait(
1614            pending_handle: PendingObjectStoreLookupHandle,
1615            body_handle_out: *mut BodyHandle,
1616        ) -> FastlyStatus;
1617
1618        #[deprecated(note = "kept for backward compatibility")]
1619        #[link_name = "insert"]
1620        pub fn insert(
1621            kv_store_handle: KVStoreHandle,
1622            key_ptr: *const u8,
1623            key_len: usize,
1624            body_handle: BodyHandle,
1625        ) -> FastlyStatus;
1626
1627        #[deprecated(note = "kept for backward compatibility")]
1628        #[link_name = "insert_async"]
1629        pub fn insert_async(
1630            kv_store_handle: KVStoreHandle,
1631            key_ptr: *const u8,
1632            key_len: usize,
1633            body_handle: BodyHandle,
1634            pending_body_handle_out: *mut PendingObjectStoreInsertHandle,
1635        ) -> FastlyStatus;
1636
1637        #[deprecated(note = "kept for backward compatibility")]
1638        #[link_name = "pending_insert_wait"]
1639        pub fn pending_insert_wait(
1640            pending_body_handle: PendingObjectStoreInsertHandle,
1641            kv_error_out: *mut KvError,
1642        ) -> FastlyStatus;
1643
1644        #[deprecated(note = "kept for backward compatibility")]
1645        #[link_name = "delete_async"]
1646        pub fn delete_async(
1647            kv_store_handle: KVStoreHandle,
1648            key_ptr: *const u8,
1649            key_len: usize,
1650            pending_body_handle_out: *mut PendingObjectStoreDeleteHandle,
1651        ) -> FastlyStatus;
1652
1653        #[deprecated(note = "kept for backward compatibility")]
1654        #[link_name = "pending_delete_wait"]
1655        pub fn pending_delete_wait(
1656            pending_body_handle: PendingObjectStoreDeleteHandle,
1657        ) -> FastlyStatus;
1658    }
1659
1660    #[link(wasm_import_module = "fastly_kv_store")]
1661    extern "C" {
1662        #[link_name = "open"]
1663        pub fn open_v2(
1664            name_ptr: *const u8,
1665            name_len: usize,
1666            kv_store_handle_out: *mut KVStoreHandle,
1667        ) -> FastlyStatus;
1668
1669        #[link_name = "lookup"]
1670        pub fn lookup_v2(
1671            kv_store_handle: KVStoreHandle,
1672            key_ptr: *const u8,
1673            key_len: usize,
1674            lookup_config_mask: LookupConfigOptions,
1675            lookup_config: *const LookupConfig,
1676            pending_body_handle_out: *mut PendingObjectStoreLookupHandle,
1677        ) -> FastlyStatus;
1678
1679        #[link_name = "lookup_wait"]
1680        pub fn pending_lookup_wait_v2(
1681            pending_handle: PendingObjectStoreLookupHandle,
1682            body_handle_out: *mut BodyHandle,
1683            metadata_buf: *mut u8,
1684            metadata_buf_len: usize,
1685            nwritten_out: *mut usize,
1686            generation_out: *mut u32,
1687            kv_error_out: *mut KvError,
1688        ) -> FastlyStatus;
1689
1690        #[link_name = "lookup_wait_v2"]
1691        pub fn lookup_wait_v2(
1692            pending_handle: PendingObjectStoreLookupHandle,
1693            body_handle_out: *mut BodyHandle,
1694            metadata_buf: *mut u8,
1695            metadata_buf_len: usize,
1696            nwritten_out: *mut usize,
1697            generation_out: *mut u64,
1698            kv_error_out: *mut KvError,
1699        ) -> FastlyStatus;
1700
1701        #[link_name = "insert"]
1702        pub fn insert_v2(
1703            kv_store_handle: KVStoreHandle,
1704            key_ptr: *const u8,
1705            key_len: usize,
1706            body_handle: BodyHandle,
1707            insert_config_mask: InsertConfigOptions,
1708            insert_config: *const InsertConfig,
1709            pending_body_handle_out: *mut PendingObjectStoreInsertHandle,
1710        ) -> FastlyStatus;
1711
1712        #[link_name = "insert_wait"]
1713        pub fn pending_insert_wait_v2(
1714            pending_body_handle: PendingObjectStoreInsertHandle,
1715            kv_error_out: *mut KvError,
1716        ) -> FastlyStatus;
1717
1718        #[link_name = "delete"]
1719        pub fn delete_v2(
1720            kv_store_handle: KVStoreHandle,
1721            key_ptr: *const u8,
1722            key_len: usize,
1723            delete_config_mask: DeleteConfigOptions,
1724            delete_config: *const DeleteConfig,
1725            pending_body_handle_out: *mut PendingObjectStoreDeleteHandle,
1726        ) -> FastlyStatus;
1727
1728        #[link_name = "delete_wait"]
1729        pub fn pending_delete_wait_v2(
1730            pending_body_handle: PendingObjectStoreDeleteHandle,
1731            kv_error_out: *mut KvError,
1732        ) -> FastlyStatus;
1733
1734        #[link_name = "list"]
1735        pub fn list_v2(
1736            kv_store_handle: KVStoreHandle,
1737            list_config_mask: ListConfigOptions,
1738            list_config: *const ListConfig,
1739            pending_body_handle_out: *mut PendingObjectStoreListHandle,
1740        ) -> FastlyStatus;
1741
1742        #[link_name = "list_wait"]
1743        pub fn pending_list_wait_v2(
1744            pending_body_handle: PendingObjectStoreListHandle,
1745            body_handle_out: *mut BodyHandle,
1746            kv_error_out: *mut KvError,
1747        ) -> FastlyStatus;
1748    }
1749}
1750
1751pub mod fastly_secret_store {
1752    use super::*;
1753
1754    #[link(wasm_import_module = "fastly_secret_store")]
1755    extern "C" {
1756        #[link_name = "open"]
1757        pub fn open(
1758            secret_store_name_ptr: *const u8,
1759            secret_store_name_len: usize,
1760            secret_store_handle_out: *mut SecretStoreHandle,
1761        ) -> FastlyStatus;
1762
1763        #[link_name = "get"]
1764        pub fn get(
1765            secret_store_handle: SecretStoreHandle,
1766            secret_name_ptr: *const u8,
1767            secret_name_len: usize,
1768            secret_handle_out: *mut SecretHandle,
1769        ) -> FastlyStatus;
1770
1771        #[link_name = "plaintext"]
1772        pub fn plaintext(
1773            secret_handle: SecretHandle,
1774            plaintext_buf: *mut u8,
1775            plaintext_max_len: usize,
1776            nwritten_out: *mut usize,
1777        ) -> FastlyStatus;
1778
1779        #[link_name = "from_bytes"]
1780        pub fn from_bytes(
1781            plaintext_buf: *const u8,
1782            plaintext_len: usize,
1783            secret_handle_out: *mut SecretHandle,
1784        ) -> FastlyStatus;
1785    }
1786}
1787
1788pub mod fastly_backend {
1789    use super::*;
1790
1791    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
1792    #[repr(u32)]
1793    pub enum BackendHealth {
1794        Unknown,
1795        Healthy,
1796        Unhealthy,
1797    }
1798
1799    #[link(wasm_import_module = "fastly_backend")]
1800    extern "C" {
1801        #[link_name = "exists"]
1802        pub fn exists(
1803            backend_ptr: *const u8,
1804            backend_len: usize,
1805            backend_exists_out: *mut u32,
1806        ) -> FastlyStatus;
1807
1808        #[link_name = "is_healthy"]
1809        pub fn is_healthy(
1810            backend_ptr: *const u8,
1811            backend_len: usize,
1812            backend_health_out: *mut BackendHealth,
1813        ) -> FastlyStatus;
1814
1815        #[link_name = "is_dynamic"]
1816        pub fn is_dynamic(
1817            backend_ptr: *const u8,
1818            backend_len: usize,
1819            value: *mut u32,
1820        ) -> FastlyStatus;
1821
1822        #[link_name = "get_host"]
1823        pub fn get_host(
1824            backend_ptr: *const u8,
1825            backend_len: usize,
1826            value: *mut u8,
1827            value_max_len: usize,
1828            nwritten: *mut usize,
1829        ) -> FastlyStatus;
1830
1831        #[link_name = "get_override_host"]
1832        pub fn get_override_host(
1833            backend_ptr: *const u8,
1834            backend_len: usize,
1835            value: *mut u8,
1836            value_max_len: usize,
1837            nwritten: *mut usize,
1838        ) -> FastlyStatus;
1839
1840        #[link_name = "get_port"]
1841        pub fn get_port(
1842            backend_ptr: *const u8,
1843            backend_len: usize,
1844            value: *mut u16,
1845        ) -> FastlyStatus;
1846
1847        #[link_name = "get_connect_timeout_ms"]
1848        pub fn get_connect_timeout_ms(
1849            backend_ptr: *const u8,
1850            backend_len: usize,
1851            value: *mut u32,
1852        ) -> FastlyStatus;
1853
1854        #[link_name = "get_first_byte_timeout_ms"]
1855        pub fn get_first_byte_timeout_ms(
1856            backend_ptr: *const u8,
1857            backend_len: usize,
1858            value: *mut u32,
1859        ) -> FastlyStatus;
1860
1861        #[link_name = "get_between_bytes_timeout_ms"]
1862        pub fn get_between_bytes_timeout_ms(
1863            backend_ptr: *const u8,
1864            backend_len: usize,
1865            value: *mut u32,
1866        ) -> FastlyStatus;
1867
1868        #[link_name = "get_http_keepalive_time"]
1869        pub fn get_http_keepalive_time(
1870            backend_ptr: *const u8,
1871            backend_len: usize,
1872            value: *mut u32,
1873        ) -> FastlyStatus;
1874
1875        #[link_name = "get_tcp_keepalive_enable"]
1876        pub fn get_tcp_keepalive_enable(
1877            backend_ptr: *const u8,
1878            backend_len: usize,
1879            value: *mut u32,
1880        ) -> FastlyStatus;
1881
1882        #[link_name = "get_tcp_keepalive_interval"]
1883        pub fn get_tcp_keepalive_interval(
1884            backend_ptr: *const u8,
1885            backend_len: usize,
1886            value: *mut u32,
1887        ) -> FastlyStatus;
1888
1889        #[link_name = "get_tcp_keepalive_probes"]
1890        pub fn get_tcp_keepalive_probes(
1891            backend_ptr: *const u8,
1892            backend_len: usize,
1893            value: *mut u32,
1894        ) -> FastlyStatus;
1895
1896        #[link_name = "get_tcp_keepalive_time"]
1897        pub fn get_tcp_keepalive_time(
1898            backend_ptr: *const u8,
1899            backend_len: usize,
1900            value: *mut u32,
1901        ) -> FastlyStatus;
1902
1903        #[link_name = "is_ssl"]
1904        pub fn is_ssl(backend_ptr: *const u8, backend_len: usize, value: *mut u32) -> FastlyStatus;
1905
1906        #[link_name = "get_ssl_min_version"]
1907        pub fn get_ssl_min_version(
1908            backend_ptr: *const u8,
1909            backend_len: usize,
1910            value: *mut u32,
1911        ) -> FastlyStatus;
1912
1913        #[link_name = "get_ssl_max_version"]
1914        pub fn get_ssl_max_version(
1915            backend_ptr: *const u8,
1916            backend_len: usize,
1917            value: *mut u32,
1918        ) -> FastlyStatus;
1919    }
1920}
1921
1922pub mod fastly_async_io {
1923    use super::*;
1924
1925    #[link(wasm_import_module = "fastly_async_io")]
1926    extern "C" {
1927        #[link_name = "select"]
1928        pub fn select(
1929            async_item_handles: *const AsyncItemHandle,
1930            async_item_handles_len: usize,
1931            timeout_ms: u32,
1932            done_index_out: *mut u32,
1933        ) -> FastlyStatus;
1934
1935        #[link_name = "is_ready"]
1936        pub fn is_ready(async_item_handle: AsyncItemHandle, ready_out: *mut u32) -> FastlyStatus;
1937    }
1938}
1939
1940pub mod fastly_image_optimizer {
1941    use super::*;
1942
1943    bitflags::bitflags! {
1944        #[repr(transparent)]
1945        pub struct ImageOptimizerTransformConfigOptions: u32 {
1946            const RESERVED = 1 << 0;
1947            const SDK_CLAIMS_OPTS = 1 << 1;
1948        }
1949    }
1950
1951    #[repr(C, align(8))]
1952    pub struct ImageOptimizerTransformConfig {
1953        pub sdk_claims_opts: *const u8,
1954        pub sdk_claims_opts_len: u32,
1955    }
1956
1957    impl Default for ImageOptimizerTransformConfig {
1958        fn default() -> Self {
1959            ImageOptimizerTransformConfig {
1960                sdk_claims_opts: std::ptr::null(),
1961                sdk_claims_opts_len: 0,
1962            }
1963        }
1964    }
1965
1966    #[repr(u32)]
1967    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
1968    pub enum ImageOptimizerErrorTag {
1969        Uninitialized,
1970        Ok,
1971        Error,
1972        Warning,
1973    }
1974
1975    #[repr(C, align(8))]
1976    #[derive(Clone, Debug, PartialEq, Eq)]
1977    pub struct ImageOptimizerErrorDetail {
1978        pub tag: ImageOptimizerErrorTag,
1979        pub message: *const u8,
1980        pub message_len: usize,
1981    }
1982
1983    impl ImageOptimizerErrorDetail {
1984        pub fn uninitialized() -> Self {
1985            Self {
1986                tag: ImageOptimizerErrorTag::Uninitialized,
1987                message: std::ptr::null(),
1988                message_len: 0,
1989            }
1990        }
1991    }
1992
1993    #[link(wasm_import_module = "fastly_image_optimizer")]
1994    extern "C" {
1995        #[link_name = "transform_image_optimizer_request"]
1996        pub fn transform_image_optimizer_request(
1997            origin_image_request: RequestHandle,
1998            origin_image_request_body: BodyHandle,
1999            origin_image_backend: *const u8,
2000            origin_image_backend_len: usize,
2001            io_transform_config_options: ImageOptimizerTransformConfigOptions,
2002            io_transform_config: *const ImageOptimizerTransformConfig,
2003            io_error_detail: *mut ImageOptimizerErrorDetail,
2004            resp_handle_out: *mut ResponseHandle,
2005            resp_body_handle_out: *mut BodyHandle,
2006        ) -> FastlyStatus;
2007    }
2008}
2009
2010pub mod fastly_purge {
2011    use super::*;
2012
2013    bitflags::bitflags! {
2014        #[derive(Default)]
2015        #[repr(transparent)]
2016        pub struct PurgeOptionsMask: u32 {
2017            const SOFT_PURGE = 1 << 0;
2018            const RET_BUF = 1 << 1;
2019        }
2020    }
2021
2022    #[derive(Debug)]
2023    #[repr(C)]
2024    pub struct PurgeOptions {
2025        pub ret_buf_ptr: *mut u8,
2026        pub ret_buf_len: usize,
2027        pub ret_buf_nwritten_out: *mut usize,
2028    }
2029
2030    #[link(wasm_import_module = "fastly_purge")]
2031    extern "C" {
2032        #[link_name = "purge_surrogate_key"]
2033        pub fn purge_surrogate_key(
2034            surrogate_key_ptr: *const u8,
2035            surrogate_key_len: usize,
2036            options_mask: PurgeOptionsMask,
2037            options: *mut PurgeOptions,
2038        ) -> FastlyStatus;
2039    }
2040}
2041
2042pub mod fastly_compute_runtime {
2043    use super::*;
2044
2045    #[link(wasm_import_module = "fastly_compute_runtime")]
2046    extern "C" {
2047        #[link_name = "get_vcpu_ms"]
2048        pub fn get_vcpu_ms(ms_out: *mut u64) -> FastlyStatus;
2049    }
2050
2051    #[link(wasm_import_module = "fastly_compute_runtime")]
2052    extern "C" {
2053        #[link_name = "get_heap_mib"]
2054        pub fn get_heap_mib(mb_out: *mut u32) -> fastly_shared::FastlyStatus;
2055    }
2056
2057    #[link(wasm_import_module = "fastly_compute_runtime")]
2058    extern "C" {
2059        #[link_name = "has_domain_inspector"]
2060        pub fn has_domain_inspector(mb_out: *mut u32) -> fastly_shared::FastlyStatus;
2061    }
2062
2063    #[link(wasm_import_module = "fastly_compute_runtime")]
2064    extern "C" {
2065        #[link_name = "has_image_optimizer"]
2066        pub fn has_image_optimizer(mb_out: *mut u32) -> fastly_shared::FastlyStatus;
2067    }
2068
2069    #[link(wasm_import_module = "fastly_compute_runtime")]
2070    extern "C" {
2071        #[link_name = "has_origin_inspector"]
2072        pub fn has_origin_inspector(mb_out: *mut u32) -> fastly_shared::FastlyStatus;
2073    }
2074}
2075
2076pub mod fastly_acl {
2077    use super::*;
2078
2079    #[repr(u32)]
2080    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
2081    pub enum AclError {
2082        Uninitialized,
2083        Ok,
2084        NoContent,
2085        TooManyRequests,
2086    }
2087
2088    #[link(wasm_import_module = "fastly_acl")]
2089    extern "C" {
2090        #[link_name = "open"]
2091        pub fn open(
2092            acl_name_ptr: *const u8,
2093            acl_name_len: usize,
2094            acl_handle_out: *mut AclHandle,
2095        ) -> FastlyStatus;
2096
2097        #[link_name = "lookup"]
2098        pub fn lookup(
2099            acl_handle: AclHandle,
2100            ip_octets: *const u8,
2101            ip_len: usize,
2102            body_handle_out: *mut BodyHandle,
2103            acl_error_out: *mut AclError,
2104        ) -> FastlyStatus;
2105    }
2106}
2107
2108pub mod fastly_shielding {
2109    use super::*;
2110
2111    bitflags::bitflags! {
2112        #[derive(Default)]
2113        #[repr(transparent)]
2114        pub struct ShieldBackendOptions: u32 {
2115            const RESERVED = 1 << 0;
2116            const CACHE_KEY = 1 << 1;
2117            const FIRST_BYTE_TIMEOUT = 1 << 2;
2118            const BETWEEN_BYTES_TIMEOUT = 1 << 3;
2119        }
2120    }
2121
2122    #[repr(C)]
2123    pub struct ShieldBackendConfig {
2124        pub cache_key: *const u8,
2125        pub cache_key_len: u32,
2126        pub first_byte_timeout_ms: u32,
2127        pub between_bytes_timeout_ms: u32,
2128    }
2129
2130    impl Default for ShieldBackendConfig {
2131        fn default() -> Self {
2132            ShieldBackendConfig {
2133                cache_key: std::ptr::null(),
2134                cache_key_len: 0,
2135                first_byte_timeout_ms: 0,
2136                between_bytes_timeout_ms: 0,
2137            }
2138        }
2139    }
2140
2141    //   (@interface func (export "shield_info")
2142    //     (param $name string)
2143    //     (param $info_block (@witx pointer (@witx char8)))
2144    //     (param $info_block_max_len (@witx usize))
2145    //     (result $err (expected $num_bytes (error $fastly_status)))
2146    //   )
2147
2148    #[link(wasm_import_module = "fastly_shielding")]
2149    extern "C" {
2150
2151        /// Get information about the given shield in the Fastly network
2152        #[link_name = "shield_info"]
2153        pub fn shield_info(
2154            name: *const u8,
2155            name_len: usize,
2156            info_block: *mut u8,
2157            info_block_len: usize,
2158            nwritten_out: *mut u32,
2159        ) -> FastlyStatus;
2160
2161        /// Turn a pop name into a backend that we can send requests to.
2162        #[link_name = "backend_for_shield"]
2163        pub fn backend_for_shield(
2164            name: *const u8,
2165            name_len: usize,
2166            options_mask: ShieldBackendOptions,
2167            options: *const ShieldBackendConfig,
2168            backend_name: *mut u8,
2169            backend_name_len: usize,
2170            nwritten_out: *mut u32,
2171        ) -> FastlyStatus;
2172    }
2173}
2174
2175/// WIT for the Fastly APIs in the `fastly:compute/service@0.1.0` world.
2176#[cfg(not(target_env = "p1"))]
2177pub mod service_0_1;
2178
2179#[cfg(not(target_env = "p1"))]
2180impl From<service_0_1::fastly::compute::types::Error> for fastly_shared::FastlyStatus {
2181    fn from(error: service_0_1::fastly::compute::types::Error) -> Self {
2182        use service_0_1::fastly::compute::types::Error;
2183        match error {
2184            Error::InvalidArgument => Self::INVAL,
2185            Error::Unsupported => Self::UNSUPPORTED,
2186            Error::LimitExceeded => Self::LIMITEXCEEDED,
2187            Error::GenericError => Self::ERROR,
2188            Error::BufferLen(_) => Self::BUFLEN,
2189            Error::CannotRead => Self::NONE,
2190            Error::AuxiliaryError => Self::BADF,
2191            Error::HttpInvalid => Self::HTTPINVALID,
2192            Error::HttpUser => Self::HTTPUSER,
2193            Error::HttpIncomplete => Self::HTTPINCOMPLETE,
2194            Error::HttpHeadTooLarge => Self::HTTPHEADTOOLARGE,
2195            Error::HttpInvalidStatus => Self::HTTPINVALIDSTATUS,
2196        }
2197    }
2198}
2199
2200#[cfg(not(target_env = "p1"))]
2201impl From<std::net::IpAddr> for service_0_1::fastly::compute::types::IpAddress {
2202    fn from(addr: std::net::IpAddr) -> Self {
2203        use std::net::IpAddr;
2204        match addr {
2205            IpAddr::V4(v4) => Self::Ipv4(v4.octets().into()),
2206            IpAddr::V6(v6) => Self::Ipv6(v6.segments().into()),
2207        }
2208    }
2209}
2210
2211#[cfg(not(target_env = "p1"))]
2212impl From<service_0_1::fastly::compute::types::IpAddress> for std::net::IpAddr {
2213    fn from(addr: service_0_1::fastly::compute::types::IpAddress) -> Self {
2214        use service_0_1::fastly::compute::types::IpAddress;
2215        match addr {
2216            IpAddress::Ipv4(v4) => Self::V4(<[u8; 4]>::from(v4).into()),
2217            IpAddress::Ipv6(v6) => Self::V6(<[u16; 8]>::from(v6).into()),
2218        }
2219    }
2220}
2221
2222#[cfg(not(target_env = "p1"))]
2223impl From<service_0_1::fastly::compute::http_types::HttpVersion> for http::version::Version {
2224    fn from(version: service_0_1::fastly::compute::http_types::HttpVersion) -> Self {
2225        use service_0_1::fastly::compute::http_types::HttpVersion;
2226        match version {
2227            HttpVersion::Http09 => Self::HTTP_09,
2228            HttpVersion::Http10 => Self::HTTP_10,
2229            HttpVersion::Http11 => Self::HTTP_11,
2230            HttpVersion::H2 => Self::HTTP_2,
2231            HttpVersion::H3 => Self::HTTP_3,
2232        }
2233    }
2234}
2235
2236#[cfg(not(target_env = "p1"))]
2237impl TryFrom<http::version::Version> for service_0_1::fastly::compute::http_types::HttpVersion {
2238    type Error = ();
2239
2240    fn try_from(version: http::version::Version) -> Result<Self, Self::Error> {
2241        use http::version::Version;
2242        Ok(match version {
2243            Version::HTTP_09 => Self::Http09,
2244            Version::HTTP_10 => Self::Http10,
2245            Version::HTTP_11 => Self::Http11,
2246            Version::HTTP_2 => Self::H2,
2247            Version::HTTP_3 => Self::H3,
2248            _ => return Err(()),
2249        })
2250    }
2251}
2252
2253#[cfg(not(target_env = "p1"))]
2254impl From<fastly_shared::FramingHeadersMode>
2255    for service_0_1::fastly::compute::http_types::FramingHeadersMode
2256{
2257    fn from(mode: fastly_shared::FramingHeadersMode) -> Self {
2258        use fastly_shared::FramingHeadersMode;
2259        match mode {
2260            FramingHeadersMode::Automatic => Self::Automatic,
2261            FramingHeadersMode::ManuallyFromHeaders => Self::ManuallyFromHeaders,
2262        }
2263    }
2264}
2265
2266#[cfg(not(target_env = "p1"))]
2267impl From<service_0_1::fastly::compute::http_types::FramingHeadersMode>
2268    for fastly_shared::FramingHeadersMode
2269{
2270    fn from(mode: service_0_1::fastly::compute::http_types::FramingHeadersMode) -> Self {
2271        use service_0_1::fastly::compute::http_types::FramingHeadersMode;
2272        match mode {
2273            FramingHeadersMode::Automatic => Self::Automatic,
2274            FramingHeadersMode::ManuallyFromHeaders => Self::ManuallyFromHeaders,
2275        }
2276    }
2277}
2278
2279#[cfg(not(target_env = "p1"))]
2280impl From<fastly_shared::HttpKeepaliveMode>
2281    for service_0_1::fastly::compute::http_resp::KeepaliveMode
2282{
2283    fn from(mode: fastly_shared::HttpKeepaliveMode) -> Self {
2284        use fastly_shared::HttpKeepaliveMode;
2285        match mode {
2286            HttpKeepaliveMode::Automatic => Self::Automatic,
2287            HttpKeepaliveMode::NoKeepalive => Self::NoKeepalive,
2288        }
2289    }
2290}
2291
2292#[cfg(not(target_env = "p1"))]
2293impl From<service_0_1::fastly::compute::http_resp::KeepaliveMode>
2294    for fastly_shared::HttpKeepaliveMode
2295{
2296    fn from(mode: service_0_1::fastly::compute::http_resp::KeepaliveMode) -> Self {
2297        use service_0_1::fastly::compute::http_resp::KeepaliveMode;
2298        match mode {
2299            KeepaliveMode::Automatic => Self::Automatic,
2300            KeepaliveMode::NoKeepalive => Self::NoKeepalive,
2301        }
2302    }
2303}