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}
704
705pub mod fastly_http_req {
706    use super::*;
707
708    bitflags::bitflags! {
709        #[derive(Default)]
710        #[repr(transparent)]
711        pub struct SendErrorDetailMask: u32 {
712            const RESERVED = 1 << 0;
713            const DNS_ERROR_RCODE = 1 << 1;
714            const DNS_ERROR_INFO_CODE = 1 << 2;
715            const TLS_ALERT_ID = 1 << 3;
716            const H2_ERROR = 1 << 4;
717        }
718    }
719
720    /// What types of responses to a `PendingRequestHandle` a queued operation
721    /// should apply to.
722    #[repr(u32)]
723    #[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
724    pub enum PendingResponseKind {
725        /// Apply the change to any response, regardless of whether it's a real one
726        /// or a synthetic response generated after a request error.
727        #[default]
728        Any = 0,
729
730        /// Only apply the change to an actual response, and skip synthetic responses.  
731        Response = 1,
732
733        /// Only apply the change to a synthetic error response, and skip real responses.
734        Error = 2,
735    }
736
737    #[repr(u32)]
738    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
739    #[non_exhaustive]
740    pub enum SendErrorDetailTag {
741        Uninitialized,
742        Ok,
743        DnsTimeout,
744        DnsError,
745        DestinationNotFound,
746        DestinationUnavailable,
747        DestinationIpUnroutable,
748        ConnectionRefused,
749        ConnectionTerminated,
750        ConnectionTimeout,
751        ConnectionLimitReached,
752        TlsCertificateError,
753        TlsConfigurationError,
754        HttpIncompleteResponse,
755        HttpResponseHeaderSectionTooLarge,
756        HttpResponseBodyTooLarge,
757        HttpResponseTimeout,
758        HttpResponseStatusInvalid,
759        HttpUpgradeFailed,
760        HttpProtocolError,
761        HttpRequestCacheKeyInvalid,
762        HttpRequestUriInvalid,
763        InternalError,
764        TlsAlertReceived,
765        TlsProtocolError,
766        H2Error,
767    }
768
769    #[repr(C)]
770    #[derive(Clone, Debug, PartialEq, Eq)]
771    #[non_exhaustive]
772    pub struct SendErrorDetail {
773        pub tag: SendErrorDetailTag,
774        pub mask: SendErrorDetailMask,
775        pub dns_error_rcode: u16,
776        pub dns_error_info_code: u16,
777        pub tls_alert_id: u8,
778        pub h2_error_frame: u8,
779        pub h2_error_code: u32,
780    }
781
782    impl SendErrorDetail {
783        pub fn uninitialized_all() -> Self {
784            Self {
785                tag: SendErrorDetailTag::Uninitialized,
786                mask: SendErrorDetailMask::all(),
787                dns_error_rcode: Default::default(),
788                dns_error_info_code: Default::default(),
789                tls_alert_id: Default::default(),
790                h2_error_frame: Default::default(),
791                h2_error_code: Default::default(),
792            }
793        }
794    }
795
796    bitflags::bitflags! {
797        #[repr(transparent)]
798        pub struct InspectInfoMask: u32 {
799            const RESERVED = 1 << 0;
800            const CORP = 1 << 1;
801            const WORKSPACE = 1 << 2;
802            const OVERRIDE_CLIENT_IP = 1 << 3;
803        }
804    }
805
806    #[repr(C)]
807    pub struct InspectInfo {
808        pub corp: *const u8,
809        pub corp_len: u32,
810        pub workspace: *const u8,
811        pub workspace_len: u32,
812        pub override_client_ip_ptr: *const u8,
813        pub override_client_ip_len: u32,
814    }
815
816    impl Default for InspectInfo {
817        fn default() -> Self {
818            InspectInfo {
819                corp: std::ptr::null(),
820                corp_len: 0,
821                workspace: std::ptr::null(),
822                workspace_len: 0,
823                override_client_ip_ptr: std::ptr::null(),
824                override_client_ip_len: 0,
825            }
826        }
827    }
828
829    #[link(wasm_import_module = "fastly_http_req")]
830    extern "C" {
831        #[link_name = "body_downstream_get"]
832        pub fn body_downstream_get(
833            req_handle_out: *mut RequestHandle,
834            body_handle_out: *mut BodyHandle,
835        ) -> FastlyStatus;
836
837        #[link_name = "cache_override_set"]
838        pub fn cache_override_set(
839            req_handle: RequestHandle,
840            tag: u32,
841            ttl: u32,
842            swr: u32,
843        ) -> FastlyStatus;
844
845        #[link_name = "cache_override_v2_set"]
846        pub fn cache_override_v2_set(
847            req_handle: RequestHandle,
848            tag: u32,
849            ttl: u32,
850            swr: u32,
851            sk: *const u8,
852            sk_len: usize,
853        ) -> FastlyStatus;
854
855        #[link_name = "cache_override_v3_set"]
856        pub fn cache_override_v3_set(
857            req_handle: RequestHandle,
858            tag: u32,
859            cache_override_ptr: *const CacheOverride,
860        ) -> FastlyStatus;
861
862        #[link_name = "framing_headers_mode_set"]
863        pub fn framing_headers_mode_set(
864            req_handle: RequestHandle,
865            mode: fastly_shared::FramingHeadersMode,
866        ) -> FastlyStatus;
867
868        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
869        #[link_name = "downstream_client_ip_addr"]
870        pub fn downstream_client_ip_addr(
871            addr_octets_out: *mut u8,
872            nwritten_out: *mut usize,
873        ) -> FastlyStatus;
874
875        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
876        #[link_name = "downstream_server_ip_addr"]
877        pub fn downstream_server_ip_addr(
878            addr_octets_out: *mut u8,
879            nwritten_out: *mut usize,
880        ) -> FastlyStatus;
881
882        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
883        #[link_name = "downstream_client_h2_fingerprint"]
884        pub fn downstream_client_h2_fingerprint(
885            h2fp_out: *mut u8,
886            h2fp_max_len: usize,
887            nwritten: *mut usize,
888        ) -> FastlyStatus;
889
890        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
891        #[link_name = "downstream_client_request_id"]
892        pub fn downstream_client_request_id(
893            reqid_out: *mut u8,
894            reqid_max_len: usize,
895            nwritten: *mut usize,
896        ) -> FastlyStatus;
897
898        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
899        #[link_name = "downstream_client_oh_fingerprint"]
900        pub fn downstream_client_oh_fingerprint(
901            ohfp_out: *mut u8,
902            ohfp_max_len: usize,
903            nwritten: *mut usize,
904        ) -> FastlyStatus;
905
906        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
907        #[link_name = "downstream_client_ddos_detected"]
908        pub fn downstream_client_ddos_detected(ddos_detected_out: *mut u32) -> FastlyStatus;
909
910        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
911        #[link_name = "downstream_tls_cipher_openssl_name"]
912        pub fn downstream_tls_cipher_openssl_name(
913            cipher_out: *mut u8,
914            cipher_max_len: usize,
915            nwritten: *mut usize,
916        ) -> FastlyStatus;
917
918        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
919        #[link_name = "downstream_tls_protocol"]
920        pub fn downstream_tls_protocol(
921            protocol_out: *mut u8,
922            protocol_max_len: usize,
923            nwritten: *mut usize,
924        ) -> FastlyStatus;
925
926        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
927        #[link_name = "downstream_tls_client_hello"]
928        pub fn downstream_tls_client_hello(
929            client_hello_out: *mut u8,
930            client_hello_max_len: usize,
931            nwritten: *mut usize,
932        ) -> FastlyStatus;
933
934        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
935        #[link_name = "downstream_tls_ja3_md5"]
936        pub fn downstream_tls_ja3_md5(
937            ja3_md5_out: *mut u8,
938            nwritten_out: *mut usize,
939        ) -> FastlyStatus;
940
941        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
942        #[link_name = "downstream_tls_ja4"]
943        pub fn downstream_tls_ja4(
944            ja4_out: *mut u8,
945            ja4_max_len: usize,
946            nwritten: *mut usize,
947        ) -> FastlyStatus;
948
949        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
950        #[link_name = "downstream_compliance_region"]
951        pub fn downstream_compliance_region(
952            region_out: *mut u8,
953            region_max_len: usize,
954            nwritten: *mut usize,
955        ) -> FastlyStatus;
956
957        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
958        #[link_name = "downstream_tls_raw_client_certificate"]
959        pub fn downstream_tls_raw_client_certificate(
960            client_hello_out: *mut u8,
961            client_hello_max_len: usize,
962            nwritten: *mut usize,
963        ) -> FastlyStatus;
964
965        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
966        #[link_name = "downstream_tls_client_cert_verify_result"]
967        pub fn downstream_tls_client_cert_verify_result(
968            verify_result_out: *mut u32,
969        ) -> FastlyStatus;
970
971        #[link_name = "header_append"]
972        pub fn header_append(
973            req_handle: RequestHandle,
974            name: *const u8,
975            name_len: usize,
976            value: *const u8,
977            value_len: usize,
978        ) -> FastlyStatus;
979
980        #[link_name = "header_insert"]
981        pub fn header_insert(
982            req_handle: RequestHandle,
983            name: *const u8,
984            name_len: usize,
985            value: *const u8,
986            value_len: usize,
987        ) -> FastlyStatus;
988
989        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
990        #[link_name = "original_header_names_get"]
991        pub fn original_header_names_get(
992            buf: *mut u8,
993            buf_len: usize,
994            cursor: u32,
995            ending_cursor: *mut i64,
996            nwritten: *mut usize,
997        ) -> FastlyStatus;
998
999        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
1000        #[link_name = "original_header_count"]
1001        pub fn original_header_count(count_out: *mut u32) -> FastlyStatus;
1002
1003        #[link_name = "header_names_get"]
1004        pub fn header_names_get(
1005            req_handle: RequestHandle,
1006            buf: *mut u8,
1007            buf_len: usize,
1008            cursor: u32,
1009            ending_cursor: *mut i64,
1010            nwritten: *mut usize,
1011        ) -> FastlyStatus;
1012
1013        #[link_name = "header_values_get"]
1014        pub fn header_values_get(
1015            req_handle: RequestHandle,
1016            name: *const u8,
1017            name_len: usize,
1018            buf: *mut u8,
1019            buf_len: usize,
1020            cursor: u32,
1021            ending_cursor: *mut i64,
1022            nwritten: *mut usize,
1023        ) -> FastlyStatus;
1024
1025        #[link_name = "header_values_set"]
1026        pub fn header_values_set(
1027            req_handle: RequestHandle,
1028            name: *const u8,
1029            name_len: usize,
1030            values: *const u8,
1031            values_len: usize,
1032        ) -> FastlyStatus;
1033
1034        #[link_name = "header_value_get"]
1035        pub fn header_value_get(
1036            req_handle: RequestHandle,
1037            name: *const u8,
1038            name_len: usize,
1039            value: *mut u8,
1040            value_max_len: usize,
1041            nwritten: *mut usize,
1042        ) -> FastlyStatus;
1043
1044        #[link_name = "header_remove"]
1045        pub fn header_remove(
1046            req_handle: RequestHandle,
1047            name: *const u8,
1048            name_len: usize,
1049        ) -> FastlyStatus;
1050
1051        #[link_name = "method_get"]
1052        pub fn method_get(
1053            req_handle: RequestHandle,
1054            method: *mut u8,
1055            method_max_len: usize,
1056            nwritten: *mut usize,
1057        ) -> FastlyStatus;
1058
1059        #[link_name = "method_set"]
1060        pub fn method_set(
1061            req_handle: RequestHandle,
1062            method: *const u8,
1063            method_len: usize,
1064        ) -> FastlyStatus;
1065
1066        #[link_name = "new"]
1067        pub fn new(req_handle_out: *mut RequestHandle) -> FastlyStatus;
1068
1069        #[link_name = "send_v2"]
1070        pub fn send_v2(
1071            req_handle: RequestHandle,
1072            body_handle: BodyHandle,
1073            backend: *const u8,
1074            backend_len: usize,
1075            error_detail: *mut SendErrorDetail,
1076            resp_handle_out: *mut ResponseHandle,
1077            resp_body_handle_out: *mut BodyHandle,
1078        ) -> FastlyStatus;
1079
1080        #[link_name = "send_v3"]
1081        pub fn send_v3(
1082            req_handle: RequestHandle,
1083            body_handle: BodyHandle,
1084            backend: *const u8,
1085            backend_len: usize,
1086            error_detail: *mut SendErrorDetail,
1087            resp_handle_out: *mut ResponseHandle,
1088            resp_body_handle_out: *mut BodyHandle,
1089        ) -> FastlyStatus;
1090
1091        #[link_name = "send_async"]
1092        pub fn send_async(
1093            req_handle: RequestHandle,
1094            body_handle: BodyHandle,
1095            backend: *const u8,
1096            backend_len: usize,
1097            pending_req_handle_out: *mut PendingRequestHandle,
1098        ) -> FastlyStatus;
1099
1100        #[link_name = "send_async_streaming"]
1101        pub fn send_async_streaming(
1102            req_handle: RequestHandle,
1103            body_handle: BodyHandle,
1104            backend: *const u8,
1105            backend_len: usize,
1106            pending_req_handle_out: *mut PendingRequestHandle,
1107        ) -> FastlyStatus;
1108
1109        #[link_name = "send_async_v2"]
1110        pub fn send_async_v2(
1111            req_handle: RequestHandle,
1112            body_handle: BodyHandle,
1113            backend: *const u8,
1114            backend_len: usize,
1115            streaming: u32,
1116            pending_req_handle_out: *mut PendingRequestHandle,
1117        ) -> FastlyStatus;
1118
1119        #[link_name = "upgrade_websocket"]
1120        pub fn upgrade_websocket(backend: *const u8, backend_len: usize) -> FastlyStatus;
1121
1122        #[link_name = "redirect_to_websocket_proxy_v2"]
1123        pub fn redirect_to_websocket_proxy_v2(
1124            req: RequestHandle,
1125            backend: *const u8,
1126            backend_len: usize,
1127        ) -> FastlyStatus;
1128
1129        #[link_name = "redirect_to_grip_proxy_v2"]
1130        pub fn redirect_to_grip_proxy_v2(
1131            req: RequestHandle,
1132            backend: *const u8,
1133            backend_len: usize,
1134        ) -> FastlyStatus;
1135
1136        #[link_name = "register_dynamic_backend"]
1137        pub fn register_dynamic_backend(
1138            name_prefix: *const u8,
1139            name_prefix_len: usize,
1140            target: *const u8,
1141            target_len: usize,
1142            config_mask: BackendConfigOptions,
1143            config: *const DynamicBackendConfig,
1144        ) -> FastlyStatus;
1145
1146        #[link_name = "uri_get"]
1147        pub fn uri_get(
1148            req_handle: RequestHandle,
1149            uri: *mut u8,
1150            uri_max_len: usize,
1151            nwritten: *mut usize,
1152        ) -> FastlyStatus;
1153
1154        #[link_name = "uri_set"]
1155        pub fn uri_set(req_handle: RequestHandle, uri: *const u8, uri_len: usize) -> FastlyStatus;
1156
1157        #[link_name = "version_get"]
1158        pub fn version_get(req_handle: RequestHandle, version: *mut u32) -> FastlyStatus;
1159
1160        #[link_name = "version_set"]
1161        pub fn version_set(req_handle: RequestHandle, version: u32) -> FastlyStatus;
1162
1163        #[link_name = "pending_req_header_append"]
1164        pub fn pending_req_header_append(
1165            pending_req_handle: PendingRequestHandle,
1166            name: *const u8,
1167            name_len: usize,
1168            value: *const u8,
1169            value_len: usize,
1170            target: PendingResponseKind,
1171        ) -> FastlyStatus;
1172
1173        #[link_name = "pending_req_header_insert"]
1174        pub fn pending_req_header_insert(
1175            pending_req_handle: PendingRequestHandle,
1176            name: *const u8,
1177            name_len: usize,
1178            value: *const u8,
1179            value_len: usize,
1180            target: PendingResponseKind,
1181        ) -> FastlyStatus;
1182
1183        #[link_name = "pending_req_header_remove"]
1184        pub fn pending_req_header_remove(
1185            pending_req_handle: PendingRequestHandle,
1186            name: *const u8,
1187            name_len: usize,
1188            target: PendingResponseKind,
1189        ) -> FastlyStatus;
1190
1191        #[link_name = "pending_req_poll_v2"]
1192        pub fn pending_req_poll_v2(
1193            pending_req_handle: PendingRequestHandle,
1194            error_detail: *mut SendErrorDetail,
1195            is_done_out: *mut i32,
1196            resp_handle_out: *mut ResponseHandle,
1197            resp_body_handle_out: *mut BodyHandle,
1198        ) -> FastlyStatus;
1199
1200        #[link_name = "pending_req_select_v2"]
1201        pub fn pending_req_select_v2(
1202            pending_req_handles: *const PendingRequestHandle,
1203            pending_req_handles_len: usize,
1204            error_detail: *mut SendErrorDetail,
1205            done_index_out: *mut i32,
1206            resp_handle_out: *mut ResponseHandle,
1207            resp_body_handle_out: *mut BodyHandle,
1208        ) -> FastlyStatus;
1209
1210        #[link_name = "pending_req_wait_v2"]
1211        pub fn pending_req_wait_v2(
1212            pending_req_handle: PendingRequestHandle,
1213            error_detail: *mut SendErrorDetail,
1214            resp_handle_out: *mut ResponseHandle,
1215            resp_body_handle_out: *mut BodyHandle,
1216        ) -> FastlyStatus;
1217
1218        #[deprecated(since = "0.12.0", note = "kept for backward compatibility")]
1219        #[link_name = "fastly_key_is_valid"]
1220        pub fn fastly_key_is_valid(is_valid_out: *mut u32) -> FastlyStatus;
1221
1222        #[link_name = "close"]
1223        pub fn close(req_handle: RequestHandle) -> FastlyStatus;
1224
1225        #[link_name = "auto_decompress_response_set"]
1226        pub fn auto_decompress_response_set(
1227            req_handle: RequestHandle,
1228            encodings: ContentEncodings,
1229        ) -> FastlyStatus;
1230
1231        #[link_name = "inspect"]
1232        pub fn inspect(
1233            request_handle: RequestHandle,
1234            body_handle: BodyHandle,
1235            add_info_mask: InspectInfoMask,
1236            add_info: *const InspectInfo,
1237            buf: *mut u8,
1238            buf_len: usize,
1239            nwritten: *mut usize,
1240        ) -> FastlyStatus;
1241
1242        #[link_name = "on_behalf_of"]
1243        pub fn on_behalf_of(
1244            request_handle: RequestHandle,
1245            service: *const u8,
1246            service_len: usize,
1247        ) -> FastlyStatus;
1248    }
1249}
1250
1251pub mod fastly_http_resp {
1252    use super::*;
1253
1254    #[link(wasm_import_module = "fastly_http_resp")]
1255    extern "C" {
1256        #[link_name = "header_append"]
1257        pub fn header_append(
1258            resp_handle: ResponseHandle,
1259            name: *const u8,
1260            name_len: usize,
1261            value: *const u8,
1262            value_len: usize,
1263        ) -> FastlyStatus;
1264
1265        #[link_name = "header_insert"]
1266        pub fn header_insert(
1267            resp_handle: ResponseHandle,
1268            name: *const u8,
1269            name_len: usize,
1270            value: *const u8,
1271            value_len: usize,
1272        ) -> FastlyStatus;
1273
1274        #[link_name = "header_names_get"]
1275        pub fn header_names_get(
1276            resp_handle: ResponseHandle,
1277            buf: *mut u8,
1278            buf_len: usize,
1279            cursor: u32,
1280            ending_cursor: *mut i64,
1281            nwritten: *mut usize,
1282        ) -> FastlyStatus;
1283
1284        #[link_name = "header_value_get"]
1285        pub fn header_value_get(
1286            resp_handle: ResponseHandle,
1287            name: *const u8,
1288            name_len: usize,
1289            value: *mut u8,
1290            value_max_len: usize,
1291            nwritten: *mut usize,
1292        ) -> FastlyStatus;
1293
1294        #[link_name = "header_values_get"]
1295        pub fn header_values_get(
1296            resp_handle: ResponseHandle,
1297            name: *const u8,
1298            name_len: usize,
1299            buf: *mut u8,
1300            buf_len: usize,
1301            cursor: u32,
1302            ending_cursor: *mut i64,
1303            nwritten: *mut usize,
1304        ) -> FastlyStatus;
1305
1306        #[link_name = "header_values_set"]
1307        pub fn header_values_set(
1308            resp_handle: ResponseHandle,
1309            name: *const u8,
1310            name_len: usize,
1311            values: *const u8,
1312            values_len: usize,
1313        ) -> FastlyStatus;
1314
1315        #[link_name = "header_remove"]
1316        pub fn header_remove(
1317            resp_handle: ResponseHandle,
1318            name: *const u8,
1319            name_len: usize,
1320        ) -> FastlyStatus;
1321
1322        #[link_name = "new"]
1323        pub fn new(resp_handle_out: *mut ResponseHandle) -> FastlyStatus;
1324
1325        #[link_name = "send_downstream"]
1326        pub fn send_downstream(
1327            resp_handle: ResponseHandle,
1328            body_handle: BodyHandle,
1329            streaming: u32,
1330        ) -> FastlyStatus;
1331
1332        #[link_name = "send_downstream_pending"]
1333        pub fn send_downstream_pending(pending_req_handle: PendingRequestHandle) -> FastlyStatus;
1334
1335        #[link_name = "status_get"]
1336        pub fn status_get(resp_handle: ResponseHandle, status: *mut u16) -> FastlyStatus;
1337
1338        #[link_name = "status_set"]
1339        pub fn status_set(resp_handle: ResponseHandle, status: u16) -> FastlyStatus;
1340
1341        #[link_name = "version_get"]
1342        pub fn version_get(resp_handle: ResponseHandle, version: *mut u32) -> FastlyStatus;
1343
1344        #[link_name = "version_set"]
1345        pub fn version_set(resp_handle: ResponseHandle, version: u32) -> FastlyStatus;
1346
1347        #[link_name = "framing_headers_mode_set"]
1348        pub fn framing_headers_mode_set(
1349            resp_handle: ResponseHandle,
1350            mode: fastly_shared::FramingHeadersMode,
1351        ) -> FastlyStatus;
1352
1353        #[doc(hidden)]
1354        #[link_name = "http_keepalive_mode_set"]
1355        pub fn http_keepalive_mode_set(
1356            resp_handle: ResponseHandle,
1357            mode: fastly_shared::HttpKeepaliveMode,
1358        ) -> FastlyStatus;
1359
1360        #[link_name = "close"]
1361        pub fn close(resp_handle: ResponseHandle) -> FastlyStatus;
1362
1363        #[link_name = "get_addr_dest_ip"]
1364        pub fn get_addr_dest_ip(
1365            resp_handle: ResponseHandle,
1366            addr_octets_out: *mut u8,
1367            nwritten_out: *mut usize,
1368        ) -> FastlyStatus;
1369
1370        #[link_name = "get_addr_dest_port"]
1371        pub fn get_addr_dest_port(resp_handle: ResponseHandle, port_out: *mut u16) -> FastlyStatus;
1372    }
1373}
1374
1375pub mod fastly_dictionary {
1376    use super::*;
1377
1378    #[link(wasm_import_module = "fastly_dictionary")]
1379    extern "C" {
1380        #[link_name = "open"]
1381        pub fn open(
1382            name: *const u8,
1383            name_len: usize,
1384            dict_handle_out: *mut DictionaryHandle,
1385        ) -> FastlyStatus;
1386
1387        #[link_name = "get"]
1388        pub fn get(
1389            dict_handle: DictionaryHandle,
1390            key: *const u8,
1391            key_len: usize,
1392            value: *mut u8,
1393            value_max_len: usize,
1394            nwritten: *mut usize,
1395        ) -> FastlyStatus;
1396    }
1397}
1398
1399pub mod fastly_geo {
1400    use super::*;
1401
1402    #[link(wasm_import_module = "fastly_geo")]
1403    extern "C" {
1404        #[link_name = "lookup"]
1405        pub fn lookup(
1406            addr_octets: *const u8,
1407            addr_len: usize,
1408            buf: *mut u8,
1409            buf_len: usize,
1410            nwritten_out: *mut usize,
1411        ) -> FastlyStatus;
1412    }
1413}
1414
1415pub mod fastly_device_detection {
1416    use super::*;
1417
1418    #[link(wasm_import_module = "fastly_device_detection")]
1419    extern "C" {
1420        #[link_name = "lookup"]
1421        pub fn lookup(
1422            user_agent: *const u8,
1423            user_agent_max_len: usize,
1424            buf: *mut u8,
1425            buf_len: usize,
1426            nwritten_out: *mut usize,
1427        ) -> FastlyStatus;
1428    }
1429}
1430
1431pub mod fastly_erl {
1432    use super::*;
1433
1434    #[link(wasm_import_module = "fastly_erl")]
1435    extern "C" {
1436        #[link_name = "check_rate"]
1437        pub fn check_rate(
1438            rc: *const u8,
1439            rc_max_len: usize,
1440            entry: *const u8,
1441            entry_max_len: usize,
1442            delta: u32,
1443            window: u32,
1444            limit: u32,
1445            pb: *const u8,
1446            pb_max_len: usize,
1447            ttl: u32,
1448            value: *mut u32,
1449        ) -> FastlyStatus;
1450
1451        #[link_name = "ratecounter_increment"]
1452        pub fn ratecounter_increment(
1453            rc: *const u8,
1454            rc_max_len: usize,
1455            entry: *const u8,
1456            entry_max_len: usize,
1457            delta: u32,
1458        ) -> FastlyStatus;
1459
1460        #[link_name = "ratecounter_lookup_rate"]
1461        pub fn ratecounter_lookup_rate(
1462            rc: *const u8,
1463            rc_max_len: usize,
1464            entry: *const u8,
1465            entry_max_len: usize,
1466            window: u32,
1467            value: *mut u32,
1468        ) -> FastlyStatus;
1469
1470        #[link_name = "ratecounter_lookup_count"]
1471        pub fn ratecounter_lookup_count(
1472            rc: *const u8,
1473            rc_max_len: usize,
1474            entry: *const u8,
1475            entry_max_len: usize,
1476            duration: u32,
1477            value: *mut u32,
1478        ) -> FastlyStatus;
1479
1480        #[link_name = "penaltybox_add"]
1481        pub fn penaltybox_add(
1482            pb: *const u8,
1483            pb_max_len: usize,
1484            entry: *const u8,
1485            entry_max_len: usize,
1486            ttl: u32,
1487        ) -> FastlyStatus;
1488
1489        #[link_name = "penaltybox_has"]
1490        pub fn penaltybox_has(
1491            pb: *const u8,
1492            pb_max_len: usize,
1493            entry: *const u8,
1494            entry_max_len: usize,
1495            value: *mut u32,
1496        ) -> FastlyStatus;
1497    }
1498}
1499
1500pub mod fastly_kv_store {
1501    use super::*;
1502
1503    #[repr(u32)]
1504    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
1505    pub enum KvError {
1506        Uninitialized,
1507        Ok,
1508        BadRequest,
1509        NotFound,
1510        PreconditionFailed,
1511        PayloadTooLarge,
1512        InternalError,
1513    }
1514
1515    // TODO ACF 2023-04-11: keep the object store name here until the ABI is updated
1516    #[link(wasm_import_module = "fastly_object_store")]
1517    extern "C" {
1518        #[link_name = "open"]
1519        pub fn open(
1520            name_ptr: *const u8,
1521            name_len: usize,
1522            kv_store_handle_out: *mut KVStoreHandle,
1523        ) -> FastlyStatus;
1524
1525        #[deprecated(note = "kept for backward compatibility")]
1526        #[link_name = "lookup"]
1527        pub fn lookup(
1528            kv_store_handle: KVStoreHandle,
1529            key_ptr: *const u8,
1530            key_len: usize,
1531            body_handle_out: *mut BodyHandle,
1532        ) -> FastlyStatus;
1533
1534        #[deprecated(note = "kept for backward compatibility")]
1535        #[link_name = "lookup_async"]
1536        pub fn lookup_async(
1537            kv_store_handle: KVStoreHandle,
1538            key_ptr: *const u8,
1539            key_len: usize,
1540            pending_body_handle_out: *mut PendingObjectStoreLookupHandle,
1541        ) -> FastlyStatus;
1542
1543        #[deprecated(note = "kept for backward compatibility")]
1544        #[link_name = "pending_lookup_wait"]
1545        pub fn pending_lookup_wait(
1546            pending_handle: PendingObjectStoreLookupHandle,
1547            body_handle_out: *mut BodyHandle,
1548        ) -> FastlyStatus;
1549
1550        #[deprecated(note = "kept for backward compatibility")]
1551        #[link_name = "insert"]
1552        pub fn insert(
1553            kv_store_handle: KVStoreHandle,
1554            key_ptr: *const u8,
1555            key_len: usize,
1556            body_handle: BodyHandle,
1557        ) -> FastlyStatus;
1558
1559        #[deprecated(note = "kept for backward compatibility")]
1560        #[link_name = "insert_async"]
1561        pub fn insert_async(
1562            kv_store_handle: KVStoreHandle,
1563            key_ptr: *const u8,
1564            key_len: usize,
1565            body_handle: BodyHandle,
1566            pending_body_handle_out: *mut PendingObjectStoreInsertHandle,
1567        ) -> FastlyStatus;
1568
1569        #[deprecated(note = "kept for backward compatibility")]
1570        #[link_name = "pending_insert_wait"]
1571        pub fn pending_insert_wait(
1572            pending_body_handle: PendingObjectStoreInsertHandle,
1573            kv_error_out: *mut KvError,
1574        ) -> FastlyStatus;
1575
1576        #[deprecated(note = "kept for backward compatibility")]
1577        #[link_name = "delete_async"]
1578        pub fn delete_async(
1579            kv_store_handle: KVStoreHandle,
1580            key_ptr: *const u8,
1581            key_len: usize,
1582            pending_body_handle_out: *mut PendingObjectStoreDeleteHandle,
1583        ) -> FastlyStatus;
1584
1585        #[deprecated(note = "kept for backward compatibility")]
1586        #[link_name = "pending_delete_wait"]
1587        pub fn pending_delete_wait(
1588            pending_body_handle: PendingObjectStoreDeleteHandle,
1589        ) -> FastlyStatus;
1590    }
1591
1592    #[link(wasm_import_module = "fastly_kv_store")]
1593    extern "C" {
1594        #[link_name = "open"]
1595        pub fn open_v2(
1596            name_ptr: *const u8,
1597            name_len: usize,
1598            kv_store_handle_out: *mut KVStoreHandle,
1599        ) -> FastlyStatus;
1600
1601        #[link_name = "lookup"]
1602        pub fn lookup_v2(
1603            kv_store_handle: KVStoreHandle,
1604            key_ptr: *const u8,
1605            key_len: usize,
1606            lookup_config_mask: LookupConfigOptions,
1607            lookup_config: *const LookupConfig,
1608            pending_body_handle_out: *mut PendingObjectStoreLookupHandle,
1609        ) -> FastlyStatus;
1610
1611        #[link_name = "lookup_wait"]
1612        pub fn pending_lookup_wait_v2(
1613            pending_handle: PendingObjectStoreLookupHandle,
1614            body_handle_out: *mut BodyHandle,
1615            metadata_buf: *mut u8,
1616            metadata_buf_len: usize,
1617            nwritten_out: *mut usize,
1618            generation_out: *mut u32,
1619            kv_error_out: *mut KvError,
1620        ) -> FastlyStatus;
1621
1622        #[link_name = "lookup_wait_v2"]
1623        pub fn lookup_wait_v2(
1624            pending_handle: PendingObjectStoreLookupHandle,
1625            body_handle_out: *mut BodyHandle,
1626            metadata_buf: *mut u8,
1627            metadata_buf_len: usize,
1628            nwritten_out: *mut usize,
1629            generation_out: *mut u64,
1630            kv_error_out: *mut KvError,
1631        ) -> FastlyStatus;
1632
1633        #[link_name = "insert"]
1634        pub fn insert_v2(
1635            kv_store_handle: KVStoreHandle,
1636            key_ptr: *const u8,
1637            key_len: usize,
1638            body_handle: BodyHandle,
1639            insert_config_mask: InsertConfigOptions,
1640            insert_config: *const InsertConfig,
1641            pending_body_handle_out: *mut PendingObjectStoreInsertHandle,
1642        ) -> FastlyStatus;
1643
1644        #[link_name = "insert_wait"]
1645        pub fn pending_insert_wait_v2(
1646            pending_body_handle: PendingObjectStoreInsertHandle,
1647            kv_error_out: *mut KvError,
1648        ) -> FastlyStatus;
1649
1650        #[link_name = "delete"]
1651        pub fn delete_v2(
1652            kv_store_handle: KVStoreHandle,
1653            key_ptr: *const u8,
1654            key_len: usize,
1655            delete_config_mask: DeleteConfigOptions,
1656            delete_config: *const DeleteConfig,
1657            pending_body_handle_out: *mut PendingObjectStoreDeleteHandle,
1658        ) -> FastlyStatus;
1659
1660        #[link_name = "delete_wait"]
1661        pub fn pending_delete_wait_v2(
1662            pending_body_handle: PendingObjectStoreDeleteHandle,
1663            kv_error_out: *mut KvError,
1664        ) -> FastlyStatus;
1665
1666        #[link_name = "list"]
1667        pub fn list_v2(
1668            kv_store_handle: KVStoreHandle,
1669            list_config_mask: ListConfigOptions,
1670            list_config: *const ListConfig,
1671            pending_body_handle_out: *mut PendingObjectStoreListHandle,
1672        ) -> FastlyStatus;
1673
1674        #[link_name = "list_wait"]
1675        pub fn pending_list_wait_v2(
1676            pending_body_handle: PendingObjectStoreListHandle,
1677            body_handle_out: *mut BodyHandle,
1678            kv_error_out: *mut KvError,
1679        ) -> FastlyStatus;
1680    }
1681}
1682
1683pub mod fastly_secret_store {
1684    use super::*;
1685
1686    #[link(wasm_import_module = "fastly_secret_store")]
1687    extern "C" {
1688        #[link_name = "open"]
1689        pub fn open(
1690            secret_store_name_ptr: *const u8,
1691            secret_store_name_len: usize,
1692            secret_store_handle_out: *mut SecretStoreHandle,
1693        ) -> FastlyStatus;
1694
1695        #[link_name = "get"]
1696        pub fn get(
1697            secret_store_handle: SecretStoreHandle,
1698            secret_name_ptr: *const u8,
1699            secret_name_len: usize,
1700            secret_handle_out: *mut SecretHandle,
1701        ) -> FastlyStatus;
1702
1703        #[link_name = "plaintext"]
1704        pub fn plaintext(
1705            secret_handle: SecretHandle,
1706            plaintext_buf: *mut u8,
1707            plaintext_max_len: usize,
1708            nwritten_out: *mut usize,
1709        ) -> FastlyStatus;
1710
1711        #[link_name = "from_bytes"]
1712        pub fn from_bytes(
1713            plaintext_buf: *const u8,
1714            plaintext_len: usize,
1715            secret_handle_out: *mut SecretHandle,
1716        ) -> FastlyStatus;
1717    }
1718}
1719
1720pub mod fastly_backend {
1721    use super::*;
1722
1723    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
1724    #[repr(u32)]
1725    pub enum BackendHealth {
1726        Unknown,
1727        Healthy,
1728        Unhealthy,
1729    }
1730
1731    #[link(wasm_import_module = "fastly_backend")]
1732    extern "C" {
1733        #[link_name = "exists"]
1734        pub fn exists(
1735            backend_ptr: *const u8,
1736            backend_len: usize,
1737            backend_exists_out: *mut u32,
1738        ) -> FastlyStatus;
1739
1740        #[link_name = "is_healthy"]
1741        pub fn is_healthy(
1742            backend_ptr: *const u8,
1743            backend_len: usize,
1744            backend_health_out: *mut BackendHealth,
1745        ) -> FastlyStatus;
1746
1747        #[link_name = "is_dynamic"]
1748        pub fn is_dynamic(
1749            backend_ptr: *const u8,
1750            backend_len: usize,
1751            value: *mut u32,
1752        ) -> FastlyStatus;
1753
1754        #[link_name = "get_host"]
1755        pub fn get_host(
1756            backend_ptr: *const u8,
1757            backend_len: usize,
1758            value: *mut u8,
1759            value_max_len: usize,
1760            nwritten: *mut usize,
1761        ) -> FastlyStatus;
1762
1763        #[link_name = "get_override_host"]
1764        pub fn get_override_host(
1765            backend_ptr: *const u8,
1766            backend_len: usize,
1767            value: *mut u8,
1768            value_max_len: usize,
1769            nwritten: *mut usize,
1770        ) -> FastlyStatus;
1771
1772        #[link_name = "get_port"]
1773        pub fn get_port(
1774            backend_ptr: *const u8,
1775            backend_len: usize,
1776            value: *mut u16,
1777        ) -> FastlyStatus;
1778
1779        #[link_name = "get_connect_timeout_ms"]
1780        pub fn get_connect_timeout_ms(
1781            backend_ptr: *const u8,
1782            backend_len: usize,
1783            value: *mut u32,
1784        ) -> FastlyStatus;
1785
1786        #[link_name = "get_first_byte_timeout_ms"]
1787        pub fn get_first_byte_timeout_ms(
1788            backend_ptr: *const u8,
1789            backend_len: usize,
1790            value: *mut u32,
1791        ) -> FastlyStatus;
1792
1793        #[link_name = "get_between_bytes_timeout_ms"]
1794        pub fn get_between_bytes_timeout_ms(
1795            backend_ptr: *const u8,
1796            backend_len: usize,
1797            value: *mut u32,
1798        ) -> FastlyStatus;
1799
1800        #[link_name = "get_http_keepalive_time"]
1801        pub fn get_http_keepalive_time(
1802            backend_ptr: *const u8,
1803            backend_len: usize,
1804            value: *mut u32,
1805        ) -> FastlyStatus;
1806
1807        #[link_name = "get_tcp_keepalive_enable"]
1808        pub fn get_tcp_keepalive_enable(
1809            backend_ptr: *const u8,
1810            backend_len: usize,
1811            value: *mut u32,
1812        ) -> FastlyStatus;
1813
1814        #[link_name = "get_tcp_keepalive_interval"]
1815        pub fn get_tcp_keepalive_interval(
1816            backend_ptr: *const u8,
1817            backend_len: usize,
1818            value: *mut u32,
1819        ) -> FastlyStatus;
1820
1821        #[link_name = "get_tcp_keepalive_probes"]
1822        pub fn get_tcp_keepalive_probes(
1823            backend_ptr: *const u8,
1824            backend_len: usize,
1825            value: *mut u32,
1826        ) -> FastlyStatus;
1827
1828        #[link_name = "get_tcp_keepalive_time"]
1829        pub fn get_tcp_keepalive_time(
1830            backend_ptr: *const u8,
1831            backend_len: usize,
1832            value: *mut u32,
1833        ) -> FastlyStatus;
1834
1835        #[link_name = "is_ssl"]
1836        pub fn is_ssl(backend_ptr: *const u8, backend_len: usize, value: *mut u32) -> FastlyStatus;
1837
1838        #[link_name = "get_ssl_min_version"]
1839        pub fn get_ssl_min_version(
1840            backend_ptr: *const u8,
1841            backend_len: usize,
1842            value: *mut u32,
1843        ) -> FastlyStatus;
1844
1845        #[link_name = "get_ssl_max_version"]
1846        pub fn get_ssl_max_version(
1847            backend_ptr: *const u8,
1848            backend_len: usize,
1849            value: *mut u32,
1850        ) -> FastlyStatus;
1851    }
1852}
1853
1854pub mod fastly_async_io {
1855    use super::*;
1856
1857    #[link(wasm_import_module = "fastly_async_io")]
1858    extern "C" {
1859        #[link_name = "select"]
1860        pub fn select(
1861            async_item_handles: *const AsyncItemHandle,
1862            async_item_handles_len: usize,
1863            timeout_ms: u32,
1864            done_index_out: *mut u32,
1865        ) -> FastlyStatus;
1866
1867        #[link_name = "is_ready"]
1868        pub fn is_ready(async_item_handle: AsyncItemHandle, ready_out: *mut u32) -> FastlyStatus;
1869    }
1870}
1871
1872pub mod fastly_image_optimizer {
1873    use super::*;
1874
1875    bitflags::bitflags! {
1876        #[repr(transparent)]
1877        pub struct ImageOptimizerTransformConfigOptions: u32 {
1878            const RESERVED = 1 << 0;
1879            const SDK_CLAIMS_OPTS = 1 << 1;
1880        }
1881    }
1882
1883    #[repr(C, align(8))]
1884    pub struct ImageOptimizerTransformConfig {
1885        pub sdk_claims_opts: *const u8,
1886        pub sdk_claims_opts_len: u32,
1887    }
1888
1889    impl Default for ImageOptimizerTransformConfig {
1890        fn default() -> Self {
1891            ImageOptimizerTransformConfig {
1892                sdk_claims_opts: std::ptr::null(),
1893                sdk_claims_opts_len: 0,
1894            }
1895        }
1896    }
1897
1898    #[repr(u32)]
1899    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
1900    pub enum ImageOptimizerErrorTag {
1901        Uninitialized,
1902        Ok,
1903        Error,
1904        Warning,
1905    }
1906
1907    #[repr(C, align(8))]
1908    #[derive(Clone, Debug, PartialEq, Eq)]
1909    pub struct ImageOptimizerErrorDetail {
1910        pub tag: ImageOptimizerErrorTag,
1911        pub message: *const u8,
1912        pub message_len: usize,
1913    }
1914
1915    impl ImageOptimizerErrorDetail {
1916        pub fn uninitialized() -> Self {
1917            Self {
1918                tag: ImageOptimizerErrorTag::Uninitialized,
1919                message: std::ptr::null(),
1920                message_len: 0,
1921            }
1922        }
1923    }
1924
1925    #[link(wasm_import_module = "fastly_image_optimizer")]
1926    extern "C" {
1927        #[link_name = "transform_image_optimizer_request"]
1928        pub fn transform_image_optimizer_request(
1929            origin_image_request: RequestHandle,
1930            origin_image_request_body: BodyHandle,
1931            origin_image_backend: *const u8,
1932            origin_image_backend_len: usize,
1933            io_transform_config_options: ImageOptimizerTransformConfigOptions,
1934            io_transform_config: *const ImageOptimizerTransformConfig,
1935            io_error_detail: *mut ImageOptimizerErrorDetail,
1936            resp_handle_out: *mut ResponseHandle,
1937            resp_body_handle_out: *mut BodyHandle,
1938        ) -> FastlyStatus;
1939    }
1940}
1941
1942pub mod fastly_purge {
1943    use super::*;
1944
1945    bitflags::bitflags! {
1946        #[derive(Default)]
1947        #[repr(transparent)]
1948        pub struct PurgeOptionsMask: u32 {
1949            const SOFT_PURGE = 1 << 0;
1950            const RET_BUF = 1 << 1;
1951        }
1952    }
1953
1954    #[derive(Debug)]
1955    #[repr(C)]
1956    pub struct PurgeOptions {
1957        pub ret_buf_ptr: *mut u8,
1958        pub ret_buf_len: usize,
1959        pub ret_buf_nwritten_out: *mut usize,
1960    }
1961
1962    #[link(wasm_import_module = "fastly_purge")]
1963    extern "C" {
1964        #[link_name = "purge_surrogate_key"]
1965        pub fn purge_surrogate_key(
1966            surrogate_key_ptr: *const u8,
1967            surrogate_key_len: usize,
1968            options_mask: PurgeOptionsMask,
1969            options: *mut PurgeOptions,
1970        ) -> FastlyStatus;
1971    }
1972}
1973
1974pub mod fastly_compute_runtime {
1975    use super::*;
1976
1977    #[link(wasm_import_module = "fastly_compute_runtime")]
1978    extern "C" {
1979        #[link_name = "get_vcpu_ms"]
1980        pub fn get_vcpu_ms(ms_out: *mut u64) -> FastlyStatus;
1981    }
1982
1983    #[link(wasm_import_module = "fastly_compute_runtime")]
1984    extern "C" {
1985        #[link_name = "get_heap_mib"]
1986        pub fn get_heap_mib(mb_out: *mut u32) -> fastly_shared::FastlyStatus;
1987    }
1988}
1989
1990pub mod fastly_acl {
1991    use super::*;
1992
1993    #[repr(u32)]
1994    #[derive(Clone, Copy, Debug, PartialEq, Eq)]
1995    pub enum AclError {
1996        Uninitialized,
1997        Ok,
1998        NoContent,
1999        TooManyRequests,
2000    }
2001
2002    #[link(wasm_import_module = "fastly_acl")]
2003    extern "C" {
2004        #[link_name = "open"]
2005        pub fn open(
2006            acl_name_ptr: *const u8,
2007            acl_name_len: usize,
2008            acl_handle_out: *mut AclHandle,
2009        ) -> FastlyStatus;
2010
2011        #[link_name = "lookup"]
2012        pub fn lookup(
2013            acl_handle: AclHandle,
2014            ip_octets: *const u8,
2015            ip_len: usize,
2016            body_handle_out: *mut BodyHandle,
2017            acl_error_out: *mut AclError,
2018        ) -> FastlyStatus;
2019    }
2020}
2021
2022pub mod fastly_shielding {
2023    use super::*;
2024
2025    bitflags::bitflags! {
2026        #[derive(Default)]
2027        #[repr(transparent)]
2028        pub struct ShieldBackendOptions: u32 {
2029            const RESERVED = 1 << 0;
2030            const CACHE_KEY = 1 << 1;
2031            const FIRST_BYTE_TIMEOUT = 1 << 2;
2032        }
2033    }
2034
2035    #[repr(C)]
2036    pub struct ShieldBackendConfig {
2037        pub cache_key: *const u8,
2038        pub cache_key_len: u32,
2039        pub first_byte_timeout_ms: u32,
2040    }
2041
2042    impl Default for ShieldBackendConfig {
2043        fn default() -> Self {
2044            ShieldBackendConfig {
2045                cache_key: std::ptr::null(),
2046                cache_key_len: 0,
2047                first_byte_timeout_ms: 0,
2048            }
2049        }
2050    }
2051
2052    //   (@interface func (export "shield_info")
2053    //     (param $name string)
2054    //     (param $info_block (@witx pointer (@witx char8)))
2055    //     (param $info_block_max_len (@witx usize))
2056    //     (result $err (expected $num_bytes (error $fastly_status)))
2057    //   )
2058
2059    #[link(wasm_import_module = "fastly_shielding")]
2060    extern "C" {
2061
2062        /// Get information about the given shield in the Fastly network
2063        #[link_name = "shield_info"]
2064        pub fn shield_info(
2065            name: *const u8,
2066            name_len: usize,
2067            info_block: *mut u8,
2068            info_block_len: usize,
2069            nwritten_out: *mut u32,
2070        ) -> FastlyStatus;
2071
2072        /// Turn a pop name into a backend that we can send requests to.
2073        #[link_name = "backend_for_shield"]
2074        pub fn backend_for_shield(
2075            name: *const u8,
2076            name_len: usize,
2077            options_mask: ShieldBackendOptions,
2078            options: *const ShieldBackendConfig,
2079            backend_name: *mut u8,
2080            backend_name_len: usize,
2081            nwritten_out: *mut u32,
2082        ) -> FastlyStatus;
2083    }
2084}
2085
2086/// WIT for the Fastly APIs in the `fastly:compute/service@0.1.0` world.
2087#[cfg(not(target_env = "p1"))]
2088pub mod service0_1_0;
2089
2090#[cfg(not(target_env = "p1"))]
2091impl From<service0_1_0::fastly::compute::types::Error> for fastly_shared::FastlyStatus {
2092    fn from(error: service0_1_0::fastly::compute::types::Error) -> Self {
2093        use service0_1_0::fastly::compute::types::Error;
2094        match error {
2095            Error::InvalidArgument => Self::INVAL,
2096            Error::Unsupported => Self::UNSUPPORTED,
2097            Error::LimitExceeded => Self::LIMITEXCEEDED,
2098            Error::GenericError => Self::ERROR,
2099            Error::BufferLen(_) => Self::BUFLEN,
2100            Error::CannotRead => Self::NONE,
2101            Error::AuxiliaryError => Self::BADF,
2102            Error::HttpInvalid => Self::HTTPINVALID,
2103            Error::HttpUser => Self::HTTPUSER,
2104            Error::HttpIncomplete => Self::HTTPINCOMPLETE,
2105            Error::HttpHeadTooLarge => Self::HTTPHEADTOOLARGE,
2106            Error::HttpInvalidStatus => Self::HTTPINVALIDSTATUS,
2107        }
2108    }
2109}
2110
2111#[cfg(not(target_env = "p1"))]
2112impl From<std::net::IpAddr> for service0_1_0::fastly::compute::types::IpAddress {
2113    fn from(addr: std::net::IpAddr) -> Self {
2114        use std::net::IpAddr;
2115        match addr {
2116            IpAddr::V4(v4) => Self::Ipv4(v4.octets().into()),
2117            IpAddr::V6(v6) => Self::Ipv6(v6.segments().into()),
2118        }
2119    }
2120}
2121
2122#[cfg(not(target_env = "p1"))]
2123impl From<service0_1_0::fastly::compute::types::IpAddress> for std::net::IpAddr {
2124    fn from(addr: service0_1_0::fastly::compute::types::IpAddress) -> Self {
2125        use service0_1_0::fastly::compute::types::IpAddress;
2126        match addr {
2127            IpAddress::Ipv4(v4) => Self::V4(<[u8; 4]>::from(v4).into()),
2128            IpAddress::Ipv6(v6) => Self::V6(<[u16; 8]>::from(v6).into()),
2129        }
2130    }
2131}
2132
2133#[cfg(not(target_env = "p1"))]
2134impl From<service0_1_0::fastly::compute::http_types::HttpVersion> for http::version::Version {
2135    fn from(version: service0_1_0::fastly::compute::http_types::HttpVersion) -> Self {
2136        use service0_1_0::fastly::compute::http_types::HttpVersion;
2137        match version {
2138            HttpVersion::Http09 => Self::HTTP_09,
2139            HttpVersion::Http10 => Self::HTTP_10,
2140            HttpVersion::Http11 => Self::HTTP_11,
2141            HttpVersion::H2 => Self::HTTP_2,
2142            HttpVersion::H3 => Self::HTTP_3,
2143        }
2144    }
2145}
2146
2147#[cfg(not(target_env = "p1"))]
2148impl TryFrom<http::version::Version> for service0_1_0::fastly::compute::http_types::HttpVersion {
2149    type Error = ();
2150
2151    fn try_from(version: http::version::Version) -> Result<Self, Self::Error> {
2152        use http::version::Version;
2153        Ok(match version {
2154            Version::HTTP_09 => Self::Http09,
2155            Version::HTTP_10 => Self::Http10,
2156            Version::HTTP_11 => Self::Http11,
2157            Version::HTTP_2 => Self::H2,
2158            Version::HTTP_3 => Self::H3,
2159            _ => return Err(()),
2160        })
2161    }
2162}
2163
2164#[cfg(not(target_env = "p1"))]
2165impl From<fastly_shared::FramingHeadersMode>
2166    for service0_1_0::fastly::compute::http_types::FramingHeadersMode
2167{
2168    fn from(mode: fastly_shared::FramingHeadersMode) -> Self {
2169        use fastly_shared::FramingHeadersMode;
2170        match mode {
2171            FramingHeadersMode::Automatic => Self::Automatic,
2172            FramingHeadersMode::ManuallyFromHeaders => Self::ManuallyFromHeaders,
2173        }
2174    }
2175}
2176
2177#[cfg(not(target_env = "p1"))]
2178impl From<service0_1_0::fastly::compute::http_types::FramingHeadersMode>
2179    for fastly_shared::FramingHeadersMode
2180{
2181    fn from(mode: service0_1_0::fastly::compute::http_types::FramingHeadersMode) -> Self {
2182        use service0_1_0::fastly::compute::http_types::FramingHeadersMode;
2183        match mode {
2184            FramingHeadersMode::Automatic => Self::Automatic,
2185            FramingHeadersMode::ManuallyFromHeaders => Self::ManuallyFromHeaders,
2186        }
2187    }
2188}
2189
2190#[cfg(not(target_env = "p1"))]
2191impl From<fastly_shared::HttpKeepaliveMode>
2192    for service0_1_0::fastly::compute::http_resp::KeepaliveMode
2193{
2194    fn from(mode: fastly_shared::HttpKeepaliveMode) -> Self {
2195        use fastly_shared::HttpKeepaliveMode;
2196        match mode {
2197            HttpKeepaliveMode::Automatic => Self::Automatic,
2198            HttpKeepaliveMode::NoKeepalive => Self::NoKeepalive,
2199        }
2200    }
2201}
2202
2203#[cfg(not(target_env = "p1"))]
2204impl From<service0_1_0::fastly::compute::http_resp::KeepaliveMode>
2205    for fastly_shared::HttpKeepaliveMode
2206{
2207    fn from(mode: service0_1_0::fastly::compute::http_resp::KeepaliveMode) -> Self {
2208        use service0_1_0::fastly::compute::http_resp::KeepaliveMode;
2209        match mode {
2210            KeepaliveMode::Automatic => Self::Automatic,
2211            KeepaliveMode::NoKeepalive => Self::NoKeepalive,
2212        }
2213    }
2214}