From 301273fcba2ea662f28a74c99e52901313690963 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 5 Sep 2025 16:30:56 -0700 Subject: [PATCH] Don't generate bindings with a synthetic package This commit addresses an issue in Rust nightly with the Rust standard library. Notably what's happening is that the `wasi` crate is using a synthetic world/package called `rust:wasi/bindings` to generate bindings. This world includes `wasi:cli/imports` and `wasi:http/imports`. What's happening is that the Rust standard library is using one version of the `wasi` crate with one version of WASI bindings, but user crates might use something different. This fails to link because `rust:wasi/bindings` is asserted to be the same no matter what and there's two different `wasi` crate versions feeding into this which cause conflicts. The fix in this commit is to skip using `rust:wasi` as a package and generate bindings directly from WASI packages themselves. These bindings correctly have versions in them and are versioned appropriately so there's no clash and merging proceeds as expected. This required moving the bindings for `wasi:http/imports` into the generation of bindings for `wasi:http/proxy`, but that doesn't actually change the structure of the crate just how the generated bindings work out. --- ci/regenerate.sh | 7 +- src/{bindings.rs => imports.rs} | 7590 ++----------------------------- src/lib.rs | 8 +- src/proxy.rs | 7020 +++++++++++++++++++++++++++- wit/wasi-crate.wit | 5 - 5 files changed, 7362 insertions(+), 7268 deletions(-) rename src/{bindings.rs => imports.rs} (53%) diff --git a/ci/regenerate.sh b/ci/regenerate.sh index ea8c4d7..dd106fd 100755 --- a/ci/regenerate.sh +++ b/ci/regenerate.sh @@ -15,8 +15,9 @@ generate() { # Generate the main body of the bindings which includes all imports from the two # worlds below. -generate src/bindings.rs --type-section-suffix rust-wasi-from-crates-io \ - --generate-all +generate src/imports.rs --type-section-suffix rust-wasi-from-crates-io \ + --generate-all \ + --world wasi:cli/imports # Generate bindings for the `wasi:cli/command` world specifically, namely the # macro `export_command`. @@ -67,8 +68,6 @@ with="$with,wasi:io/error@0.2.4=crate::io::error" with="$with,wasi:io/poll@0.2.4=crate::io::poll" with="$with,wasi:io/streams@0.2.4=crate::io::streams" with="$with,wasi:random/random@0.2.4=crate::random::random" -with="$with,wasi:http/types@0.2.4=crate::http::types" -with="$with,wasi:http/outgoing-handler@0.2.4=crate::http::outgoing_handler" generate src/proxy.rs \ --world wasi:http/proxy \ --with "$with" \ diff --git a/src/bindings.rs b/src/imports.rs similarity index 53% rename from src/bindings.rs rename to src/imports.rs index da99a26..726b026 100644 --- a/src/bindings.rs +++ b/src/imports.rs @@ -3609,6817 +3609,116 @@ pub mod wasi { } } } - pub mod http { - /// This interface defines all of the types and methods for implementing - /// HTTP Requests and Responses, both incoming and outgoing, as well as - /// their headers, trailers, and bodies. - #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] - pub mod types { - #[used] - #[doc(hidden)] - static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; - use super::super::super::_rt; - pub type Duration = super::super::super::wasi::clocks::monotonic_clock::Duration; - pub type InputStream = super::super::super::wasi::io::streams::InputStream; - pub type OutputStream = super::super::super::wasi::io::streams::OutputStream; - pub type IoError = super::super::super::wasi::io::error::Error; - pub type Pollable = super::super::super::wasi::io::poll::Pollable; - /// This type corresponds to HTTP standard Methods. - #[derive(Clone)] - pub enum Method { - Get, - Head, - Post, - Put, - Delete, - Connect, - Options, - Trace, - Patch, - Other(_rt::String), - } - impl ::core::fmt::Debug for Method { - fn fmt( - &self, - f: &mut ::core::fmt::Formatter<'_>, - ) -> ::core::fmt::Result { - match self { - Method::Get => f.debug_tuple("Method::Get").finish(), - Method::Head => f.debug_tuple("Method::Head").finish(), - Method::Post => f.debug_tuple("Method::Post").finish(), - Method::Put => f.debug_tuple("Method::Put").finish(), - Method::Delete => f.debug_tuple("Method::Delete").finish(), - Method::Connect => f.debug_tuple("Method::Connect").finish(), - Method::Options => f.debug_tuple("Method::Options").finish(), - Method::Trace => f.debug_tuple("Method::Trace").finish(), - Method::Patch => f.debug_tuple("Method::Patch").finish(), - Method::Other(e) => { - f.debug_tuple("Method::Other").field(e).finish() - } - } - } - } - /// This type corresponds to HTTP standard Related Schemes. - #[derive(Clone)] - pub enum Scheme { - Http, - Https, - Other(_rt::String), - } - impl ::core::fmt::Debug for Scheme { - fn fmt( - &self, - f: &mut ::core::fmt::Formatter<'_>, - ) -> ::core::fmt::Result { - match self { - Scheme::Http => f.debug_tuple("Scheme::Http").finish(), - Scheme::Https => f.debug_tuple("Scheme::Https").finish(), - Scheme::Other(e) => { - f.debug_tuple("Scheme::Other").field(e).finish() - } - } - } - } - /// Defines the case payload type for `DNS-error` above: - #[derive(Clone)] - pub struct DnsErrorPayload { - pub rcode: Option<_rt::String>, - pub info_code: Option, - } - impl ::core::fmt::Debug for DnsErrorPayload { - fn fmt( - &self, - f: &mut ::core::fmt::Formatter<'_>, - ) -> ::core::fmt::Result { - f.debug_struct("DnsErrorPayload") - .field("rcode", &self.rcode) - .field("info-code", &self.info_code) - .finish() - } - } - /// Defines the case payload type for `TLS-alert-received` above: - #[derive(Clone)] - pub struct TlsAlertReceivedPayload { - pub alert_id: Option, - pub alert_message: Option<_rt::String>, - } - impl ::core::fmt::Debug for TlsAlertReceivedPayload { - fn fmt( - &self, - f: &mut ::core::fmt::Formatter<'_>, - ) -> ::core::fmt::Result { - f.debug_struct("TlsAlertReceivedPayload") - .field("alert-id", &self.alert_id) - .field("alert-message", &self.alert_message) - .finish() - } - } - /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: - #[derive(Clone)] - pub struct FieldSizePayload { - pub field_name: Option<_rt::String>, - pub field_size: Option, - } - impl ::core::fmt::Debug for FieldSizePayload { - fn fmt( - &self, - f: &mut ::core::fmt::Formatter<'_>, - ) -> ::core::fmt::Result { - f.debug_struct("FieldSizePayload") - .field("field-name", &self.field_name) - .field("field-size", &self.field_size) - .finish() - } - } - /// These cases are inspired by the IANA HTTP Proxy Error Types: - /// - #[derive(Clone)] - pub enum ErrorCode { - DnsTimeout, - DnsError(DnsErrorPayload), - DestinationNotFound, - DestinationUnavailable, - DestinationIpProhibited, - DestinationIpUnroutable, - ConnectionRefused, - ConnectionTerminated, - ConnectionTimeout, - ConnectionReadTimeout, - ConnectionWriteTimeout, - ConnectionLimitReached, - TlsProtocolError, - TlsCertificateError, - TlsAlertReceived(TlsAlertReceivedPayload), - HttpRequestDenied, - HttpRequestLengthRequired, - HttpRequestBodySize(Option), - HttpRequestMethodInvalid, - HttpRequestUriInvalid, - HttpRequestUriTooLong, - HttpRequestHeaderSectionSize(Option), - HttpRequestHeaderSize(Option), - HttpRequestTrailerSectionSize(Option), - HttpRequestTrailerSize(FieldSizePayload), - HttpResponseIncomplete, - HttpResponseHeaderSectionSize(Option), - HttpResponseHeaderSize(FieldSizePayload), - HttpResponseBodySize(Option), - HttpResponseTrailerSectionSize(Option), - HttpResponseTrailerSize(FieldSizePayload), - HttpResponseTransferCoding(Option<_rt::String>), - HttpResponseContentCoding(Option<_rt::String>), - HttpResponseTimeout, - HttpUpgradeFailed, - HttpProtocolError, - LoopDetected, - ConfigurationError, - /// This is a catch-all error for anything that doesn't fit cleanly into a - /// more specific case. It also includes an optional string for an - /// unstructured description of the error. Users should not depend on the - /// string for diagnosing errors, as it's not required to be consistent - /// between implementations. - InternalError(Option<_rt::String>), - } - impl ::core::fmt::Debug for ErrorCode { - fn fmt( - &self, - f: &mut ::core::fmt::Formatter<'_>, - ) -> ::core::fmt::Result { - match self { - ErrorCode::DnsTimeout => { - f.debug_tuple("ErrorCode::DnsTimeout").finish() - } - ErrorCode::DnsError(e) => { - f.debug_tuple("ErrorCode::DnsError").field(e).finish() - } - ErrorCode::DestinationNotFound => { - f.debug_tuple("ErrorCode::DestinationNotFound").finish() - } - ErrorCode::DestinationUnavailable => { - f.debug_tuple("ErrorCode::DestinationUnavailable").finish() - } - ErrorCode::DestinationIpProhibited => { - f.debug_tuple("ErrorCode::DestinationIpProhibited").finish() - } - ErrorCode::DestinationIpUnroutable => { - f.debug_tuple("ErrorCode::DestinationIpUnroutable").finish() - } - ErrorCode::ConnectionRefused => { - f.debug_tuple("ErrorCode::ConnectionRefused").finish() - } - ErrorCode::ConnectionTerminated => { - f.debug_tuple("ErrorCode::ConnectionTerminated").finish() - } - ErrorCode::ConnectionTimeout => { - f.debug_tuple("ErrorCode::ConnectionTimeout").finish() - } - ErrorCode::ConnectionReadTimeout => { - f.debug_tuple("ErrorCode::ConnectionReadTimeout").finish() - } - ErrorCode::ConnectionWriteTimeout => { - f.debug_tuple("ErrorCode::ConnectionWriteTimeout").finish() - } - ErrorCode::ConnectionLimitReached => { - f.debug_tuple("ErrorCode::ConnectionLimitReached").finish() - } - ErrorCode::TlsProtocolError => { - f.debug_tuple("ErrorCode::TlsProtocolError").finish() - } - ErrorCode::TlsCertificateError => { - f.debug_tuple("ErrorCode::TlsCertificateError").finish() - } - ErrorCode::TlsAlertReceived(e) => { - f.debug_tuple("ErrorCode::TlsAlertReceived") - .field(e) - .finish() - } - ErrorCode::HttpRequestDenied => { - f.debug_tuple("ErrorCode::HttpRequestDenied").finish() - } - ErrorCode::HttpRequestLengthRequired => { - f.debug_tuple("ErrorCode::HttpRequestLengthRequired") - .finish() - } - ErrorCode::HttpRequestBodySize(e) => { - f.debug_tuple("ErrorCode::HttpRequestBodySize") - .field(e) - .finish() - } - ErrorCode::HttpRequestMethodInvalid => { - f.debug_tuple("ErrorCode::HttpRequestMethodInvalid").finish() - } - ErrorCode::HttpRequestUriInvalid => { - f.debug_tuple("ErrorCode::HttpRequestUriInvalid").finish() - } - ErrorCode::HttpRequestUriTooLong => { - f.debug_tuple("ErrorCode::HttpRequestUriTooLong").finish() - } - ErrorCode::HttpRequestHeaderSectionSize(e) => { - f.debug_tuple("ErrorCode::HttpRequestHeaderSectionSize") - .field(e) - .finish() - } - ErrorCode::HttpRequestHeaderSize(e) => { - f.debug_tuple("ErrorCode::HttpRequestHeaderSize") - .field(e) - .finish() - } - ErrorCode::HttpRequestTrailerSectionSize(e) => { - f.debug_tuple("ErrorCode::HttpRequestTrailerSectionSize") - .field(e) - .finish() - } - ErrorCode::HttpRequestTrailerSize(e) => { - f.debug_tuple("ErrorCode::HttpRequestTrailerSize") - .field(e) - .finish() - } - ErrorCode::HttpResponseIncomplete => { - f.debug_tuple("ErrorCode::HttpResponseIncomplete").finish() - } - ErrorCode::HttpResponseHeaderSectionSize(e) => { - f.debug_tuple("ErrorCode::HttpResponseHeaderSectionSize") - .field(e) - .finish() - } - ErrorCode::HttpResponseHeaderSize(e) => { - f.debug_tuple("ErrorCode::HttpResponseHeaderSize") - .field(e) - .finish() - } - ErrorCode::HttpResponseBodySize(e) => { - f.debug_tuple("ErrorCode::HttpResponseBodySize") - .field(e) - .finish() - } - ErrorCode::HttpResponseTrailerSectionSize(e) => { - f.debug_tuple("ErrorCode::HttpResponseTrailerSectionSize") - .field(e) - .finish() - } - ErrorCode::HttpResponseTrailerSize(e) => { - f.debug_tuple("ErrorCode::HttpResponseTrailerSize") - .field(e) - .finish() - } - ErrorCode::HttpResponseTransferCoding(e) => { - f.debug_tuple("ErrorCode::HttpResponseTransferCoding") - .field(e) - .finish() - } - ErrorCode::HttpResponseContentCoding(e) => { - f.debug_tuple("ErrorCode::HttpResponseContentCoding") - .field(e) - .finish() - } - ErrorCode::HttpResponseTimeout => { - f.debug_tuple("ErrorCode::HttpResponseTimeout").finish() - } - ErrorCode::HttpUpgradeFailed => { - f.debug_tuple("ErrorCode::HttpUpgradeFailed").finish() - } - ErrorCode::HttpProtocolError => { - f.debug_tuple("ErrorCode::HttpProtocolError").finish() - } - ErrorCode::LoopDetected => { - f.debug_tuple("ErrorCode::LoopDetected").finish() - } - ErrorCode::ConfigurationError => { - f.debug_tuple("ErrorCode::ConfigurationError").finish() - } - ErrorCode::InternalError(e) => { - f.debug_tuple("ErrorCode::InternalError").field(e).finish() - } - } - } - } - impl ::core::fmt::Display for ErrorCode { - fn fmt( - &self, - f: &mut ::core::fmt::Formatter<'_>, - ) -> ::core::fmt::Result { - write!(f, "{:?}", self) - } - } - #[cfg(feature = "std")] - impl std::error::Error for ErrorCode {} - /// This type enumerates the different kinds of errors that may occur when - /// setting or appending to a `fields` resource. - #[derive(Clone, Copy)] - pub enum HeaderError { - /// This error indicates that a `field-name` or `field-value` was - /// syntactically invalid when used with an operation that sets headers in a - /// `fields`. - InvalidSyntax, - /// This error indicates that a forbidden `field-name` was used when trying - /// to set a header in a `fields`. - Forbidden, - /// This error indicates that the operation on the `fields` was not - /// permitted because the fields are immutable. - Immutable, - } - impl ::core::fmt::Debug for HeaderError { - fn fmt( - &self, - f: &mut ::core::fmt::Formatter<'_>, - ) -> ::core::fmt::Result { - match self { - HeaderError::InvalidSyntax => { - f.debug_tuple("HeaderError::InvalidSyntax").finish() - } - HeaderError::Forbidden => { - f.debug_tuple("HeaderError::Forbidden").finish() - } - HeaderError::Immutable => { - f.debug_tuple("HeaderError::Immutable").finish() - } - } - } - } - impl ::core::fmt::Display for HeaderError { - fn fmt( - &self, - f: &mut ::core::fmt::Formatter<'_>, - ) -> ::core::fmt::Result { - write!(f, "{:?}", self) - } - } - #[cfg(feature = "std")] - impl std::error::Error for HeaderError {} - /// Field keys are always strings. - /// - /// Field keys should always be treated as case insensitive by the `fields` - /// resource for the purposes of equality checking. - /// - /// # Deprecation - /// - /// This type has been deprecated in favor of the `field-name` type. - pub type FieldKey = _rt::String; - /// Field names are always strings. - /// - /// Field names should always be treated as case insensitive by the `fields` - /// resource for the purposes of equality checking. - pub type FieldName = FieldKey; - /// Field values should always be ASCII strings. However, in - /// reality, HTTP implementations often have to interpret malformed values, - /// so they are provided as a list of bytes. - pub type FieldValue = _rt::Vec; - /// This following block defines the `fields` resource which corresponds to - /// HTTP standard Fields. Fields are a common representation used for both - /// Headers and Trailers. - /// - /// A `fields` may be mutable or immutable. A `fields` created using the - /// constructor, `from-list`, or `clone` will be mutable, but a `fields` - /// resource given by other means (including, but not limited to, - /// `incoming-request.headers`, `outgoing-request.headers`) might be - /// immutable. In an immutable fields, the `set`, `append`, and `delete` - /// operations will fail with `header-error.immutable`. - #[derive(Debug)] - #[repr(transparent)] - pub struct Fields { - handle: _rt::Resource, - } - impl Fields { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for Fields { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]fields"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - /// Headers is an alias for Fields. - pub type Headers = Fields; - /// Trailers is an alias for Fields. - pub type Trailers = Fields; - /// Represents an incoming HTTP Request. - #[derive(Debug)] - #[repr(transparent)] - pub struct IncomingRequest { - handle: _rt::Resource, - } - impl IncomingRequest { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for IncomingRequest { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]incoming-request"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - /// Represents an outgoing HTTP Request. - #[derive(Debug)] - #[repr(transparent)] - pub struct OutgoingRequest { - handle: _rt::Resource, - } - impl OutgoingRequest { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for OutgoingRequest { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]outgoing-request"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - /// Parameters for making an HTTP Request. Each of these parameters is - /// currently an optional timeout applicable to the transport layer of the - /// HTTP protocol. - /// - /// These timeouts are separate from any the user may use to bound a - /// blocking call to `wasi:io/poll.poll`. - #[derive(Debug)] - #[repr(transparent)] - pub struct RequestOptions { - handle: _rt::Resource, - } - impl RequestOptions { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for RequestOptions { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]request-options"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - /// Represents the ability to send an HTTP Response. - /// - /// This resource is used by the `wasi:http/incoming-handler` interface to - /// allow a Response to be sent corresponding to the Request provided as the - /// other argument to `incoming-handler.handle`. - #[derive(Debug)] - #[repr(transparent)] - pub struct ResponseOutparam { - handle: _rt::Resource, - } - impl ResponseOutparam { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for ResponseOutparam { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]response-outparam"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - /// This type corresponds to the HTTP standard Status Code. - pub type StatusCode = u16; - /// Represents an incoming HTTP Response. - #[derive(Debug)] - #[repr(transparent)] - pub struct IncomingResponse { - handle: _rt::Resource, - } - impl IncomingResponse { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for IncomingResponse { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]incoming-response"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - /// Represents an incoming HTTP Request or Response's Body. - /// - /// A body has both its contents - a stream of bytes - and a (possibly - /// empty) set of trailers, indicating that the full contents of the - /// body have been received. This resource represents the contents as - /// an `input-stream` and the delivery of trailers as a `future-trailers`, - /// and ensures that the user of this interface may only be consuming either - /// the body contents or waiting on trailers at any given time. - #[derive(Debug)] - #[repr(transparent)] - pub struct IncomingBody { - handle: _rt::Resource, - } - impl IncomingBody { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for IncomingBody { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]incoming-body"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - /// Represents a future which may eventually return trailers, or an error. - /// - /// In the case that the incoming HTTP Request or Response did not have any - /// trailers, this future will resolve to the empty set of trailers once the - /// complete Request or Response body has been received. - #[derive(Debug)] - #[repr(transparent)] - pub struct FutureTrailers { - handle: _rt::Resource, - } - impl FutureTrailers { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for FutureTrailers { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]future-trailers"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - /// Represents an outgoing HTTP Response. - #[derive(Debug)] - #[repr(transparent)] - pub struct OutgoingResponse { - handle: _rt::Resource, - } - impl OutgoingResponse { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for OutgoingResponse { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]outgoing-response"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - /// Represents an outgoing HTTP Request or Response's Body. - /// - /// A body has both its contents - a stream of bytes - and a (possibly - /// empty) set of trailers, inducating the full contents of the body - /// have been sent. This resource represents the contents as an - /// `output-stream` child resource, and the completion of the body (with - /// optional trailers) with a static function that consumes the - /// `outgoing-body` resource, and ensures that the user of this interface - /// may not write to the body contents after the body has been finished. - /// - /// If the user code drops this resource, as opposed to calling the static - /// method `finish`, the implementation should treat the body as incomplete, - /// and that an error has occurred. The implementation should propagate this - /// error to the HTTP protocol by whatever means it has available, - /// including: corrupting the body on the wire, aborting the associated - /// Request, or sending a late status code for the Response. - #[derive(Debug)] - #[repr(transparent)] - pub struct OutgoingBody { - handle: _rt::Resource, - } - impl OutgoingBody { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for OutgoingBody { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]outgoing-body"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - /// Represents a future which may eventually return an incoming HTTP - /// Response, or an error. - /// - /// This resource is returned by the `wasi:http/outgoing-handler` interface to - /// provide the HTTP Response corresponding to the sent Request. - #[derive(Debug)] - #[repr(transparent)] - pub struct FutureIncomingResponse { - handle: _rt::Resource, - } - impl FutureIncomingResponse { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for FutureIncomingResponse { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]future-incoming-response"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - #[allow(unused_unsafe, clippy::all)] - /// Attempts to extract a http-related `error` from the wasi:io `error` - /// provided. - /// - /// Stream operations which return - /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of - /// type `wasi:io/error/error` with more information about the operation - /// that failed. This payload can be passed through to this function to see - /// if there's http-related information about the error to return. - /// - /// Note that this function is fallible because not all io-errors are - /// http-related errors. - #[allow(async_fn_in_trait)] - pub fn http_error_code(err: &IoError) -> Option { - unsafe { - #[repr(align(8))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 24 + 4 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 24 - + 4 * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "http-error-code"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((err).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result66 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = i32::from(*ptr0.add(8).cast::()); - let v65 = match l3 { - 0 => ErrorCode::DnsTimeout, - 1 => { - let e65 = { - let l4 = i32::from(*ptr0.add(16).cast::()); - let l8 = i32::from( - *ptr0 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - DnsErrorPayload { - rcode: match l4 { - 0 => None, - 1 => { - let e = { - let l5 = *ptr0 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l6 = *ptr0 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len7 = l6; - let bytes7 = _rt::Vec::from_raw_parts( - l5.cast(), - len7, - len7, - ); - _rt::string_lift(bytes7) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - info_code: match l8 { - 0 => None, - 1 => { - let e = { - let l9 = i32::from( - *ptr0 - .add(18 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - l9 as u16 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::DnsError(e65) - } - 2 => ErrorCode::DestinationNotFound, - 3 => ErrorCode::DestinationUnavailable, - 4 => ErrorCode::DestinationIpProhibited, - 5 => ErrorCode::DestinationIpUnroutable, - 6 => ErrorCode::ConnectionRefused, - 7 => ErrorCode::ConnectionTerminated, - 8 => ErrorCode::ConnectionTimeout, - 9 => ErrorCode::ConnectionReadTimeout, - 10 => ErrorCode::ConnectionWriteTimeout, - 11 => ErrorCode::ConnectionLimitReached, - 12 => ErrorCode::TlsProtocolError, - 13 => ErrorCode::TlsCertificateError, - 14 => { - let e65 = { - let l10 = i32::from(*ptr0.add(16).cast::()); - let l12 = i32::from( - *ptr0 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - TlsAlertReceivedPayload { - alert_id: match l10 { - 0 => None, - 1 => { - let e = { - let l11 = i32::from(*ptr0.add(17).cast::()); - l11 as u8 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - alert_message: match l12 { - 0 => None, - 1 => { - let e = { - let l13 = *ptr0 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l14 = *ptr0 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len15 = l14; - let bytes15 = _rt::Vec::from_raw_parts( - l13.cast(), - len15, - len15, - ); - _rt::string_lift(bytes15) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::TlsAlertReceived(e65) - } - 15 => ErrorCode::HttpRequestDenied, - 16 => ErrorCode::HttpRequestLengthRequired, - 17 => { - let e65 = { - let l16 = i32::from(*ptr0.add(16).cast::()); - match l16 { - 0 => None, - 1 => { - let e = { - let l17 = *ptr0.add(24).cast::(); - l17 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestBodySize(e65) - } - 18 => ErrorCode::HttpRequestMethodInvalid, - 19 => ErrorCode::HttpRequestUriInvalid, - 20 => ErrorCode::HttpRequestUriTooLong, - 21 => { - let e65 = { - let l18 = i32::from(*ptr0.add(16).cast::()); - match l18 { - 0 => None, - 1 => { - let e = { - let l19 = *ptr0.add(20).cast::(); - l19 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestHeaderSectionSize(e65) - } - 22 => { - let e65 = { - let l20 = i32::from(*ptr0.add(16).cast::()); - match l20 { - 0 => None, - 1 => { - let e = { - let l21 = i32::from( - *ptr0 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - let l25 = i32::from( - *ptr0 - .add(16 + 4 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l21 { - 0 => None, - 1 => { - let e = { - let l22 = *ptr0 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l23 = *ptr0 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len24 = l23; - let bytes24 = _rt::Vec::from_raw_parts( - l22.cast(), - len24, - len24, - ); - _rt::string_lift(bytes24) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l25 { - 0 => None, - 1 => { - let e = { - let l26 = *ptr0 - .add(20 + 4 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l26 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestHeaderSize(e65) - } - 23 => { - let e65 = { - let l27 = i32::from(*ptr0.add(16).cast::()); - match l27 { - 0 => None, - 1 => { - let e = { - let l28 = *ptr0.add(20).cast::(); - l28 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestTrailerSectionSize(e65) - } - 24 => { - let e65 = { - let l29 = i32::from(*ptr0.add(16).cast::()); - let l33 = i32::from( - *ptr0 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l29 { - 0 => None, - 1 => { - let e = { - let l30 = *ptr0 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l31 = *ptr0 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len32 = l31; - let bytes32 = _rt::Vec::from_raw_parts( - l30.cast(), - len32, - len32, - ); - _rt::string_lift(bytes32) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l33 { - 0 => None, - 1 => { - let e = { - let l34 = *ptr0 - .add(20 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l34 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpRequestTrailerSize(e65) - } - 25 => ErrorCode::HttpResponseIncomplete, - 26 => { - let e65 = { - let l35 = i32::from(*ptr0.add(16).cast::()); - match l35 { - 0 => None, - 1 => { - let e = { - let l36 = *ptr0.add(20).cast::(); - l36 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseHeaderSectionSize(e65) - } - 27 => { - let e65 = { - let l37 = i32::from(*ptr0.add(16).cast::()); - let l41 = i32::from( - *ptr0 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l37 { - 0 => None, - 1 => { - let e = { - let l38 = *ptr0 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l39 = *ptr0 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len40 = l39; - let bytes40 = _rt::Vec::from_raw_parts( - l38.cast(), - len40, - len40, - ); - _rt::string_lift(bytes40) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l41 { - 0 => None, - 1 => { - let e = { - let l42 = *ptr0 - .add(20 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l42 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpResponseHeaderSize(e65) - } - 28 => { - let e65 = { - let l43 = i32::from(*ptr0.add(16).cast::()); - match l43 { - 0 => None, - 1 => { - let e = { - let l44 = *ptr0.add(24).cast::(); - l44 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseBodySize(e65) - } - 29 => { - let e65 = { - let l45 = i32::from(*ptr0.add(16).cast::()); - match l45 { - 0 => None, - 1 => { - let e = { - let l46 = *ptr0.add(20).cast::(); - l46 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseTrailerSectionSize(e65) - } - 30 => { - let e65 = { - let l47 = i32::from(*ptr0.add(16).cast::()); - let l51 = i32::from( - *ptr0 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l47 { - 0 => None, - 1 => { - let e = { - let l48 = *ptr0 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l49 = *ptr0 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len50 = l49; - let bytes50 = _rt::Vec::from_raw_parts( - l48.cast(), - len50, - len50, - ); - _rt::string_lift(bytes50) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l51 { - 0 => None, - 1 => { - let e = { - let l52 = *ptr0 - .add(20 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l52 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpResponseTrailerSize(e65) - } - 31 => { - let e65 = { - let l53 = i32::from(*ptr0.add(16).cast::()); - match l53 { - 0 => None, - 1 => { - let e = { - let l54 = *ptr0 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l55 = *ptr0 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len56 = l55; - let bytes56 = _rt::Vec::from_raw_parts( - l54.cast(), - len56, - len56, - ); - _rt::string_lift(bytes56) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseTransferCoding(e65) - } - 32 => { - let e65 = { - let l57 = i32::from(*ptr0.add(16).cast::()); - match l57 { - 0 => None, - 1 => { - let e = { - let l58 = *ptr0 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l59 = *ptr0 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len60 = l59; - let bytes60 = _rt::Vec::from_raw_parts( - l58.cast(), - len60, - len60, - ); - _rt::string_lift(bytes60) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseContentCoding(e65) - } - 33 => ErrorCode::HttpResponseTimeout, - 34 => ErrorCode::HttpUpgradeFailed, - 35 => ErrorCode::HttpProtocolError, - 36 => ErrorCode::LoopDetected, - 37 => ErrorCode::ConfigurationError, - n => { - debug_assert_eq!(n, 38, "invalid enum discriminant"); - let e65 = { - let l61 = i32::from(*ptr0.add(16).cast::()); - match l61 { - 0 => None, - 1 => { - let e = { - let l62 = *ptr0 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l63 = *ptr0 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len64 = l63; - let bytes64 = _rt::Vec::from_raw_parts( - l62.cast(), - len64, - len64, - ); - _rt::string_lift(bytes64) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::InternalError(e65) - } - }; - v65 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result66 - } - } - impl Fields { - #[allow(unused_unsafe, clippy::all)] - /// Construct an empty HTTP Fields. - /// - /// The resulting `fields` is mutable. - #[allow(async_fn_in_trait)] - pub fn new() -> Self { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[constructor]fields"] - fn wit_import0() -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0() -> i32 { - unreachable!() - } - let ret = wit_import0(); - Fields::from_handle(ret as u32) - } - } - } - impl Fields { - #[allow(unused_unsafe, clippy::all)] - /// Construct an HTTP Fields. - /// - /// The resulting `fields` is mutable. - /// - /// The list represents each name-value pair in the Fields. Names - /// which have multiple values are represented by multiple entries in this - /// list with the same name. - /// - /// The tuple is a pair of the field name, represented as a string, and - /// Value, represented as a list of bytes. - /// - /// An error result will be returned if any `field-name` or `field-value` is - /// syntactically invalid, or if a field is forbidden. - #[allow(async_fn_in_trait)] - pub fn from_list( - entries: &[(FieldName, FieldValue)], - ) -> Result { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 8], - ); - let vec3 = entries; - let len3 = vec3.len(); - let layout3 = _rt::alloc::Layout::from_size_align( - vec3.len() * (4 * ::core::mem::size_of::<*const u8>()), - ::core::mem::size_of::<*const u8>(), - ) - .unwrap(); - let (result3, _cleanup3) = wit_bindgen::rt::Cleanup::new( - layout3, - ); - for (i, e) in vec3.into_iter().enumerate() { - let base = result3 - .add(i * (4 * ::core::mem::size_of::<*const u8>())); - { - let (t0_0, t0_1) = e; - let vec1 = t0_0; - let ptr1 = vec1.as_ptr().cast::(); - let len1 = vec1.len(); - *base - .add(::core::mem::size_of::<*const u8>()) - .cast::() = len1; - *base.add(0).cast::<*mut u8>() = ptr1.cast_mut(); - let vec2 = t0_1; - let ptr2 = vec2.as_ptr().cast::(); - let len2 = vec2.len(); - *base - .add(3 * ::core::mem::size_of::<*const u8>()) - .cast::() = len2; - *base - .add(2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>() = ptr2.cast_mut(); - } - } - let ptr4 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[static]fields.from-list"] - fn wit_import5(_: *mut u8, _: usize, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import5( - _: *mut u8, - _: usize, - _: *mut u8, - ) { - unreachable!() - } - wit_import5(result3, len3, ptr4); - let l6 = i32::from(*ptr4.add(0).cast::()); - let result10 = match l6 { - 0 => { - let e = { - let l7 = *ptr4.add(4).cast::(); - Fields::from_handle(l7 as u32) - }; - Ok(e) - } - 1 => { - let e = { - let l8 = i32::from(*ptr4.add(4).cast::()); - let v9 = match l8 { - 0 => HeaderError::InvalidSyntax, - 1 => HeaderError::Forbidden, - n => { - debug_assert_eq!(n, 2, "invalid enum discriminant"); - HeaderError::Immutable - } - }; - v9 - }; - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result10 - } - } - } - impl Fields { - #[allow(unused_unsafe, clippy::all)] - /// Get all of the values corresponding to a name. If the name is not present - /// in this `fields` or is syntactically invalid, an empty list is returned. - /// However, if the name is present but empty, this is represented by a list - /// with one or more empty field-values present. - #[allow(async_fn_in_trait)] - pub fn get(&self, name: &str) -> _rt::Vec { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 2 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 2 - * ::core::mem::size_of::<*const u8>()], - ); - let vec0 = name; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - let ptr1 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]fields.get"] - fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import2( - _: i32, - _: *mut u8, - _: usize, - _: *mut u8, - ) { - unreachable!() - } - wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); - let l3 = *ptr1.add(0).cast::<*mut u8>(); - let l4 = *ptr1 - .add(::core::mem::size_of::<*const u8>()) - .cast::(); - let base8 = l3; - let len8 = l4; - let mut result8 = _rt::Vec::with_capacity(len8); - for i in 0..len8 { - let base = base8 - .add(i * (2 * ::core::mem::size_of::<*const u8>())); - let e8 = { - let l5 = *base.add(0).cast::<*mut u8>(); - let l6 = *base - .add(::core::mem::size_of::<*const u8>()) - .cast::(); - let len7 = l6; - _rt::Vec::from_raw_parts(l5.cast(), len7, len7) - }; - result8.push(e8); - } - _rt::cabi_dealloc( - base8, - len8 * (2 * ::core::mem::size_of::<*const u8>()), - ::core::mem::size_of::<*const u8>(), - ); - let result9 = result8; - result9 - } - } - } - impl Fields { - #[allow(unused_unsafe, clippy::all)] - /// Returns `true` when the name is present in this `fields`. If the name is - /// syntactically invalid, `false` is returned. - #[allow(async_fn_in_trait)] - pub fn has(&self, name: &str) -> bool { - unsafe { - let vec0 = name; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]fields.has"] - fn wit_import1(_: i32, _: *mut u8, _: usize) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1( - _: i32, - _: *mut u8, - _: usize, - ) -> i32 { - unreachable!() - } - let ret = wit_import1( - (self).handle() as i32, - ptr0.cast_mut(), - len0, - ); - _rt::bool_lift(ret as u8) - } - } - } - impl Fields { - #[allow(unused_unsafe, clippy::all)] - /// Set all of the values for a name. Clears any existing values for that - /// name, if they have been set. - /// - /// Fails with `header-error.immutable` if the `fields` are immutable. - /// - /// Fails with `header-error.invalid-syntax` if the `field-name` or any of - /// the `field-value`s are syntactically invalid. - #[allow(async_fn_in_trait)] - pub fn set( - &self, - name: &str, - value: &[FieldValue], - ) -> Result<(), HeaderError> { - unsafe { - #[repr(align(1))] - struct RetArea([::core::mem::MaybeUninit; 2]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 2], - ); - let vec0 = name; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - let vec2 = value; - let len2 = vec2.len(); - let layout2 = _rt::alloc::Layout::from_size_align( - vec2.len() * (2 * ::core::mem::size_of::<*const u8>()), - ::core::mem::size_of::<*const u8>(), - ) - .unwrap(); - let (result2, _cleanup2) = wit_bindgen::rt::Cleanup::new( - layout2, - ); - for (i, e) in vec2.into_iter().enumerate() { - let base = result2 - .add(i * (2 * ::core::mem::size_of::<*const u8>())); - { - let vec1 = e; - let ptr1 = vec1.as_ptr().cast::(); - let len1 = vec1.len(); - *base - .add(::core::mem::size_of::<*const u8>()) - .cast::() = len1; - *base.add(0).cast::<*mut u8>() = ptr1.cast_mut(); - } - } - let ptr3 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]fields.set"] - fn wit_import4( - _: i32, - _: *mut u8, - _: usize, - _: *mut u8, - _: usize, - _: *mut u8, - ); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import4( - _: i32, - _: *mut u8, - _: usize, - _: *mut u8, - _: usize, - _: *mut u8, - ) { - unreachable!() - } - wit_import4( - (self).handle() as i32, - ptr0.cast_mut(), - len0, - result2, - len2, - ptr3, - ); - let l5 = i32::from(*ptr3.add(0).cast::()); - let result8 = match l5 { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = { - let l6 = i32::from(*ptr3.add(1).cast::()); - let v7 = match l6 { - 0 => HeaderError::InvalidSyntax, - 1 => HeaderError::Forbidden, - n => { - debug_assert_eq!(n, 2, "invalid enum discriminant"); - HeaderError::Immutable - } - }; - v7 - }; - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result8 - } - } - } - impl Fields { - #[allow(unused_unsafe, clippy::all)] - /// Delete all values for a name. Does nothing if no values for the name - /// exist. - /// - /// Fails with `header-error.immutable` if the `fields` are immutable. - /// - /// Fails with `header-error.invalid-syntax` if the `field-name` is - /// syntactically invalid. - #[allow(async_fn_in_trait)] - pub fn delete(&self, name: &str) -> Result<(), HeaderError> { - unsafe { - #[repr(align(1))] - struct RetArea([::core::mem::MaybeUninit; 2]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 2], - ); - let vec0 = name; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - let ptr1 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]fields.delete"] - fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import2( - _: i32, - _: *mut u8, - _: usize, - _: *mut u8, - ) { - unreachable!() - } - wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); - let l3 = i32::from(*ptr1.add(0).cast::()); - let result6 = match l3 { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = { - let l4 = i32::from(*ptr1.add(1).cast::()); - let v5 = match l4 { - 0 => HeaderError::InvalidSyntax, - 1 => HeaderError::Forbidden, - n => { - debug_assert_eq!(n, 2, "invalid enum discriminant"); - HeaderError::Immutable - } - }; - v5 - }; - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result6 - } - } - } - impl Fields { - #[allow(unused_unsafe, clippy::all)] - /// Append a value for a name. Does not change or delete any existing - /// values for that name. - /// - /// Fails with `header-error.immutable` if the `fields` are immutable. - /// - /// Fails with `header-error.invalid-syntax` if the `field-name` or - /// `field-value` are syntactically invalid. - #[allow(async_fn_in_trait)] - pub fn append( - &self, - name: &str, - value: &[u8], - ) -> Result<(), HeaderError> { - unsafe { - #[repr(align(1))] - struct RetArea([::core::mem::MaybeUninit; 2]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 2], - ); - let vec0 = name; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - let vec1 = value; - let ptr1 = vec1.as_ptr().cast::(); - let len1 = vec1.len(); - let ptr2 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]fields.append"] - fn wit_import3( - _: i32, - _: *mut u8, - _: usize, - _: *mut u8, - _: usize, - _: *mut u8, - ); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import3( - _: i32, - _: *mut u8, - _: usize, - _: *mut u8, - _: usize, - _: *mut u8, - ) { - unreachable!() - } - wit_import3( - (self).handle() as i32, - ptr0.cast_mut(), - len0, - ptr1.cast_mut(), - len1, - ptr2, - ); - let l4 = i32::from(*ptr2.add(0).cast::()); - let result7 = match l4 { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = { - let l5 = i32::from(*ptr2.add(1).cast::()); - let v6 = match l5 { - 0 => HeaderError::InvalidSyntax, - 1 => HeaderError::Forbidden, - n => { - debug_assert_eq!(n, 2, "invalid enum discriminant"); - HeaderError::Immutable - } - }; - v6 - }; - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result7 - } - } - } - impl Fields { - #[allow(unused_unsafe, clippy::all)] - /// Retrieve the full set of names and values in the Fields. Like the - /// constructor, the list represents each name-value pair. - /// - /// The outer list represents each name-value pair in the Fields. Names - /// which have multiple values are represented by multiple entries in this - /// list with the same name. - /// - /// The names and values are always returned in the original casing and in - /// the order in which they will be serialized for transport. - #[allow(async_fn_in_trait)] - pub fn entries(&self) -> _rt::Vec<(FieldName, FieldValue)> { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 2 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 2 - * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]fields.entries"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = *ptr0.add(0).cast::<*mut u8>(); - let l3 = *ptr0 - .add(::core::mem::size_of::<*const u8>()) - .cast::(); - let base10 = l2; - let len10 = l3; - let mut result10 = _rt::Vec::with_capacity(len10); - for i in 0..len10 { - let base = base10 - .add(i * (4 * ::core::mem::size_of::<*const u8>())); - let e10 = { - let l4 = *base.add(0).cast::<*mut u8>(); - let l5 = *base - .add(::core::mem::size_of::<*const u8>()) - .cast::(); - let len6 = l5; - let bytes6 = _rt::Vec::from_raw_parts( - l4.cast(), - len6, - len6, - ); - let l7 = *base - .add(2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l8 = *base - .add(3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len9 = l8; - ( - _rt::string_lift(bytes6), - _rt::Vec::from_raw_parts(l7.cast(), len9, len9), - ) - }; - result10.push(e10); - } - _rt::cabi_dealloc( - base10, - len10 * (4 * ::core::mem::size_of::<*const u8>()), - ::core::mem::size_of::<*const u8>(), - ); - let result11 = result10; - result11 - } - } - } - impl Fields { - #[allow(unused_unsafe, clippy::all)] - /// Make a deep copy of the Fields. Equivalent in behavior to calling the - /// `fields` constructor on the return value of `entries`. The resulting - /// `fields` is mutable. - #[allow(async_fn_in_trait)] - pub fn clone(&self) -> Fields { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]fields.clone"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((self).handle() as i32); - Fields::from_handle(ret as u32) - } - } - } - impl IncomingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Returns the method of the incoming request. - #[allow(async_fn_in_trait)] - pub fn method(&self) -> Method { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 3 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 3 - * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]incoming-request.method"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let v6 = match l2 { - 0 => Method::Get, - 1 => Method::Head, - 2 => Method::Post, - 3 => Method::Put, - 4 => Method::Delete, - 5 => Method::Connect, - 6 => Method::Options, - 7 => Method::Trace, - 8 => Method::Patch, - n => { - debug_assert_eq!(n, 9, "invalid enum discriminant"); - let e6 = { - let l3 = *ptr0 - .add(::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l4 = *ptr0 - .add(2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len5 = l4; - let bytes5 = _rt::Vec::from_raw_parts( - l3.cast(), - len5, - len5, - ); - _rt::string_lift(bytes5) - }; - Method::Other(e6) - } - }; - let result7 = v6; - result7 - } - } - } - impl IncomingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Returns the path with query parameters from the request, as a string. - #[allow(async_fn_in_trait)] - pub fn path_with_query(&self) -> Option<_rt::String> { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 3 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 3 - * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]incoming-request.path-with-query"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result6 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = *ptr0 - .add(::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l4 = *ptr0 - .add(2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len5 = l4; - let bytes5 = _rt::Vec::from_raw_parts( - l3.cast(), - len5, - len5, - ); - _rt::string_lift(bytes5) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result6 - } - } - } - impl IncomingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Returns the protocol scheme from the request. - #[allow(async_fn_in_trait)] - pub fn scheme(&self) -> Option { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 4 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 4 - * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]incoming-request.scheme"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result8 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = i32::from( - *ptr0.add(::core::mem::size_of::<*const u8>()).cast::(), - ); - let v7 = match l3 { - 0 => Scheme::Http, - 1 => Scheme::Https, - n => { - debug_assert_eq!(n, 2, "invalid enum discriminant"); - let e7 = { - let l4 = *ptr0 - .add(2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l5 = *ptr0 - .add(3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len6 = l5; - let bytes6 = _rt::Vec::from_raw_parts( - l4.cast(), - len6, - len6, - ); - _rt::string_lift(bytes6) - }; - Scheme::Other(e7) - } - }; - v7 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result8 - } - } - } - impl IncomingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Returns the authority of the Request's target URI, if present. - #[allow(async_fn_in_trait)] - pub fn authority(&self) -> Option<_rt::String> { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 3 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 3 - * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]incoming-request.authority"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result6 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = *ptr0 - .add(::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l4 = *ptr0 - .add(2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len5 = l4; - let bytes5 = _rt::Vec::from_raw_parts( - l3.cast(), - len5, - len5, - ); - _rt::string_lift(bytes5) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result6 - } - } - } - impl IncomingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Get the `headers` associated with the request. - /// - /// The returned `headers` resource is immutable: `set`, `append`, and - /// `delete` operations will fail with `header-error.immutable`. - /// - /// The `headers` returned are a child resource: it must be dropped before - /// the parent `incoming-request` is dropped. Dropping this - /// `incoming-request` before all children are dropped will trap. - #[allow(async_fn_in_trait)] - pub fn headers(&self) -> Headers { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]incoming-request.headers"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((self).handle() as i32); - Fields::from_handle(ret as u32) - } - } - } - impl IncomingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Gives the `incoming-body` associated with this request. Will only - /// return success at most once, and subsequent calls will return error. - #[allow(async_fn_in_trait)] - pub fn consume(&self) -> Result { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 8], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]incoming-request.consume"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result4 = match l2 { - 0 => { - let e = { - let l3 = *ptr0.add(4).cast::(); - IncomingBody::from_handle(l3 as u32) - }; - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result4 - } - } - } - impl OutgoingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Construct a new `outgoing-request` with a default `method` of `GET`, and - /// `none` values for `path-with-query`, `scheme`, and `authority`. - /// - /// * `headers` is the HTTP Headers for the Request. - /// - /// It is possible to construct, or manipulate with the accessor functions - /// below, an `outgoing-request` with an invalid combination of `scheme` - /// and `authority`, or `headers` which are not permitted to be sent. - /// It is the obligation of the `outgoing-handler.handle` implementation - /// to reject invalid constructions of `outgoing-request`. - #[allow(async_fn_in_trait)] - pub fn new(headers: Headers) -> Self { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[constructor]outgoing-request"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((&headers).take_handle() as i32); - OutgoingRequest::from_handle(ret as u32) - } - } - } - impl OutgoingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Returns the resource corresponding to the outgoing Body for this - /// Request. - /// - /// Returns success on the first call: the `outgoing-body` resource for - /// this `outgoing-request` can be retrieved at most once. Subsequent - /// calls will return error. - #[allow(async_fn_in_trait)] - pub fn body(&self) -> Result { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 8], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-request.body"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result4 = match l2 { - 0 => { - let e = { - let l3 = *ptr0.add(4).cast::(); - OutgoingBody::from_handle(l3 as u32) - }; - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result4 - } - } - } - impl OutgoingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Get the Method for the Request. - #[allow(async_fn_in_trait)] - pub fn method(&self) -> Method { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 3 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 3 - * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-request.method"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let v6 = match l2 { - 0 => Method::Get, - 1 => Method::Head, - 2 => Method::Post, - 3 => Method::Put, - 4 => Method::Delete, - 5 => Method::Connect, - 6 => Method::Options, - 7 => Method::Trace, - 8 => Method::Patch, - n => { - debug_assert_eq!(n, 9, "invalid enum discriminant"); - let e6 = { - let l3 = *ptr0 - .add(::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l4 = *ptr0 - .add(2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len5 = l4; - let bytes5 = _rt::Vec::from_raw_parts( - l3.cast(), - len5, - len5, - ); - _rt::string_lift(bytes5) - }; - Method::Other(e6) - } - }; - let result7 = v6; - result7 - } - } - } - impl OutgoingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Set the Method for the Request. Fails if the string present in a - /// `method.other` argument is not a syntactically valid method. - #[allow(async_fn_in_trait)] - pub fn set_method(&self, method: &Method) -> Result<(), ()> { - unsafe { - let (result1_0, result1_1, result1_2) = match method { - Method::Get => (0i32, ::core::ptr::null_mut(), 0usize), - Method::Head => (1i32, ::core::ptr::null_mut(), 0usize), - Method::Post => (2i32, ::core::ptr::null_mut(), 0usize), - Method::Put => (3i32, ::core::ptr::null_mut(), 0usize), - Method::Delete => (4i32, ::core::ptr::null_mut(), 0usize), - Method::Connect => (5i32, ::core::ptr::null_mut(), 0usize), - Method::Options => (6i32, ::core::ptr::null_mut(), 0usize), - Method::Trace => (7i32, ::core::ptr::null_mut(), 0usize), - Method::Patch => (8i32, ::core::ptr::null_mut(), 0usize), - Method::Other(e) => { - let vec0 = e; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - (9i32, ptr0.cast_mut(), len0) - } - }; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-request.set-method"] - fn wit_import2(_: i32, _: i32, _: *mut u8, _: usize) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import2( - _: i32, - _: i32, - _: *mut u8, - _: usize, - ) -> i32 { - unreachable!() - } - let ret = wit_import2( - (self).handle() as i32, - result1_0, - result1_1, - result1_2, - ); - match ret { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - } - } - } - impl OutgoingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Get the combination of the HTTP Path and Query for the Request. - /// When `none`, this represents an empty Path and empty Query. - #[allow(async_fn_in_trait)] - pub fn path_with_query(&self) -> Option<_rt::String> { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 3 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 3 - * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-request.path-with-query"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result6 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = *ptr0 - .add(::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l4 = *ptr0 - .add(2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len5 = l4; - let bytes5 = _rt::Vec::from_raw_parts( - l3.cast(), - len5, - len5, - ); - _rt::string_lift(bytes5) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result6 - } - } - } - impl OutgoingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Set the combination of the HTTP Path and Query for the Request. - /// When `none`, this represents an empty Path and empty Query. Fails is the - /// string given is not a syntactically valid path and query uri component. - #[allow(async_fn_in_trait)] - pub fn set_path_with_query( - &self, - path_with_query: Option<&str>, - ) -> Result<(), ()> { - unsafe { - let (result1_0, result1_1, result1_2) = match path_with_query { - Some(e) => { - let vec0 = e; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - (1i32, ptr0.cast_mut(), len0) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-request.set-path-with-query"] - fn wit_import2(_: i32, _: i32, _: *mut u8, _: usize) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import2( - _: i32, - _: i32, - _: *mut u8, - _: usize, - ) -> i32 { - unreachable!() - } - let ret = wit_import2( - (self).handle() as i32, - result1_0, - result1_1, - result1_2, - ); - match ret { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - } - } - } - impl OutgoingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Get the HTTP Related Scheme for the Request. When `none`, the - /// implementation may choose an appropriate default scheme. - #[allow(async_fn_in_trait)] - pub fn scheme(&self) -> Option { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 4 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 4 - * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-request.scheme"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result8 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = i32::from( - *ptr0.add(::core::mem::size_of::<*const u8>()).cast::(), - ); - let v7 = match l3 { - 0 => Scheme::Http, - 1 => Scheme::Https, - n => { - debug_assert_eq!(n, 2, "invalid enum discriminant"); - let e7 = { - let l4 = *ptr0 - .add(2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l5 = *ptr0 - .add(3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len6 = l5; - let bytes6 = _rt::Vec::from_raw_parts( - l4.cast(), - len6, - len6, - ); - _rt::string_lift(bytes6) - }; - Scheme::Other(e7) - } - }; - v7 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result8 - } - } - } - impl OutgoingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Set the HTTP Related Scheme for the Request. When `none`, the - /// implementation may choose an appropriate default scheme. Fails if the - /// string given is not a syntactically valid uri scheme. - #[allow(async_fn_in_trait)] - pub fn set_scheme(&self, scheme: Option<&Scheme>) -> Result<(), ()> { - unsafe { - let (result2_0, result2_1, result2_2, result2_3) = match scheme { - Some(e) => { - let (result1_0, result1_1, result1_2) = match e { - Scheme::Http => (0i32, ::core::ptr::null_mut(), 0usize), - Scheme::Https => (1i32, ::core::ptr::null_mut(), 0usize), - Scheme::Other(e) => { - let vec0 = e; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - (2i32, ptr0.cast_mut(), len0) - } - }; - (1i32, result1_0, result1_1, result1_2) - } - None => (0i32, 0i32, ::core::ptr::null_mut(), 0usize), - }; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-request.set-scheme"] - fn wit_import3( - _: i32, - _: i32, - _: i32, - _: *mut u8, - _: usize, - ) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import3( - _: i32, - _: i32, - _: i32, - _: *mut u8, - _: usize, - ) -> i32 { - unreachable!() - } - let ret = wit_import3( - (self).handle() as i32, - result2_0, - result2_1, - result2_2, - result2_3, - ); - match ret { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - } - } - } - impl OutgoingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Get the authority of the Request's target URI. A value of `none` may be used - /// with Related Schemes which do not require an authority. The HTTP and - /// HTTPS schemes always require an authority. - #[allow(async_fn_in_trait)] - pub fn authority(&self) -> Option<_rt::String> { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 3 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 3 - * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-request.authority"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result6 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = *ptr0 - .add(::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l4 = *ptr0 - .add(2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len5 = l4; - let bytes5 = _rt::Vec::from_raw_parts( - l3.cast(), - len5, - len5, - ); - _rt::string_lift(bytes5) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result6 - } - } - } - impl OutgoingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Set the authority of the Request's target URI. A value of `none` may be used - /// with Related Schemes which do not require an authority. The HTTP and - /// HTTPS schemes always require an authority. Fails if the string given is - /// not a syntactically valid URI authority. - #[allow(async_fn_in_trait)] - pub fn set_authority(&self, authority: Option<&str>) -> Result<(), ()> { - unsafe { - let (result1_0, result1_1, result1_2) = match authority { - Some(e) => { - let vec0 = e; - let ptr0 = vec0.as_ptr().cast::(); - let len0 = vec0.len(); - (1i32, ptr0.cast_mut(), len0) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-request.set-authority"] - fn wit_import2(_: i32, _: i32, _: *mut u8, _: usize) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import2( - _: i32, - _: i32, - _: *mut u8, - _: usize, - ) -> i32 { - unreachable!() - } - let ret = wit_import2( - (self).handle() as i32, - result1_0, - result1_1, - result1_2, - ); - match ret { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - } - } - } - impl OutgoingRequest { - #[allow(unused_unsafe, clippy::all)] - /// Get the headers associated with the Request. - /// - /// The returned `headers` resource is immutable: `set`, `append`, and - /// `delete` operations will fail with `header-error.immutable`. - /// - /// This headers resource is a child: it must be dropped before the parent - /// `outgoing-request` is dropped, or its ownership is transferred to - /// another component by e.g. `outgoing-handler.handle`. - #[allow(async_fn_in_trait)] - pub fn headers(&self) -> Headers { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-request.headers"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((self).handle() as i32); - Fields::from_handle(ret as u32) - } - } - } - impl RequestOptions { - #[allow(unused_unsafe, clippy::all)] - /// Construct a default `request-options` value. - #[allow(async_fn_in_trait)] - pub fn new() -> Self { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[constructor]request-options"] - fn wit_import0() -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0() -> i32 { - unreachable!() - } - let ret = wit_import0(); - RequestOptions::from_handle(ret as u32) - } - } - } - impl RequestOptions { - #[allow(unused_unsafe, clippy::all)] - /// The timeout for the initial connect to the HTTP Server. - #[allow(async_fn_in_trait)] - pub fn connect_timeout(&self) -> Option { - unsafe { - #[repr(align(8))] - struct RetArea([::core::mem::MaybeUninit; 16]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 16], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]request-options.connect-timeout"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result4 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = *ptr0.add(8).cast::(); - l3 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result4 - } - } - } - impl RequestOptions { - #[allow(unused_unsafe, clippy::all)] - /// Set the timeout for the initial connect to the HTTP Server. An error - /// return value indicates that this timeout is not supported. - #[allow(async_fn_in_trait)] - pub fn set_connect_timeout( - &self, - duration: Option, - ) -> Result<(), ()> { - unsafe { - let (result0_0, result0_1) = match duration { - Some(e) => (1i32, _rt::as_i64(e)), - None => (0i32, 0i64), - }; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]request-options.set-connect-timeout"] - fn wit_import1(_: i32, _: i32, _: i64) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: i32, _: i64) -> i32 { - unreachable!() - } - let ret = wit_import1( - (self).handle() as i32, - result0_0, - result0_1, - ); - match ret { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - } - } - } - impl RequestOptions { - #[allow(unused_unsafe, clippy::all)] - /// The timeout for receiving the first byte of the Response body. - #[allow(async_fn_in_trait)] - pub fn first_byte_timeout(&self) -> Option { - unsafe { - #[repr(align(8))] - struct RetArea([::core::mem::MaybeUninit; 16]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 16], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]request-options.first-byte-timeout"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result4 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = *ptr0.add(8).cast::(); - l3 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result4 - } - } - } - impl RequestOptions { - #[allow(unused_unsafe, clippy::all)] - /// Set the timeout for receiving the first byte of the Response body. An - /// error return value indicates that this timeout is not supported. - #[allow(async_fn_in_trait)] - pub fn set_first_byte_timeout( - &self, - duration: Option, - ) -> Result<(), ()> { - unsafe { - let (result0_0, result0_1) = match duration { - Some(e) => (1i32, _rt::as_i64(e)), - None => (0i32, 0i64), - }; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]request-options.set-first-byte-timeout"] - fn wit_import1(_: i32, _: i32, _: i64) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: i32, _: i64) -> i32 { - unreachable!() - } - let ret = wit_import1( - (self).handle() as i32, - result0_0, - result0_1, - ); - match ret { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - } - } - } - impl RequestOptions { - #[allow(unused_unsafe, clippy::all)] - /// The timeout for receiving subsequent chunks of bytes in the Response - /// body stream. - #[allow(async_fn_in_trait)] - pub fn between_bytes_timeout(&self) -> Option { - unsafe { - #[repr(align(8))] - struct RetArea([::core::mem::MaybeUninit; 16]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 16], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]request-options.between-bytes-timeout"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result4 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = *ptr0.add(8).cast::(); - l3 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result4 - } - } - } - impl RequestOptions { - #[allow(unused_unsafe, clippy::all)] - /// Set the timeout for receiving subsequent chunks of bytes in the Response - /// body stream. An error return value indicates that this timeout is not - /// supported. - #[allow(async_fn_in_trait)] - pub fn set_between_bytes_timeout( - &self, - duration: Option, - ) -> Result<(), ()> { - unsafe { - let (result0_0, result0_1) = match duration { - Some(e) => (1i32, _rt::as_i64(e)), - None => (0i32, 0i64), - }; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]request-options.set-between-bytes-timeout"] - fn wit_import1(_: i32, _: i32, _: i64) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: i32, _: i64) -> i32 { - unreachable!() - } - let ret = wit_import1( - (self).handle() as i32, - result0_0, - result0_1, - ); - match ret { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - } - } - } - impl ResponseOutparam { - #[allow(unused_unsafe, clippy::all)] - /// Set the value of the `response-outparam` to either send a response, - /// or indicate an error. - /// - /// This method consumes the `response-outparam` to ensure that it is - /// called at most once. If it is never called, the implementation - /// will respond with an error. - /// - /// The user may provide an `error` to `response` to allow the - /// implementation determine how to respond with an HTTP error response. - #[allow(async_fn_in_trait)] - pub fn set( - param: ResponseOutparam, - response: Result, - ) -> () { - unsafe { - let ( - result38_0, - result38_1, - result38_2, - result38_3, - result38_4, - result38_5, - result38_6, - result38_7, - ) = match &response { - Ok(e) => { - ( - 0i32, - (e).take_handle() as i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - Err(e) => { - let ( - result37_0, - result37_1, - result37_2, - result37_3, - result37_4, - result37_5, - result37_6, - ) = match e { - ErrorCode::DnsTimeout => { - ( - 0i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::DnsError(e) => { - let DnsErrorPayload { - rcode: rcode0, - info_code: info_code0, - } = e; - let (result2_0, result2_1, result2_2) = match rcode0 { - Some(e) => { - let vec1 = e; - let ptr1 = vec1.as_ptr().cast::(); - let len1 = vec1.len(); - (1i32, ptr1.cast_mut(), len1) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - let (result3_0, result3_1) = match info_code0 { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - ( - 1i32, - result2_0, - { - let mut t = ::core::mem::MaybeUninit::::uninit(); - t.as_mut_ptr().cast::<*mut u8>().write(result2_1); - t - }, - result2_2 as *mut u8, - result3_0 as *mut u8, - result3_1 as usize, - 0i32, - ) - } - ErrorCode::DestinationNotFound => { - ( - 2i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::DestinationUnavailable => { - ( - 3i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::DestinationIpProhibited => { - ( - 4i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::DestinationIpUnroutable => { - ( - 5i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::ConnectionRefused => { - ( - 6i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::ConnectionTerminated => { - ( - 7i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::ConnectionTimeout => { - ( - 8i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::ConnectionReadTimeout => { - ( - 9i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::ConnectionWriteTimeout => { - ( - 10i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::ConnectionLimitReached => { - ( - 11i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::TlsProtocolError => { - ( - 12i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::TlsCertificateError => { - ( - 13i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::TlsAlertReceived(e) => { - let TlsAlertReceivedPayload { - alert_id: alert_id4, - alert_message: alert_message4, - } = e; - let (result5_0, result5_1) = match alert_id4 { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - let (result7_0, result7_1, result7_2) = match alert_message4 { - Some(e) => { - let vec6 = e; - let ptr6 = vec6.as_ptr().cast::(); - let len6 = vec6.len(); - (1i32, ptr6.cast_mut(), len6) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - ( - 14i32, - result5_0, - ::core::mem::MaybeUninit::new(i64::from(result5_1) as u64), - result7_0 as *mut u8, - result7_1, - result7_2, - 0i32, - ) - } - ErrorCode::HttpRequestDenied => { - ( - 15i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpRequestLengthRequired => { - ( - 16i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpRequestBodySize(e) => { - let (result8_0, result8_1) = match e { - Some(e) => (1i32, _rt::as_i64(e)), - None => (0i32, 0i64), - }; - ( - 17i32, - result8_0, - ::core::mem::MaybeUninit::new(result8_1 as u64), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpRequestMethodInvalid => { - ( - 18i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpRequestUriInvalid => { - ( - 19i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpRequestUriTooLong => { - ( - 20i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpRequestHeaderSectionSize(e) => { - let (result9_0, result9_1) = match e { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - ( - 21i32, - result9_0, - ::core::mem::MaybeUninit::new(i64::from(result9_1) as u64), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpRequestHeaderSize(e) => { - let ( - result14_0, - result14_1, - result14_2, - result14_3, - result14_4, - result14_5, - ) = match e { - Some(e) => { - let FieldSizePayload { - field_name: field_name10, - field_size: field_size10, - } = e; - let (result12_0, result12_1, result12_2) = match field_name10 { - Some(e) => { - let vec11 = e; - let ptr11 = vec11.as_ptr().cast::(); - let len11 = vec11.len(); - (1i32, ptr11.cast_mut(), len11) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - let (result13_0, result13_1) = match field_size10 { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - ( - 1i32, - result12_0, - result12_1, - result12_2, - result13_0, - result13_1, - ) - } - None => { - (0i32, 0i32, ::core::ptr::null_mut(), 0usize, 0i32, 0i32) - } - }; - ( - 22i32, - result14_0, - ::core::mem::MaybeUninit::new(i64::from(result14_1) as u64), - result14_2, - result14_3 as *mut u8, - result14_4 as usize, - result14_5, - ) - } - ErrorCode::HttpRequestTrailerSectionSize(e) => { - let (result15_0, result15_1) = match e { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - ( - 23i32, - result15_0, - ::core::mem::MaybeUninit::new(i64::from(result15_1) as u64), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpRequestTrailerSize(e) => { - let FieldSizePayload { - field_name: field_name16, - field_size: field_size16, - } = e; - let (result18_0, result18_1, result18_2) = match field_name16 { - Some(e) => { - let vec17 = e; - let ptr17 = vec17.as_ptr().cast::(); - let len17 = vec17.len(); - (1i32, ptr17.cast_mut(), len17) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - let (result19_0, result19_1) = match field_size16 { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - ( - 24i32, - result18_0, - { - let mut t = ::core::mem::MaybeUninit::::uninit(); - t.as_mut_ptr().cast::<*mut u8>().write(result18_1); - t - }, - result18_2 as *mut u8, - result19_0 as *mut u8, - result19_1 as usize, - 0i32, - ) - } - ErrorCode::HttpResponseIncomplete => { - ( - 25i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpResponseHeaderSectionSize(e) => { - let (result20_0, result20_1) = match e { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - ( - 26i32, - result20_0, - ::core::mem::MaybeUninit::new(i64::from(result20_1) as u64), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpResponseHeaderSize(e) => { - let FieldSizePayload { - field_name: field_name21, - field_size: field_size21, - } = e; - let (result23_0, result23_1, result23_2) = match field_name21 { - Some(e) => { - let vec22 = e; - let ptr22 = vec22.as_ptr().cast::(); - let len22 = vec22.len(); - (1i32, ptr22.cast_mut(), len22) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - let (result24_0, result24_1) = match field_size21 { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - ( - 27i32, - result23_0, - { - let mut t = ::core::mem::MaybeUninit::::uninit(); - t.as_mut_ptr().cast::<*mut u8>().write(result23_1); - t - }, - result23_2 as *mut u8, - result24_0 as *mut u8, - result24_1 as usize, - 0i32, - ) - } - ErrorCode::HttpResponseBodySize(e) => { - let (result25_0, result25_1) = match e { - Some(e) => (1i32, _rt::as_i64(e)), - None => (0i32, 0i64), - }; - ( - 28i32, - result25_0, - ::core::mem::MaybeUninit::new(result25_1 as u64), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpResponseTrailerSectionSize(e) => { - let (result26_0, result26_1) = match e { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - ( - 29i32, - result26_0, - ::core::mem::MaybeUninit::new(i64::from(result26_1) as u64), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpResponseTrailerSize(e) => { - let FieldSizePayload { - field_name: field_name27, - field_size: field_size27, - } = e; - let (result29_0, result29_1, result29_2) = match field_name27 { - Some(e) => { - let vec28 = e; - let ptr28 = vec28.as_ptr().cast::(); - let len28 = vec28.len(); - (1i32, ptr28.cast_mut(), len28) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - let (result30_0, result30_1) = match field_size27 { - Some(e) => (1i32, _rt::as_i32(e)), - None => (0i32, 0i32), - }; - ( - 30i32, - result29_0, - { - let mut t = ::core::mem::MaybeUninit::::uninit(); - t.as_mut_ptr().cast::<*mut u8>().write(result29_1); - t - }, - result29_2 as *mut u8, - result30_0 as *mut u8, - result30_1 as usize, - 0i32, - ) - } - ErrorCode::HttpResponseTransferCoding(e) => { - let (result32_0, result32_1, result32_2) = match e { - Some(e) => { - let vec31 = e; - let ptr31 = vec31.as_ptr().cast::(); - let len31 = vec31.len(); - (1i32, ptr31.cast_mut(), len31) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - ( - 31i32, - result32_0, - { - let mut t = ::core::mem::MaybeUninit::::uninit(); - t.as_mut_ptr().cast::<*mut u8>().write(result32_1); - t - }, - result32_2 as *mut u8, - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpResponseContentCoding(e) => { - let (result34_0, result34_1, result34_2) = match e { - Some(e) => { - let vec33 = e; - let ptr33 = vec33.as_ptr().cast::(); - let len33 = vec33.len(); - (1i32, ptr33.cast_mut(), len33) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - ( - 32i32, - result34_0, - { - let mut t = ::core::mem::MaybeUninit::::uninit(); - t.as_mut_ptr().cast::<*mut u8>().write(result34_1); - t - }, - result34_2 as *mut u8, - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpResponseTimeout => { - ( - 33i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpUpgradeFailed => { - ( - 34i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::HttpProtocolError => { - ( - 35i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::LoopDetected => { - ( - 36i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::ConfigurationError => { - ( - 37i32, - 0i32, - ::core::mem::MaybeUninit::::zeroed(), - ::core::ptr::null_mut(), - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - ErrorCode::InternalError(e) => { - let (result36_0, result36_1, result36_2) = match e { - Some(e) => { - let vec35 = e; - let ptr35 = vec35.as_ptr().cast::(); - let len35 = vec35.len(); - (1i32, ptr35.cast_mut(), len35) - } - None => (0i32, ::core::ptr::null_mut(), 0usize), - }; - ( - 38i32, - result36_0, - { - let mut t = ::core::mem::MaybeUninit::::uninit(); - t.as_mut_ptr().cast::<*mut u8>().write(result36_1); - t - }, - result36_2 as *mut u8, - ::core::ptr::null_mut(), - 0usize, - 0i32, - ) - } - }; - ( - 1i32, - result37_0, - result37_1, - result37_2, - result37_3, - result37_4, - result37_5, - result37_6, - ) - } - }; - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[static]response-outparam.set"] - fn wit_import39( - _: i32, - _: i32, - _: i32, - _: i32, - _: ::core::mem::MaybeUninit, - _: *mut u8, - _: *mut u8, - _: usize, - _: i32, - ); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import39( - _: i32, - _: i32, - _: i32, - _: i32, - _: ::core::mem::MaybeUninit, - _: *mut u8, - _: *mut u8, - _: usize, - _: i32, - ) { - unreachable!() - } - wit_import39( - (¶m).take_handle() as i32, - result38_0, - result38_1, - result38_2, - result38_3, - result38_4, - result38_5, - result38_6, - result38_7, - ); - } - } - } - impl IncomingResponse { - #[allow(unused_unsafe, clippy::all)] - /// Returns the status code from the incoming response. - #[allow(async_fn_in_trait)] - pub fn status(&self) -> StatusCode { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]incoming-response.status"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((self).handle() as i32); - ret as u16 - } - } - } - impl IncomingResponse { - #[allow(unused_unsafe, clippy::all)] - /// Returns the headers from the incoming response. - /// - /// The returned `headers` resource is immutable: `set`, `append`, and - /// `delete` operations will fail with `header-error.immutable`. - /// - /// This headers resource is a child: it must be dropped before the parent - /// `incoming-response` is dropped. - #[allow(async_fn_in_trait)] - pub fn headers(&self) -> Headers { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]incoming-response.headers"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((self).handle() as i32); - Fields::from_handle(ret as u32) - } - } - } - impl IncomingResponse { - #[allow(unused_unsafe, clippy::all)] - /// Returns the incoming body. May be called at most once. Returns error - /// if called additional times. - #[allow(async_fn_in_trait)] - pub fn consume(&self) -> Result { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 8], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]incoming-response.consume"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result4 = match l2 { - 0 => { - let e = { - let l3 = *ptr0.add(4).cast::(); - IncomingBody::from_handle(l3 as u32) - }; - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result4 - } - } - } - impl IncomingBody { - #[allow(unused_unsafe, clippy::all)] - /// Returns the contents of the body, as a stream of bytes. - /// - /// Returns success on first call: the stream representing the contents - /// can be retrieved at most once. Subsequent calls will return error. - /// - /// The returned `input-stream` resource is a child: it must be dropped - /// before the parent `incoming-body` is dropped, or consumed by - /// `incoming-body.finish`. - /// - /// This invariant ensures that the implementation can determine whether - /// the user is consuming the contents of the body, waiting on the - /// `future-trailers` to be ready, or neither. This allows for network - /// backpressure is to be applied when the user is consuming the body, - /// and for that backpressure to not inhibit delivery of the trailers if - /// the user does not read the entire body. - #[allow(async_fn_in_trait)] - pub fn stream(&self) -> Result { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 8], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]incoming-body.stream"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result4 = match l2 { - 0 => { - let e = { - let l3 = *ptr0.add(4).cast::(); - super::super::super::wasi::io::streams::InputStream::from_handle( - l3 as u32, - ) - }; - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result4 - } - } - } - impl IncomingBody { - #[allow(unused_unsafe, clippy::all)] - /// Takes ownership of `incoming-body`, and returns a `future-trailers`. - /// This function will trap if the `input-stream` child is still alive. - #[allow(async_fn_in_trait)] - pub fn finish(this: IncomingBody) -> FutureTrailers { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[static]incoming-body.finish"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((&this).take_handle() as i32); - FutureTrailers::from_handle(ret as u32) - } - } - } - impl FutureTrailers { - #[allow(unused_unsafe, clippy::all)] - /// Returns a pollable which becomes ready when either the trailers have - /// been received, or an error has occurred. When this pollable is ready, - /// the `get` method will return `some`. - #[allow(async_fn_in_trait)] - pub fn subscribe(&self) -> Pollable { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]future-trailers.subscribe"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((self).handle() as i32); - super::super::super::wasi::io::poll::Pollable::from_handle( - ret as u32, - ) - } - } - } - impl FutureTrailers { - #[allow(unused_unsafe, clippy::all)] - /// Returns the contents of the trailers, or an error which occurred, - /// once the future is ready. - /// - /// The outer `option` represents future readiness. Users can wait on this - /// `option` to become `some` using the `subscribe` method. - /// - /// The outer `result` is used to retrieve the trailers or error at most - /// once. It will be success on the first call in which the outer option - /// is `some`, and error on subsequent calls. - /// - /// The inner `result` represents that either the HTTP Request or Response - /// body, as well as any trailers, were received successfully, or that an - /// error occurred receiving them. The optional `trailers` indicates whether - /// or not trailers were present in the body. - /// - /// When some `trailers` are returned by this method, the `trailers` - /// resource is immutable, and a child. Use of the `set`, `append`, or - /// `delete` methods will return an error, and the resource must be - /// dropped before the parent `future-trailers` is dropped. - #[allow(async_fn_in_trait)] - pub fn get( - &self, - ) -> Option, ErrorCode>, ()>> { - unsafe { - #[repr(align(8))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 40 + 4 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 40 - + 4 * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]future-trailers.get"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result70 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = i32::from(*ptr0.add(8).cast::()); - match l3 { - 0 => { - let e = { - let l4 = i32::from(*ptr0.add(16).cast::()); - match l4 { - 0 => { - let e = { - let l5 = i32::from(*ptr0.add(24).cast::()); - match l5 { - 0 => None, - 1 => { - let e = { - let l6 = *ptr0.add(28).cast::(); - Fields::from_handle(l6 as u32) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - Ok(e) - } - 1 => { - let e = { - let l7 = i32::from(*ptr0.add(24).cast::()); - let v69 = match l7 { - 0 => ErrorCode::DnsTimeout, - 1 => { - let e69 = { - let l8 = i32::from(*ptr0.add(32).cast::()); - let l12 = i32::from( - *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - DnsErrorPayload { - rcode: match l8 { - 0 => None, - 1 => { - let e = { - let l9 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l10 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len11 = l10; - let bytes11 = _rt::Vec::from_raw_parts( - l9.cast(), - len11, - len11, - ); - _rt::string_lift(bytes11) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - info_code: match l12 { - 0 => None, - 1 => { - let e = { - let l13 = i32::from( - *ptr0 - .add(34 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - l13 as u16 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::DnsError(e69) - } - 2 => ErrorCode::DestinationNotFound, - 3 => ErrorCode::DestinationUnavailable, - 4 => ErrorCode::DestinationIpProhibited, - 5 => ErrorCode::DestinationIpUnroutable, - 6 => ErrorCode::ConnectionRefused, - 7 => ErrorCode::ConnectionTerminated, - 8 => ErrorCode::ConnectionTimeout, - 9 => ErrorCode::ConnectionReadTimeout, - 10 => ErrorCode::ConnectionWriteTimeout, - 11 => ErrorCode::ConnectionLimitReached, - 12 => ErrorCode::TlsProtocolError, - 13 => ErrorCode::TlsCertificateError, - 14 => { - let e69 = { - let l14 = i32::from(*ptr0.add(32).cast::()); - let l16 = i32::from( - *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - TlsAlertReceivedPayload { - alert_id: match l14 { - 0 => None, - 1 => { - let e = { - let l15 = i32::from(*ptr0.add(33).cast::()); - l15 as u8 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - alert_message: match l16 { - 0 => None, - 1 => { - let e = { - let l17 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l18 = *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len19 = l18; - let bytes19 = _rt::Vec::from_raw_parts( - l17.cast(), - len19, - len19, - ); - _rt::string_lift(bytes19) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::TlsAlertReceived(e69) - } - 15 => ErrorCode::HttpRequestDenied, - 16 => ErrorCode::HttpRequestLengthRequired, - 17 => { - let e69 = { - let l20 = i32::from(*ptr0.add(32).cast::()); - match l20 { - 0 => None, - 1 => { - let e = { - let l21 = *ptr0.add(40).cast::(); - l21 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestBodySize(e69) - } - 18 => ErrorCode::HttpRequestMethodInvalid, - 19 => ErrorCode::HttpRequestUriInvalid, - 20 => ErrorCode::HttpRequestUriTooLong, - 21 => { - let e69 = { - let l22 = i32::from(*ptr0.add(32).cast::()); - match l22 { - 0 => None, - 1 => { - let e = { - let l23 = *ptr0.add(36).cast::(); - l23 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestHeaderSectionSize(e69) - } - 22 => { - let e69 = { - let l24 = i32::from(*ptr0.add(32).cast::()); - match l24 { - 0 => None, - 1 => { - let e = { - let l25 = i32::from( - *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - let l29 = i32::from( - *ptr0 - .add(32 + 4 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l25 { - 0 => None, - 1 => { - let e = { - let l26 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l27 = *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len28 = l27; - let bytes28 = _rt::Vec::from_raw_parts( - l26.cast(), - len28, - len28, - ); - _rt::string_lift(bytes28) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l29 { - 0 => None, - 1 => { - let e = { - let l30 = *ptr0 - .add(36 + 4 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l30 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestHeaderSize(e69) - } - 23 => { - let e69 = { - let l31 = i32::from(*ptr0.add(32).cast::()); - match l31 { - 0 => None, - 1 => { - let e = { - let l32 = *ptr0.add(36).cast::(); - l32 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestTrailerSectionSize(e69) - } - 24 => { - let e69 = { - let l33 = i32::from(*ptr0.add(32).cast::()); - let l37 = i32::from( - *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l33 { - 0 => None, - 1 => { - let e = { - let l34 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l35 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len36 = l35; - let bytes36 = _rt::Vec::from_raw_parts( - l34.cast(), - len36, - len36, - ); - _rt::string_lift(bytes36) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l37 { - 0 => None, - 1 => { - let e = { - let l38 = *ptr0 - .add(36 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l38 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpRequestTrailerSize(e69) - } - 25 => ErrorCode::HttpResponseIncomplete, - 26 => { - let e69 = { - let l39 = i32::from(*ptr0.add(32).cast::()); - match l39 { - 0 => None, - 1 => { - let e = { - let l40 = *ptr0.add(36).cast::(); - l40 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseHeaderSectionSize(e69) - } - 27 => { - let e69 = { - let l41 = i32::from(*ptr0.add(32).cast::()); - let l45 = i32::from( - *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l41 { - 0 => None, - 1 => { - let e = { - let l42 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l43 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len44 = l43; - let bytes44 = _rt::Vec::from_raw_parts( - l42.cast(), - len44, - len44, - ); - _rt::string_lift(bytes44) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l45 { - 0 => None, - 1 => { - let e = { - let l46 = *ptr0 - .add(36 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l46 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpResponseHeaderSize(e69) - } - 28 => { - let e69 = { - let l47 = i32::from(*ptr0.add(32).cast::()); - match l47 { - 0 => None, - 1 => { - let e = { - let l48 = *ptr0.add(40).cast::(); - l48 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseBodySize(e69) - } - 29 => { - let e69 = { - let l49 = i32::from(*ptr0.add(32).cast::()); - match l49 { - 0 => None, - 1 => { - let e = { - let l50 = *ptr0.add(36).cast::(); - l50 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseTrailerSectionSize(e69) - } - 30 => { - let e69 = { - let l51 = i32::from(*ptr0.add(32).cast::()); - let l55 = i32::from( - *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l51 { - 0 => None, - 1 => { - let e = { - let l52 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l53 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len54 = l53; - let bytes54 = _rt::Vec::from_raw_parts( - l52.cast(), - len54, - len54, - ); - _rt::string_lift(bytes54) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l55 { - 0 => None, - 1 => { - let e = { - let l56 = *ptr0 - .add(36 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l56 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpResponseTrailerSize(e69) - } - 31 => { - let e69 = { - let l57 = i32::from(*ptr0.add(32).cast::()); - match l57 { - 0 => None, - 1 => { - let e = { - let l58 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l59 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len60 = l59; - let bytes60 = _rt::Vec::from_raw_parts( - l58.cast(), - len60, - len60, - ); - _rt::string_lift(bytes60) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseTransferCoding(e69) - } - 32 => { - let e69 = { - let l61 = i32::from(*ptr0.add(32).cast::()); - match l61 { - 0 => None, - 1 => { - let e = { - let l62 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l63 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len64 = l63; - let bytes64 = _rt::Vec::from_raw_parts( - l62.cast(), - len64, - len64, - ); - _rt::string_lift(bytes64) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseContentCoding(e69) - } - 33 => ErrorCode::HttpResponseTimeout, - 34 => ErrorCode::HttpUpgradeFailed, - 35 => ErrorCode::HttpProtocolError, - 36 => ErrorCode::LoopDetected, - 37 => ErrorCode::ConfigurationError, - n => { - debug_assert_eq!(n, 38, "invalid enum discriminant"); - let e69 = { - let l65 = i32::from(*ptr0.add(32).cast::()); - match l65 { - 0 => None, - 1 => { - let e = { - let l66 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l67 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len68 = l67; - let bytes68 = _rt::Vec::from_raw_parts( - l66.cast(), - len68, - len68, - ); - _rt::string_lift(bytes68) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::InternalError(e69) - } - }; - v69 - }; - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result70 - } - } - } - impl OutgoingResponse { - #[allow(unused_unsafe, clippy::all)] - /// Construct an `outgoing-response`, with a default `status-code` of `200`. - /// If a different `status-code` is needed, it must be set via the - /// `set-status-code` method. - /// - /// * `headers` is the HTTP Headers for the Response. - #[allow(async_fn_in_trait)] - pub fn new(headers: Headers) -> Self { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[constructor]outgoing-response"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((&headers).take_handle() as i32); - OutgoingResponse::from_handle(ret as u32) - } - } - } - impl OutgoingResponse { - #[allow(unused_unsafe, clippy::all)] - /// Get the HTTP Status Code for the Response. - #[allow(async_fn_in_trait)] - pub fn status_code(&self) -> StatusCode { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-response.status-code"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((self).handle() as i32); - ret as u16 - } - } - } - impl OutgoingResponse { - #[allow(unused_unsafe, clippy::all)] - /// Set the HTTP Status Code for the Response. Fails if the status-code - /// given is not a valid http status code. - #[allow(async_fn_in_trait)] - pub fn set_status_code( - &self, - status_code: StatusCode, - ) -> Result<(), ()> { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-response.set-status-code"] - fn wit_import0(_: i32, _: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32, _: i32) -> i32 { - unreachable!() - } - let ret = wit_import0( - (self).handle() as i32, - _rt::as_i32(status_code), - ); - match ret { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - } - } - } - impl OutgoingResponse { - #[allow(unused_unsafe, clippy::all)] - /// Get the headers associated with the Request. - /// - /// The returned `headers` resource is immutable: `set`, `append`, and - /// `delete` operations will fail with `header-error.immutable`. - /// - /// This headers resource is a child: it must be dropped before the parent - /// `outgoing-request` is dropped, or its ownership is transferred to - /// another component by e.g. `outgoing-handler.handle`. - #[allow(async_fn_in_trait)] - pub fn headers(&self) -> Headers { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-response.headers"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((self).handle() as i32); - Fields::from_handle(ret as u32) - } - } - } - impl OutgoingResponse { - #[allow(unused_unsafe, clippy::all)] - /// Returns the resource corresponding to the outgoing Body for this Response. - /// - /// Returns success on the first call: the `outgoing-body` resource for - /// this `outgoing-response` can be retrieved at most once. Subsequent - /// calls will return error. - #[allow(async_fn_in_trait)] - pub fn body(&self) -> Result { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 8], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-response.body"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result4 = match l2 { - 0 => { - let e = { - let l3 = *ptr0.add(4).cast::(); - OutgoingBody::from_handle(l3 as u32) - }; - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result4 - } - } - } - impl OutgoingBody { - #[allow(unused_unsafe, clippy::all)] - /// Returns a stream for writing the body contents. - /// - /// The returned `output-stream` is a child resource: it must be dropped - /// before the parent `outgoing-body` resource is dropped (or finished), - /// otherwise the `outgoing-body` drop or `finish` will trap. - /// - /// Returns success on the first call: the `output-stream` resource for - /// this `outgoing-body` may be retrieved at most once. Subsequent calls - /// will return error. - #[allow(async_fn_in_trait)] - pub fn write(&self) -> Result { - unsafe { - #[repr(align(4))] - struct RetArea([::core::mem::MaybeUninit; 8]); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 8], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]outgoing-body.write"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result4 = match l2 { - 0 => { - let e = { - let l3 = *ptr0.add(4).cast::(); - super::super::super::wasi::io::streams::OutputStream::from_handle( - l3 as u32, - ) - }; - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result4 - } - } - } - impl OutgoingBody { - #[allow(unused_unsafe, clippy::all)] - /// Finalize an outgoing body, optionally providing trailers. This must be - /// called to signal that the response is complete. If the `outgoing-body` - /// is dropped without calling `outgoing-body.finalize`, the implementation - /// should treat the body as corrupted. - /// - /// Fails if the body's `outgoing-request` or `outgoing-response` was - /// constructed with a Content-Length header, and the contents written - /// to the body (via `write`) does not match the value given in the - /// Content-Length. - #[allow(async_fn_in_trait)] - pub fn finish( - this: OutgoingBody, - trailers: Option, - ) -> Result<(), ErrorCode> { - unsafe { - #[repr(align(8))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 24 + 4 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 24 - + 4 * ::core::mem::size_of::<*const u8>()], - ); - let (result0_0, result0_1) = match &trailers { - Some(e) => (1i32, (e).take_handle() as i32), - None => (0i32, 0i32), - }; - let ptr1 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[static]outgoing-body.finish"] - fn wit_import2(_: i32, _: i32, _: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import2( - _: i32, - _: i32, - _: i32, - _: *mut u8, - ) { - unreachable!() - } - wit_import2( - (&this).take_handle() as i32, - result0_0, - result0_1, - ptr1, - ); - let l3 = i32::from(*ptr1.add(0).cast::()); - let result67 = match l3 { - 0 => { - let e = (); - Ok(e) - } - 1 => { - let e = { - let l4 = i32::from(*ptr1.add(8).cast::()); - let v66 = match l4 { - 0 => ErrorCode::DnsTimeout, - 1 => { - let e66 = { - let l5 = i32::from(*ptr1.add(16).cast::()); - let l9 = i32::from( - *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - DnsErrorPayload { - rcode: match l5 { - 0 => None, - 1 => { - let e = { - let l6 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l7 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len8 = l7; - let bytes8 = _rt::Vec::from_raw_parts( - l6.cast(), - len8, - len8, - ); - _rt::string_lift(bytes8) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - info_code: match l9 { - 0 => None, - 1 => { - let e = { - let l10 = i32::from( - *ptr1 - .add(18 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - l10 as u16 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::DnsError(e66) - } - 2 => ErrorCode::DestinationNotFound, - 3 => ErrorCode::DestinationUnavailable, - 4 => ErrorCode::DestinationIpProhibited, - 5 => ErrorCode::DestinationIpUnroutable, - 6 => ErrorCode::ConnectionRefused, - 7 => ErrorCode::ConnectionTerminated, - 8 => ErrorCode::ConnectionTimeout, - 9 => ErrorCode::ConnectionReadTimeout, - 10 => ErrorCode::ConnectionWriteTimeout, - 11 => ErrorCode::ConnectionLimitReached, - 12 => ErrorCode::TlsProtocolError, - 13 => ErrorCode::TlsCertificateError, - 14 => { - let e66 = { - let l11 = i32::from(*ptr1.add(16).cast::()); - let l13 = i32::from( - *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - TlsAlertReceivedPayload { - alert_id: match l11 { - 0 => None, - 1 => { - let e = { - let l12 = i32::from(*ptr1.add(17).cast::()); - l12 as u8 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - alert_message: match l13 { - 0 => None, - 1 => { - let e = { - let l14 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l15 = *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len16 = l15; - let bytes16 = _rt::Vec::from_raw_parts( - l14.cast(), - len16, - len16, - ); - _rt::string_lift(bytes16) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::TlsAlertReceived(e66) - } - 15 => ErrorCode::HttpRequestDenied, - 16 => ErrorCode::HttpRequestLengthRequired, - 17 => { - let e66 = { - let l17 = i32::from(*ptr1.add(16).cast::()); - match l17 { - 0 => None, - 1 => { - let e = { - let l18 = *ptr1.add(24).cast::(); - l18 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestBodySize(e66) - } - 18 => ErrorCode::HttpRequestMethodInvalid, - 19 => ErrorCode::HttpRequestUriInvalid, - 20 => ErrorCode::HttpRequestUriTooLong, - 21 => { - let e66 = { - let l19 = i32::from(*ptr1.add(16).cast::()); - match l19 { - 0 => None, - 1 => { - let e = { - let l20 = *ptr1.add(20).cast::(); - l20 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestHeaderSectionSize(e66) - } - 22 => { - let e66 = { - let l21 = i32::from(*ptr1.add(16).cast::()); - match l21 { - 0 => None, - 1 => { - let e = { - let l22 = i32::from( - *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - let l26 = i32::from( - *ptr1 - .add(16 + 4 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l22 { - 0 => None, - 1 => { - let e = { - let l23 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l24 = *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len25 = l24; - let bytes25 = _rt::Vec::from_raw_parts( - l23.cast(), - len25, - len25, - ); - _rt::string_lift(bytes25) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l26 { - 0 => None, - 1 => { - let e = { - let l27 = *ptr1 - .add(20 + 4 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l27 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestHeaderSize(e66) - } - 23 => { - let e66 = { - let l28 = i32::from(*ptr1.add(16).cast::()); - match l28 { - 0 => None, - 1 => { - let e = { - let l29 = *ptr1.add(20).cast::(); - l29 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestTrailerSectionSize(e66) - } - 24 => { - let e66 = { - let l30 = i32::from(*ptr1.add(16).cast::()); - let l34 = i32::from( - *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l30 { - 0 => None, - 1 => { - let e = { - let l31 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l32 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len33 = l32; - let bytes33 = _rt::Vec::from_raw_parts( - l31.cast(), - len33, - len33, - ); - _rt::string_lift(bytes33) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l34 { - 0 => None, - 1 => { - let e = { - let l35 = *ptr1 - .add(20 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l35 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpRequestTrailerSize(e66) - } - 25 => ErrorCode::HttpResponseIncomplete, - 26 => { - let e66 = { - let l36 = i32::from(*ptr1.add(16).cast::()); - match l36 { - 0 => None, - 1 => { - let e = { - let l37 = *ptr1.add(20).cast::(); - l37 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseHeaderSectionSize(e66) - } - 27 => { - let e66 = { - let l38 = i32::from(*ptr1.add(16).cast::()); - let l42 = i32::from( - *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l38 { - 0 => None, - 1 => { - let e = { - let l39 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l40 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len41 = l40; - let bytes41 = _rt::Vec::from_raw_parts( - l39.cast(), - len41, - len41, - ); - _rt::string_lift(bytes41) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l42 { - 0 => None, - 1 => { - let e = { - let l43 = *ptr1 - .add(20 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l43 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpResponseHeaderSize(e66) - } - 28 => { - let e66 = { - let l44 = i32::from(*ptr1.add(16).cast::()); - match l44 { - 0 => None, - 1 => { - let e = { - let l45 = *ptr1.add(24).cast::(); - l45 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseBodySize(e66) - } - 29 => { - let e66 = { - let l46 = i32::from(*ptr1.add(16).cast::()); - match l46 { - 0 => None, - 1 => { - let e = { - let l47 = *ptr1.add(20).cast::(); - l47 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseTrailerSectionSize(e66) - } - 30 => { - let e66 = { - let l48 = i32::from(*ptr1.add(16).cast::()); - let l52 = i32::from( - *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l48 { - 0 => None, - 1 => { - let e = { - let l49 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l50 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len51 = l50; - let bytes51 = _rt::Vec::from_raw_parts( - l49.cast(), - len51, - len51, - ); - _rt::string_lift(bytes51) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l52 { - 0 => None, - 1 => { - let e = { - let l53 = *ptr1 - .add(20 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l53 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpResponseTrailerSize(e66) - } - 31 => { - let e66 = { - let l54 = i32::from(*ptr1.add(16).cast::()); - match l54 { - 0 => None, - 1 => { - let e = { - let l55 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l56 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len57 = l56; - let bytes57 = _rt::Vec::from_raw_parts( - l55.cast(), - len57, - len57, - ); - _rt::string_lift(bytes57) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseTransferCoding(e66) - } - 32 => { - let e66 = { - let l58 = i32::from(*ptr1.add(16).cast::()); - match l58 { - 0 => None, - 1 => { - let e = { - let l59 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l60 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len61 = l60; - let bytes61 = _rt::Vec::from_raw_parts( - l59.cast(), - len61, - len61, - ); - _rt::string_lift(bytes61) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseContentCoding(e66) - } - 33 => ErrorCode::HttpResponseTimeout, - 34 => ErrorCode::HttpUpgradeFailed, - 35 => ErrorCode::HttpProtocolError, - 36 => ErrorCode::LoopDetected, - 37 => ErrorCode::ConfigurationError, - n => { - debug_assert_eq!(n, 38, "invalid enum discriminant"); - let e66 = { - let l62 = i32::from(*ptr1.add(16).cast::()); - match l62 { - 0 => None, - 1 => { - let e = { - let l63 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l64 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len65 = l64; - let bytes65 = _rt::Vec::from_raw_parts( - l63.cast(), - len65, - len65, - ); - _rt::string_lift(bytes65) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::InternalError(e66) - } - }; - v66 - }; - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result67 - } - } - } - impl FutureIncomingResponse { - #[allow(unused_unsafe, clippy::all)] - /// Returns a pollable which becomes ready when either the Response has - /// been received, or an error has occurred. When this pollable is ready, - /// the `get` method will return `some`. - #[allow(async_fn_in_trait)] - pub fn subscribe(&self) -> Pollable { - unsafe { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]future-incoming-response.subscribe"] - fn wit_import0(_: i32) -> i32; - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import0(_: i32) -> i32 { - unreachable!() - } - let ret = wit_import0((self).handle() as i32); - super::super::super::wasi::io::poll::Pollable::from_handle( - ret as u32, - ) - } - } - } - impl FutureIncomingResponse { - #[allow(unused_unsafe, clippy::all)] - /// Returns the incoming HTTP Response, or an error, once one is ready. - /// - /// The outer `option` represents future readiness. Users can wait on this - /// `option` to become `some` using the `subscribe` method. - /// - /// The outer `result` is used to retrieve the response or error at most - /// once. It will be success on the first call in which the outer option - /// is `some`, and error on subsequent calls. - /// - /// The inner `result` represents that either the incoming HTTP Response - /// status and headers have received successfully, or that an error - /// occurred. Errors may also occur while consuming the response body, - /// but those will be reported by the `incoming-body` and its - /// `output-stream` child. - #[allow(async_fn_in_trait)] - pub fn get( - &self, - ) -> Option, ()>> { - unsafe { - #[repr(align(8))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 40 + 4 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 40 - + 4 * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/types@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]future-incoming-response.get"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = i32::from(*ptr0.add(0).cast::()); - let result69 = match l2 { - 0 => None, - 1 => { - let e = { - let l3 = i32::from(*ptr0.add(8).cast::()); - match l3 { - 0 => { - let e = { - let l4 = i32::from(*ptr0.add(16).cast::()); - match l4 { - 0 => { - let e = { - let l5 = *ptr0.add(24).cast::(); - IncomingResponse::from_handle(l5 as u32) - }; - Ok(e) - } - 1 => { - let e = { - let l6 = i32::from(*ptr0.add(24).cast::()); - let v68 = match l6 { - 0 => ErrorCode::DnsTimeout, - 1 => { - let e68 = { - let l7 = i32::from(*ptr0.add(32).cast::()); - let l11 = i32::from( - *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - DnsErrorPayload { - rcode: match l7 { - 0 => None, - 1 => { - let e = { - let l8 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l9 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len10 = l9; - let bytes10 = _rt::Vec::from_raw_parts( - l8.cast(), - len10, - len10, - ); - _rt::string_lift(bytes10) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - info_code: match l11 { - 0 => None, - 1 => { - let e = { - let l12 = i32::from( - *ptr0 - .add(34 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - l12 as u16 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::DnsError(e68) - } - 2 => ErrorCode::DestinationNotFound, - 3 => ErrorCode::DestinationUnavailable, - 4 => ErrorCode::DestinationIpProhibited, - 5 => ErrorCode::DestinationIpUnroutable, - 6 => ErrorCode::ConnectionRefused, - 7 => ErrorCode::ConnectionTerminated, - 8 => ErrorCode::ConnectionTimeout, - 9 => ErrorCode::ConnectionReadTimeout, - 10 => ErrorCode::ConnectionWriteTimeout, - 11 => ErrorCode::ConnectionLimitReached, - 12 => ErrorCode::TlsProtocolError, - 13 => ErrorCode::TlsCertificateError, - 14 => { - let e68 = { - let l13 = i32::from(*ptr0.add(32).cast::()); - let l15 = i32::from( - *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - TlsAlertReceivedPayload { - alert_id: match l13 { - 0 => None, - 1 => { - let e = { - let l14 = i32::from(*ptr0.add(33).cast::()); - l14 as u8 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - alert_message: match l15 { - 0 => None, - 1 => { - let e = { - let l16 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l17 = *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len18 = l17; - let bytes18 = _rt::Vec::from_raw_parts( - l16.cast(), - len18, - len18, - ); - _rt::string_lift(bytes18) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::TlsAlertReceived(e68) - } - 15 => ErrorCode::HttpRequestDenied, - 16 => ErrorCode::HttpRequestLengthRequired, - 17 => { - let e68 = { - let l19 = i32::from(*ptr0.add(32).cast::()); - match l19 { - 0 => None, - 1 => { - let e = { - let l20 = *ptr0.add(40).cast::(); - l20 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestBodySize(e68) - } - 18 => ErrorCode::HttpRequestMethodInvalid, - 19 => ErrorCode::HttpRequestUriInvalid, - 20 => ErrorCode::HttpRequestUriTooLong, - 21 => { - let e68 = { - let l21 = i32::from(*ptr0.add(32).cast::()); - match l21 { - 0 => None, - 1 => { - let e = { - let l22 = *ptr0.add(36).cast::(); - l22 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestHeaderSectionSize(e68) - } - 22 => { - let e68 = { - let l23 = i32::from(*ptr0.add(32).cast::()); - match l23 { - 0 => None, - 1 => { - let e = { - let l24 = i32::from( - *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - let l28 = i32::from( - *ptr0 - .add(32 + 4 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l24 { - 0 => None, - 1 => { - let e = { - let l25 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l26 = *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len27 = l26; - let bytes27 = _rt::Vec::from_raw_parts( - l25.cast(), - len27, - len27, - ); - _rt::string_lift(bytes27) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l28 { - 0 => None, - 1 => { - let e = { - let l29 = *ptr0 - .add(36 + 4 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l29 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestHeaderSize(e68) - } - 23 => { - let e68 = { - let l30 = i32::from(*ptr0.add(32).cast::()); - match l30 { - 0 => None, - 1 => { - let e = { - let l31 = *ptr0.add(36).cast::(); - l31 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpRequestTrailerSectionSize(e68) - } - 24 => { - let e68 = { - let l32 = i32::from(*ptr0.add(32).cast::()); - let l36 = i32::from( - *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l32 { - 0 => None, - 1 => { - let e = { - let l33 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l34 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len35 = l34; - let bytes35 = _rt::Vec::from_raw_parts( - l33.cast(), - len35, - len35, - ); - _rt::string_lift(bytes35) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l36 { - 0 => None, - 1 => { - let e = { - let l37 = *ptr0 - .add(36 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l37 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpRequestTrailerSize(e68) - } - 25 => ErrorCode::HttpResponseIncomplete, - 26 => { - let e68 = { - let l38 = i32::from(*ptr0.add(32).cast::()); - match l38 { - 0 => None, - 1 => { - let e = { - let l39 = *ptr0.add(36).cast::(); - l39 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseHeaderSectionSize(e68) - } - 27 => { - let e68 = { - let l40 = i32::from(*ptr0.add(32).cast::()); - let l44 = i32::from( - *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l40 { - 0 => None, - 1 => { - let e = { - let l41 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l42 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len43 = l42; - let bytes43 = _rt::Vec::from_raw_parts( - l41.cast(), - len43, - len43, - ); - _rt::string_lift(bytes43) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l44 { - 0 => None, - 1 => { - let e = { - let l45 = *ptr0 - .add(36 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l45 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpResponseHeaderSize(e68) - } - 28 => { - let e68 = { - let l46 = i32::from(*ptr0.add(32).cast::()); - match l46 { - 0 => None, - 1 => { - let e = { - let l47 = *ptr0.add(40).cast::(); - l47 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseBodySize(e68) - } - 29 => { - let e68 = { - let l48 = i32::from(*ptr0.add(32).cast::()); - match l48 { - 0 => None, - 1 => { - let e = { - let l49 = *ptr0.add(36).cast::(); - l49 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseTrailerSectionSize(e68) - } - 30 => { - let e68 = { - let l50 = i32::from(*ptr0.add(32).cast::()); - let l54 = i32::from( - *ptr0 - .add(32 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - FieldSizePayload { - field_name: match l50 { - 0 => None, - 1 => { - let e = { - let l51 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l52 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len53 = l52; - let bytes53 = _rt::Vec::from_raw_parts( - l51.cast(), - len53, - len53, - ); - _rt::string_lift(bytes53) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l54 { - 0 => None, - 1 => { - let e = { - let l55 = *ptr0 - .add(36 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l55 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - ErrorCode::HttpResponseTrailerSize(e68) - } - 31 => { - let e68 = { - let l56 = i32::from(*ptr0.add(32).cast::()); - match l56 { - 0 => None, - 1 => { - let e = { - let l57 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l58 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len59 = l58; - let bytes59 = _rt::Vec::from_raw_parts( - l57.cast(), - len59, - len59, - ); - _rt::string_lift(bytes59) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseTransferCoding(e68) - } - 32 => { - let e68 = { - let l60 = i32::from(*ptr0.add(32).cast::()); - match l60 { - 0 => None, - 1 => { - let e = { - let l61 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l62 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len63 = l62; - let bytes63 = _rt::Vec::from_raw_parts( - l61.cast(), - len63, - len63, - ); - _rt::string_lift(bytes63) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::HttpResponseContentCoding(e68) - } - 33 => ErrorCode::HttpResponseTimeout, - 34 => ErrorCode::HttpUpgradeFailed, - 35 => ErrorCode::HttpProtocolError, - 36 => ErrorCode::LoopDetected, - 37 => ErrorCode::ConfigurationError, - n => { - debug_assert_eq!(n, 38, "invalid enum discriminant"); - let e68 = { - let l64 = i32::from(*ptr0.add(32).cast::()); - match l64 { - 0 => None, - 1 => { - let e = { - let l65 = *ptr0 - .add(32 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l66 = *ptr0 - .add(32 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len67 = l66; - let bytes67 = _rt::Vec::from_raw_parts( - l65.cast(), - len67, - len67, - ); - _rt::string_lift(bytes67) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - ErrorCode::InternalError(e68) - } - }; - v68 - }; - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - Ok(e) - } - 1 => { - let e = (); - Err(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }; - result69 - } - } - } - } - /// This interface defines a handler of outgoing HTTP Requests. It should be - /// imported by components which wish to make HTTP Requests. + pub mod io { #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] - pub mod outgoing_handler { + pub mod error { #[used] #[doc(hidden)] static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; use super::super::super::_rt; - pub type OutgoingRequest = super::super::super::wasi::http::types::OutgoingRequest; - pub type RequestOptions = super::super::super::wasi::http::types::RequestOptions; - pub type FutureIncomingResponse = super::super::super::wasi::http::types::FutureIncomingResponse; - pub type ErrorCode = super::super::super::wasi::http::types::ErrorCode; - #[allow(unused_unsafe, clippy::all)] - /// This function is invoked with an outgoing HTTP Request, and it returns - /// a resource `future-incoming-response` which represents an HTTP Response - /// which may arrive in the future. + /// A resource which represents some error information. /// - /// The `options` argument accepts optional parameters for the HTTP - /// protocol's transport layer. + /// The only method provided by this resource is `to-debug-string`, + /// which provides some human-readable information about the error. /// - /// This function may return an error if the `outgoing-request` is invalid - /// or not allowed to be made. Otherwise, protocol errors are reported - /// through the `future-incoming-response`. - #[allow(async_fn_in_trait)] - pub fn handle( - request: OutgoingRequest, - options: Option, - ) -> Result { - unsafe { - #[repr(align(8))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 24 + 4 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 24 - + 4 * ::core::mem::size_of::<*const u8>()], - ); - let (result0_0, result0_1) = match &options { - Some(e) => (1i32, (e).take_handle() as i32), - None => (0i32, 0i32), - }; - let ptr1 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:http/outgoing-handler@0.2.4")] - unsafe extern "C" { - #[link_name = "handle"] - fn wit_import2(_: i32, _: i32, _: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import2( - _: i32, - _: i32, - _: i32, - _: *mut u8, - ) { - unreachable!() - } - wit_import2( - (&request).take_handle() as i32, - result0_0, - result0_1, - ptr1, - ); - let l3 = i32::from(*ptr1.add(0).cast::()); - let result68 = match l3 { - 0 => { - let e = { - let l4 = *ptr1.add(8).cast::(); - super::super::super::wasi::http::types::FutureIncomingResponse::from_handle( - l4 as u32, - ) - }; - Ok(e) - } - 1 => { - let e = { - let l5 = i32::from(*ptr1.add(8).cast::()); - use super::super::super::wasi::http::types::ErrorCode as V67; - let v67 = match l5 { - 0 => V67::DnsTimeout, - 1 => { - let e67 = { - let l6 = i32::from(*ptr1.add(16).cast::()); - let l10 = i32::from( - *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - super::super::super::wasi::http::types::DnsErrorPayload { - rcode: match l6 { - 0 => None, - 1 => { - let e = { - let l7 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l8 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len9 = l8; - let bytes9 = _rt::Vec::from_raw_parts( - l7.cast(), - len9, - len9, - ); - _rt::string_lift(bytes9) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - info_code: match l10 { - 0 => None, - 1 => { - let e = { - let l11 = i32::from( - *ptr1 - .add(18 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - l11 as u16 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - V67::DnsError(e67) - } - 2 => V67::DestinationNotFound, - 3 => V67::DestinationUnavailable, - 4 => V67::DestinationIpProhibited, - 5 => V67::DestinationIpUnroutable, - 6 => V67::ConnectionRefused, - 7 => V67::ConnectionTerminated, - 8 => V67::ConnectionTimeout, - 9 => V67::ConnectionReadTimeout, - 10 => V67::ConnectionWriteTimeout, - 11 => V67::ConnectionLimitReached, - 12 => V67::TlsProtocolError, - 13 => V67::TlsCertificateError, - 14 => { - let e67 = { - let l12 = i32::from(*ptr1.add(16).cast::()); - let l14 = i32::from( - *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - super::super::super::wasi::http::types::TlsAlertReceivedPayload { - alert_id: match l12 { - 0 => None, - 1 => { - let e = { - let l13 = i32::from(*ptr1.add(17).cast::()); - l13 as u8 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - alert_message: match l14 { - 0 => None, - 1 => { - let e = { - let l15 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l16 = *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len17 = l16; - let bytes17 = _rt::Vec::from_raw_parts( - l15.cast(), - len17, - len17, - ); - _rt::string_lift(bytes17) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - V67::TlsAlertReceived(e67) - } - 15 => V67::HttpRequestDenied, - 16 => V67::HttpRequestLengthRequired, - 17 => { - let e67 = { - let l18 = i32::from(*ptr1.add(16).cast::()); - match l18 { - 0 => None, - 1 => { - let e = { - let l19 = *ptr1.add(24).cast::(); - l19 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - V67::HttpRequestBodySize(e67) - } - 18 => V67::HttpRequestMethodInvalid, - 19 => V67::HttpRequestUriInvalid, - 20 => V67::HttpRequestUriTooLong, - 21 => { - let e67 = { - let l20 = i32::from(*ptr1.add(16).cast::()); - match l20 { - 0 => None, - 1 => { - let e = { - let l21 = *ptr1.add(20).cast::(); - l21 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - V67::HttpRequestHeaderSectionSize(e67) - } - 22 => { - let e67 = { - let l22 = i32::from(*ptr1.add(16).cast::()); - match l22 { - 0 => None, - 1 => { - let e = { - let l23 = i32::from( - *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - let l27 = i32::from( - *ptr1 - .add(16 + 4 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - super::super::super::wasi::http::types::FieldSizePayload { - field_name: match l23 { - 0 => None, - 1 => { - let e = { - let l24 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l25 = *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len26 = l25; - let bytes26 = _rt::Vec::from_raw_parts( - l24.cast(), - len26, - len26, - ); - _rt::string_lift(bytes26) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l27 { - 0 => None, - 1 => { - let e = { - let l28 = *ptr1 - .add(20 + 4 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l28 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - V67::HttpRequestHeaderSize(e67) - } - 23 => { - let e67 = { - let l29 = i32::from(*ptr1.add(16).cast::()); - match l29 { - 0 => None, - 1 => { - let e = { - let l30 = *ptr1.add(20).cast::(); - l30 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - V67::HttpRequestTrailerSectionSize(e67) - } - 24 => { - let e67 = { - let l31 = i32::from(*ptr1.add(16).cast::()); - let l35 = i32::from( - *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - super::super::super::wasi::http::types::FieldSizePayload { - field_name: match l31 { - 0 => None, - 1 => { - let e = { - let l32 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l33 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len34 = l33; - let bytes34 = _rt::Vec::from_raw_parts( - l32.cast(), - len34, - len34, - ); - _rt::string_lift(bytes34) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l35 { - 0 => None, - 1 => { - let e = { - let l36 = *ptr1 - .add(20 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l36 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - V67::HttpRequestTrailerSize(e67) - } - 25 => V67::HttpResponseIncomplete, - 26 => { - let e67 = { - let l37 = i32::from(*ptr1.add(16).cast::()); - match l37 { - 0 => None, - 1 => { - let e = { - let l38 = *ptr1.add(20).cast::(); - l38 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - V67::HttpResponseHeaderSectionSize(e67) - } - 27 => { - let e67 = { - let l39 = i32::from(*ptr1.add(16).cast::()); - let l43 = i32::from( - *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - super::super::super::wasi::http::types::FieldSizePayload { - field_name: match l39 { - 0 => None, - 1 => { - let e = { - let l40 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l41 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len42 = l41; - let bytes42 = _rt::Vec::from_raw_parts( - l40.cast(), - len42, - len42, - ); - _rt::string_lift(bytes42) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l43 { - 0 => None, - 1 => { - let e = { - let l44 = *ptr1 - .add(20 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l44 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - V67::HttpResponseHeaderSize(e67) - } - 28 => { - let e67 = { - let l45 = i32::from(*ptr1.add(16).cast::()); - match l45 { - 0 => None, - 1 => { - let e = { - let l46 = *ptr1.add(24).cast::(); - l46 as u64 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - V67::HttpResponseBodySize(e67) - } - 29 => { - let e67 = { - let l47 = i32::from(*ptr1.add(16).cast::()); - match l47 { - 0 => None, - 1 => { - let e = { - let l48 = *ptr1.add(20).cast::(); - l48 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - V67::HttpResponseTrailerSectionSize(e67) - } - 30 => { - let e67 = { - let l49 = i32::from(*ptr1.add(16).cast::()); - let l53 = i32::from( - *ptr1 - .add(16 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(), - ); - super::super::super::wasi::http::types::FieldSizePayload { - field_name: match l49 { - 0 => None, - 1 => { - let e = { - let l50 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l51 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len52 = l51; - let bytes52 = _rt::Vec::from_raw_parts( - l50.cast(), - len52, - len52, - ); - _rt::string_lift(bytes52) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - field_size: match l53 { - 0 => None, - 1 => { - let e = { - let l54 = *ptr1 - .add(20 + 3 * ::core::mem::size_of::<*const u8>()) - .cast::(); - l54 as u32 - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - }, - } - }; - V67::HttpResponseTrailerSize(e67) - } - 31 => { - let e67 = { - let l55 = i32::from(*ptr1.add(16).cast::()); - match l55 { - 0 => None, - 1 => { - let e = { - let l56 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l57 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len58 = l57; - let bytes58 = _rt::Vec::from_raw_parts( - l56.cast(), - len58, - len58, - ); - _rt::string_lift(bytes58) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - V67::HttpResponseTransferCoding(e67) - } - 32 => { - let e67 = { - let l59 = i32::from(*ptr1.add(16).cast::()); - match l59 { - 0 => None, - 1 => { - let e = { - let l60 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l61 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len62 = l61; - let bytes62 = _rt::Vec::from_raw_parts( - l60.cast(), - len62, - len62, - ); - _rt::string_lift(bytes62) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - V67::HttpResponseContentCoding(e67) - } - 33 => V67::HttpResponseTimeout, - 34 => V67::HttpUpgradeFailed, - 35 => V67::HttpProtocolError, - 36 => V67::LoopDetected, - 37 => V67::ConfigurationError, - n => { - debug_assert_eq!(n, 38, "invalid enum discriminant"); - let e67 = { - let l63 = i32::from(*ptr1.add(16).cast::()); - match l63 { - 0 => None, - 1 => { - let e = { - let l64 = *ptr1 - .add(16 + 1 * ::core::mem::size_of::<*const u8>()) - .cast::<*mut u8>(); - let l65 = *ptr1 - .add(16 + 2 * ::core::mem::size_of::<*const u8>()) - .cast::(); - let len66 = l65; - let bytes66 = _rt::Vec::from_raw_parts( - l64.cast(), - len66, - len66, - ); - _rt::string_lift(bytes66) - }; - Some(e) - } - _ => _rt::invalid_enum_discriminant(), - } - }; - V67::InternalError(e67) - } - }; - v67 - }; - Err(e) + /// In the `wasi:io` package, this resource is returned through the + /// `wasi:io/streams/stream-error` type. + /// + /// To provide more specific error information, other interfaces may + /// offer functions to "downcast" this error into more specific types. For example, + /// errors returned from streams derived from filesystem types can be described using + /// the filesystem's own error-code type. This is done using the function + /// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow` + /// parameter and returns an `option`. + /// + /// The set of functions which can "downcast" an `error` into a more + /// concrete type is open. + #[derive(Debug)] + #[repr(transparent)] + pub struct Error { + handle: _rt::Resource, + } + impl Error { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for Error { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/error@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]error"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + impl Error { + #[allow(unused_unsafe, clippy::all)] + /// Returns a string that is suitable to assist humans in debugging + /// this error. + /// + /// WARNING: The returned string should not be consumed mechanically! + /// It may change across platforms, hosts, or other implementation + /// details. Parsing this string is a major platform-compatibility + /// hazard. + #[allow(async_fn_in_trait)] + pub fn to_debug_string(&self) -> _rt::String { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 2 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 2 + * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:io/error@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]error.to-debug-string"] + fn wit_import1(_: i32, _: *mut u8); } - _ => _rt::invalid_enum_discriminant(), - }; - result68 + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = *ptr0.add(0).cast::<*mut u8>(); + let l3 = *ptr0 + .add(::core::mem::size_of::<*const u8>()) + .cast::(); + let len4 = l3; + let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4); + let result5 = _rt::string_lift(bytes4); + result5 + } } } } - } - pub mod io { /// A poll API intended to let users wait for I/O events on multiple handles /// at once. #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] @@ -10582,115 +3881,6 @@ pub mod wasi { } } } - #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] - pub mod error { - #[used] - #[doc(hidden)] - static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; - use super::super::super::_rt; - /// A resource which represents some error information. - /// - /// The only method provided by this resource is `to-debug-string`, - /// which provides some human-readable information about the error. - /// - /// In the `wasi:io` package, this resource is returned through the - /// `wasi:io/streams/stream-error` type. - /// - /// To provide more specific error information, other interfaces may - /// offer functions to "downcast" this error into more specific types. For example, - /// errors returned from streams derived from filesystem types can be described using - /// the filesystem's own error-code type. This is done using the function - /// `wasi:filesystem/types/filesystem-error-code`, which takes a `borrow` - /// parameter and returns an `option`. - /// - /// The set of functions which can "downcast" an `error` into a more - /// concrete type is open. - #[derive(Debug)] - #[repr(transparent)] - pub struct Error { - handle: _rt::Resource, - } - impl Error { - #[doc(hidden)] - pub unsafe fn from_handle(handle: u32) -> Self { - Self { - handle: unsafe { _rt::Resource::from_handle(handle) }, - } - } - #[doc(hidden)] - pub fn take_handle(&self) -> u32 { - _rt::Resource::take_handle(&self.handle) - } - #[doc(hidden)] - pub fn handle(&self) -> u32 { - _rt::Resource::handle(&self.handle) - } - } - unsafe impl _rt::WasmResource for Error { - #[inline] - unsafe fn drop(_handle: u32) { - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:io/error@0.2.4")] - unsafe extern "C" { - #[link_name = "[resource-drop]error"] - fn drop(_: i32); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn drop(_: i32) { - unreachable!() - } - unsafe { - drop(_handle as i32); - } - } - } - impl Error { - #[allow(unused_unsafe, clippy::all)] - /// Returns a string that is suitable to assist humans in debugging - /// this error. - /// - /// WARNING: The returned string should not be consumed mechanically! - /// It may change across platforms, hosts, or other implementation - /// details. Parsing this string is a major platform-compatibility - /// hazard. - #[allow(async_fn_in_trait)] - pub fn to_debug_string(&self) -> _rt::String { - unsafe { - #[cfg_attr(target_pointer_width = "64", repr(align(8)))] - #[cfg_attr(target_pointer_width = "32", repr(align(4)))] - struct RetArea( - [::core::mem::MaybeUninit< - u8, - >; 2 * ::core::mem::size_of::<*const u8>()], - ); - let mut ret_area = RetArea( - [::core::mem::MaybeUninit::uninit(); 2 - * ::core::mem::size_of::<*const u8>()], - ); - let ptr0 = ret_area.0.as_mut_ptr().cast::(); - #[cfg(target_arch = "wasm32")] - #[link(wasm_import_module = "wasi:io/error@0.2.4")] - unsafe extern "C" { - #[link_name = "[method]error.to-debug-string"] - fn wit_import1(_: i32, _: *mut u8); - } - #[cfg(not(target_arch = "wasm32"))] - unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { - unreachable!() - } - wit_import1((self).handle() as i32, ptr0); - let l2 = *ptr0.add(0).cast::<*mut u8>(); - let l3 = *ptr0 - .add(::core::mem::size_of::<*const u8>()) - .cast::(); - let len4 = l3; - let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4); - let result5 = _rt::string_lift(bytes4); - result5 - } - } - } - } /// WASI I/O is an I/O abstraction API which is currently focused on providing /// stream types. /// @@ -16620,6 +9810,31 @@ pub mod wasi { #[rustfmt::skip] mod _rt { #![allow(dead_code, clippy::all)] + pub use alloc_crate::vec::Vec; + pub use alloc_crate::string::String; + pub unsafe fn string_lift(bytes: Vec) -> String { + if cfg!(debug_assertions) { + String::from_utf8(bytes).unwrap() + } else { + unsafe { String::from_utf8_unchecked(bytes) } + } + } + pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { + if size == 0 { + return; + } + unsafe { + let layout = alloc::Layout::from_size_align_unchecked(size, align); + alloc::dealloc(ptr, layout); + } + } + pub unsafe fn invalid_enum_discriminant() -> T { + if cfg!(debug_assertions) { + panic!("invalid enum discriminant") + } else { + unsafe { core::hint::unreachable_unchecked() } + } + } use core::fmt; use core::marker; use core::sync::atomic::{AtomicU32, Ordering::Relaxed}; @@ -16705,7 +9920,6 @@ mod _rt { val != 0 } } - pub use alloc_crate::vec::Vec; pub use alloc_crate::alloc; pub fn as_i64(t: T) -> i64 { t.as_i64() @@ -16730,30 +9944,6 @@ mod _rt { self as i64 } } - pub use alloc_crate::string::String; - pub unsafe fn string_lift(bytes: Vec) -> String { - if cfg!(debug_assertions) { - String::from_utf8(bytes).unwrap() - } else { - unsafe { String::from_utf8_unchecked(bytes) } - } - } - pub unsafe fn invalid_enum_discriminant() -> T { - if cfg!(debug_assertions) { - panic!("invalid enum discriminant") - } else { - unsafe { core::hint::unreachable_unchecked() } - } - } - pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { - if size == 0 { - return; - } - unsafe { - let layout = alloc::Layout::from_size_align_unchecked(size, align); - alloc::dealloc(ptr, layout); - } - } pub fn as_i32(t: T) -> i32 { t.as_i32() } @@ -16818,323 +10008,229 @@ mod _rt { #[rustfmt::skip] #[cfg(target_arch = "wasm32")] -#[cfg_attr(feature = "rustc-dep-of-std", unsafe(link_section = "component-type:wit-bindgen:0.45.0:rust:wasi:bindings:encoded worldrust-wasi-from-crates-io-in-libstd"))] -#[cfg_attr(not(feature = "rustc-dep-of-std"), unsafe(link_section = "component-type:wit-bindgen:0.45.0:rust:wasi:bindings:encoded worldrust-wasi-from-crates-io"))] +#[cfg_attr(feature = "rustc-dep-of-std", unsafe(link_section = "component-type:wit-bindgen:0.45.0:wasi:cli@0.2.4:imports:encoded worldrust-wasi-from-crates-io-in-libstd"))] +#[cfg_attr(not(feature = "rustc-dep-of-std"), unsafe(link_section = "component-type:wit-bindgen:0.45.0:wasi:cli@0.2.4:imports:encoded worldrust-wasi-from-crates-io"))] #[doc(hidden)] #[allow(clippy::octal_escapes)] -pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 15623] = *b"\ -\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\x88y\x01A\x02\x01AO\x01\ -B\x0a\x04\0\x08pollable\x03\x01\x01h\0\x01@\x01\x04self\x01\0\x7f\x04\0\x16[meth\ -od]pollable.ready\x01\x02\x01@\x01\x04self\x01\x01\0\x04\0\x16[method]pollable.b\ -lock\x01\x03\x01p\x01\x01py\x01@\x01\x02in\x04\0\x05\x04\0\x04poll\x01\x06\x03\0\ -\x12wasi:io/poll@0.2.4\x05\0\x02\x03\0\0\x08pollable\x01B\x0f\x02\x03\x02\x01\x01\ -\x04\0\x08pollable\x03\0\0\x01w\x04\0\x07instant\x03\0\x02\x01w\x04\0\x08duratio\ -n\x03\0\x04\x01@\0\0\x03\x04\0\x03now\x01\x06\x01@\0\0\x05\x04\0\x0aresolution\x01\ -\x07\x01i\x01\x01@\x01\x04when\x03\0\x08\x04\0\x11subscribe-instant\x01\x09\x01@\ -\x01\x04when\x05\0\x08\x04\0\x12subscribe-duration\x01\x0a\x03\0!wasi:clocks/mon\ -otonic-clock@0.2.4\x05\x02\x01B\x04\x04\0\x05error\x03\x01\x01h\0\x01@\x01\x04se\ -lf\x01\0s\x04\0\x1d[method]error.to-debug-string\x01\x02\x03\0\x13wasi:io/error@\ -0.2.4\x05\x03\x02\x03\0\x02\x05error\x01B(\x02\x03\x02\x01\x04\x04\0\x05error\x03\ -\0\0\x02\x03\x02\x01\x01\x04\0\x08pollable\x03\0\x02\x01i\x01\x01q\x02\x15last-o\ -peration-failed\x01\x04\0\x06closed\0\0\x04\0\x0cstream-error\x03\0\x05\x04\0\x0c\ -input-stream\x03\x01\x04\0\x0doutput-stream\x03\x01\x01h\x07\x01p}\x01j\x01\x0a\x01\ -\x06\x01@\x02\x04self\x09\x03lenw\0\x0b\x04\0\x19[method]input-stream.read\x01\x0c\ -\x04\0\"[method]input-stream.blocking-read\x01\x0c\x01j\x01w\x01\x06\x01@\x02\x04\ -self\x09\x03lenw\0\x0d\x04\0\x19[method]input-stream.skip\x01\x0e\x04\0\"[method\ -]input-stream.blocking-skip\x01\x0e\x01i\x03\x01@\x01\x04self\x09\0\x0f\x04\0\x1e\ -[method]input-stream.subscribe\x01\x10\x01h\x08\x01@\x01\x04self\x11\0\x0d\x04\0\ -![method]output-stream.check-write\x01\x12\x01j\0\x01\x06\x01@\x02\x04self\x11\x08\ -contents\x0a\0\x13\x04\0\x1b[method]output-stream.write\x01\x14\x04\0.[method]ou\ -tput-stream.blocking-write-and-flush\x01\x14\x01@\x01\x04self\x11\0\x13\x04\0\x1b\ -[method]output-stream.flush\x01\x15\x04\0$[method]output-stream.blocking-flush\x01\ -\x15\x01@\x01\x04self\x11\0\x0f\x04\0\x1f[method]output-stream.subscribe\x01\x16\ -\x01@\x02\x04self\x11\x03lenw\0\x13\x04\0\"[method]output-stream.write-zeroes\x01\ -\x17\x04\05[method]output-stream.blocking-write-zeroes-and-flush\x01\x17\x01@\x03\ -\x04self\x11\x03src\x09\x03lenw\0\x0d\x04\0\x1c[method]output-stream.splice\x01\x18\ -\x04\0%[method]output-stream.blocking-splice\x01\x18\x03\0\x15wasi:io/streams@0.\ -2.4\x05\x05\x02\x03\0\x01\x08duration\x02\x03\0\x03\x0cinput-stream\x02\x03\0\x03\ -\x0doutput-stream\x01B\xc1\x01\x02\x03\x02\x01\x06\x04\0\x08duration\x03\0\0\x02\ -\x03\x02\x01\x07\x04\0\x0cinput-stream\x03\0\x02\x02\x03\x02\x01\x08\x04\0\x0dou\ -tput-stream\x03\0\x04\x02\x03\x02\x01\x04\x04\0\x08io-error\x03\0\x06\x02\x03\x02\ -\x01\x01\x04\0\x08pollable\x03\0\x08\x01q\x0a\x03get\0\0\x04head\0\0\x04post\0\0\ -\x03put\0\0\x06delete\0\0\x07connect\0\0\x07options\0\0\x05trace\0\0\x05patch\0\0\ -\x05other\x01s\0\x04\0\x06method\x03\0\x0a\x01q\x03\x04HTTP\0\0\x05HTTPS\0\0\x05\ -other\x01s\0\x04\0\x06scheme\x03\0\x0c\x01ks\x01k{\x01r\x02\x05rcode\x0e\x09info\ --code\x0f\x04\0\x11DNS-error-payload\x03\0\x10\x01k}\x01r\x02\x08alert-id\x12\x0d\ -alert-message\x0e\x04\0\x1aTLS-alert-received-payload\x03\0\x13\x01ky\x01r\x02\x0a\ -field-name\x0e\x0afield-size\x15\x04\0\x12field-size-payload\x03\0\x16\x01kw\x01\ -k\x17\x01q'\x0bDNS-timeout\0\0\x09DNS-error\x01\x11\0\x15destination-not-found\0\ -\0\x17destination-unavailable\0\0\x19destination-IP-prohibited\0\0\x19destinatio\ -n-IP-unroutable\0\0\x12connection-refused\0\0\x15connection-terminated\0\0\x12co\ -nnection-timeout\0\0\x17connection-read-timeout\0\0\x18connection-write-timeout\0\ -\0\x18connection-limit-reached\0\0\x12TLS-protocol-error\0\0\x15TLS-certificate-\ -error\0\0\x12TLS-alert-received\x01\x14\0\x13HTTP-request-denied\0\0\x1cHTTP-req\ -uest-length-required\0\0\x16HTTP-request-body-size\x01\x18\0\x1bHTTP-request-met\ -hod-invalid\0\0\x18HTTP-request-URI-invalid\0\0\x19HTTP-request-URI-too-long\0\0\ -\x20HTTP-request-header-section-size\x01\x15\0\x18HTTP-request-header-size\x01\x19\ -\0!HTTP-request-trailer-section-size\x01\x15\0\x19HTTP-request-trailer-size\x01\x17\ -\0\x18HTTP-response-incomplete\0\0!HTTP-response-header-section-size\x01\x15\0\x19\ -HTTP-response-header-size\x01\x17\0\x17HTTP-response-body-size\x01\x18\0\"HTTP-r\ -esponse-trailer-section-size\x01\x15\0\x1aHTTP-response-trailer-size\x01\x17\0\x1d\ -HTTP-response-transfer-coding\x01\x0e\0\x1cHTTP-response-content-coding\x01\x0e\0\ -\x15HTTP-response-timeout\0\0\x13HTTP-upgrade-failed\0\0\x13HTTP-protocol-error\0\ -\0\x0dloop-detected\0\0\x13configuration-error\0\0\x0einternal-error\x01\x0e\0\x04\ -\0\x0aerror-code\x03\0\x1a\x01q\x03\x0einvalid-syntax\0\0\x09forbidden\0\0\x09im\ -mutable\0\0\x04\0\x0cheader-error\x03\0\x1c\x01s\x04\0\x09field-key\x03\0\x1e\x04\ -\0\x0afield-name\x03\0\x1f\x01p}\x04\0\x0bfield-value\x03\0!\x04\0\x06fields\x03\ -\x01\x04\0\x07headers\x03\0#\x04\0\x08trailers\x03\0#\x04\0\x10incoming-request\x03\ -\x01\x04\0\x10outgoing-request\x03\x01\x04\0\x0frequest-options\x03\x01\x04\0\x11\ -response-outparam\x03\x01\x01{\x04\0\x0bstatus-code\x03\0*\x04\0\x11incoming-res\ -ponse\x03\x01\x04\0\x0dincoming-body\x03\x01\x04\0\x0ffuture-trailers\x03\x01\x04\ -\0\x11outgoing-response\x03\x01\x04\0\x0doutgoing-body\x03\x01\x04\0\x18future-i\ -ncoming-response\x03\x01\x01i#\x01@\0\02\x04\0\x13[constructor]fields\x013\x01o\x02\ -\x20\"\x01p4\x01j\x012\x01\x1d\x01@\x01\x07entries5\06\x04\0\x18[static]fields.f\ -rom-list\x017\x01h#\x01p\"\x01@\x02\x04self8\x04name\x20\09\x04\0\x12[method]fie\ -lds.get\x01:\x01@\x02\x04self8\x04name\x20\0\x7f\x04\0\x12[method]fields.has\x01\ -;\x01j\0\x01\x1d\x01@\x03\x04self8\x04name\x20\x05value9\0<\x04\0\x12[method]fie\ -lds.set\x01=\x01@\x02\x04self8\x04name\x20\0<\x04\0\x15[method]fields.delete\x01\ ->\x01@\x03\x04self8\x04name\x20\x05value\"\0<\x04\0\x15[method]fields.append\x01\ -?\x01@\x01\x04self8\05\x04\0\x16[method]fields.entries\x01@\x01@\x01\x04self8\02\ -\x04\0\x14[method]fields.clone\x01A\x01h&\x01@\x01\x04self\xc2\0\0\x0b\x04\0\x1f\ -[method]incoming-request.method\x01C\x01@\x01\x04self\xc2\0\0\x0e\x04\0([method]\ -incoming-request.path-with-query\x01D\x01k\x0d\x01@\x01\x04self\xc2\0\0\xc5\0\x04\ -\0\x1f[method]incoming-request.scheme\x01F\x04\0\"[method]incoming-request.autho\ -rity\x01D\x01i$\x01@\x01\x04self\xc2\0\0\xc7\0\x04\0\x20[method]incoming-request\ -.headers\x01H\x01i-\x01j\x01\xc9\0\0\x01@\x01\x04self\xc2\0\0\xca\0\x04\0\x20[me\ -thod]incoming-request.consume\x01K\x01i'\x01@\x01\x07headers\xc7\0\0\xcc\0\x04\0\ -\x1d[constructor]outgoing-request\x01M\x01h'\x01i0\x01j\x01\xcf\0\0\x01@\x01\x04\ -self\xce\0\0\xd0\0\x04\0\x1d[method]outgoing-request.body\x01Q\x01@\x01\x04self\xce\ -\0\0\x0b\x04\0\x1f[method]outgoing-request.method\x01R\x01j\0\0\x01@\x02\x04self\ -\xce\0\x06method\x0b\0\xd3\0\x04\0#[method]outgoing-request.set-method\x01T\x01@\ -\x01\x04self\xce\0\0\x0e\x04\0([method]outgoing-request.path-with-query\x01U\x01\ -@\x02\x04self\xce\0\x0fpath-with-query\x0e\0\xd3\0\x04\0,[method]outgoing-reques\ -t.set-path-with-query\x01V\x01@\x01\x04self\xce\0\0\xc5\0\x04\0\x1f[method]outgo\ -ing-request.scheme\x01W\x01@\x02\x04self\xce\0\x06scheme\xc5\0\0\xd3\0\x04\0#[me\ -thod]outgoing-request.set-scheme\x01X\x04\0\"[method]outgoing-request.authority\x01\ -U\x01@\x02\x04self\xce\0\x09authority\x0e\0\xd3\0\x04\0&[method]outgoing-request\ -.set-authority\x01Y\x01@\x01\x04self\xce\0\0\xc7\0\x04\0\x20[method]outgoing-req\ -uest.headers\x01Z\x01i(\x01@\0\0\xdb\0\x04\0\x1c[constructor]request-options\x01\ -\\\x01h(\x01k\x01\x01@\x01\x04self\xdd\0\0\xde\0\x04\0'[method]request-options.c\ -onnect-timeout\x01_\x01@\x02\x04self\xdd\0\x08duration\xde\0\0\xd3\0\x04\0+[meth\ -od]request-options.set-connect-timeout\x01`\x04\0*[method]request-options.first-\ -byte-timeout\x01_\x04\0.[method]request-options.set-first-byte-timeout\x01`\x04\0\ --[method]request-options.between-bytes-timeout\x01_\x04\01[method]request-option\ -s.set-between-bytes-timeout\x01`\x01i)\x01i/\x01j\x01\xe2\0\x01\x1b\x01@\x02\x05\ -param\xe1\0\x08response\xe3\0\x01\0\x04\0\x1d[static]response-outparam.set\x01d\x01\ -h,\x01@\x01\x04self\xe5\0\0+\x04\0\x20[method]incoming-response.status\x01f\x01@\ -\x01\x04self\xe5\0\0\xc7\0\x04\0![method]incoming-response.headers\x01g\x01@\x01\ -\x04self\xe5\0\0\xca\0\x04\0![method]incoming-response.consume\x01h\x01h-\x01i\x03\ -\x01j\x01\xea\0\0\x01@\x01\x04self\xe9\0\0\xeb\0\x04\0\x1c[method]incoming-body.\ -stream\x01l\x01i.\x01@\x01\x04this\xc9\0\0\xed\0\x04\0\x1c[static]incoming-body.\ -finish\x01n\x01h.\x01i\x09\x01@\x01\x04self\xef\0\0\xf0\0\x04\0![method]future-t\ -railers.subscribe\x01q\x01i%\x01k\xf2\0\x01j\x01\xf3\0\x01\x1b\x01j\x01\xf4\0\0\x01\ -k\xf5\0\x01@\x01\x04self\xef\0\0\xf6\0\x04\0\x1b[method]future-trailers.get\x01w\ -\x01@\x01\x07headers\xc7\0\0\xe2\0\x04\0\x1e[constructor]outgoing-response\x01x\x01\ -h/\x01@\x01\x04self\xf9\0\0+\x04\0%[method]outgoing-response.status-code\x01z\x01\ -@\x02\x04self\xf9\0\x0bstatus-code+\0\xd3\0\x04\0)[method]outgoing-response.set-\ -status-code\x01{\x01@\x01\x04self\xf9\0\0\xc7\0\x04\0![method]outgoing-response.\ -headers\x01|\x01@\x01\x04self\xf9\0\0\xd0\0\x04\0\x1e[method]outgoing-response.b\ -ody\x01}\x01h0\x01i\x05\x01j\x01\xff\0\0\x01@\x01\x04self\xfe\0\0\x80\x01\x04\0\x1b\ -[method]outgoing-body.write\x01\x81\x01\x01j\0\x01\x1b\x01@\x02\x04this\xcf\0\x08\ -trailers\xf3\0\0\x82\x01\x04\0\x1c[static]outgoing-body.finish\x01\x83\x01\x01h1\ -\x01@\x01\x04self\x84\x01\0\xf0\0\x04\0*[method]future-incoming-response.subscri\ -be\x01\x85\x01\x01i,\x01j\x01\x86\x01\x01\x1b\x01j\x01\x87\x01\0\x01k\x88\x01\x01\ -@\x01\x04self\x84\x01\0\x89\x01\x04\0$[method]future-incoming-response.get\x01\x8a\ -\x01\x01h\x07\x01k\x1b\x01@\x01\x03err\x8b\x01\0\x8c\x01\x04\0\x0fhttp-error-cod\ -e\x01\x8d\x01\x03\0\x15wasi:http/types@0.2.4\x05\x09\x02\x03\0\x04\x10outgoing-r\ -equest\x02\x03\0\x04\x0frequest-options\x02\x03\0\x04\x18future-incoming-respons\ -e\x02\x03\0\x04\x0aerror-code\x01B\x0f\x02\x03\x02\x01\x0a\x04\0\x10outgoing-req\ -uest\x03\0\0\x02\x03\x02\x01\x0b\x04\0\x0frequest-options\x03\0\x02\x02\x03\x02\x01\ -\x0c\x04\0\x18future-incoming-response\x03\0\x04\x02\x03\x02\x01\x0d\x04\0\x0aer\ -ror-code\x03\0\x06\x01i\x01\x01i\x03\x01k\x09\x01i\x05\x01j\x01\x0b\x01\x07\x01@\ -\x02\x07request\x08\x07options\x0a\0\x0c\x04\0\x06handle\x01\x0d\x03\0\x20wasi:h\ -ttp/outgoing-handler@0.2.4\x05\x0e\x01B\x0a\x01o\x02ss\x01p\0\x01@\0\0\x01\x04\0\ -\x0fget-environment\x01\x02\x01ps\x01@\0\0\x03\x04\0\x0dget-arguments\x01\x04\x01\ -ks\x01@\0\0\x05\x04\0\x0binitial-cwd\x01\x06\x03\0\x1awasi:cli/environment@0.2.4\ -\x05\x0f\x01B\x03\x01j\0\0\x01@\x01\x06status\0\x01\0\x04\0\x04exit\x01\x01\x03\0\ -\x13wasi:cli/exit@0.2.4\x05\x10\x01B\x05\x02\x03\x02\x01\x07\x04\0\x0cinput-stre\ -am\x03\0\0\x01i\x01\x01@\0\0\x02\x04\0\x09get-stdin\x01\x03\x03\0\x14wasi:cli/st\ -din@0.2.4\x05\x11\x01B\x05\x02\x03\x02\x01\x08\x04\0\x0doutput-stream\x03\0\0\x01\ -i\x01\x01@\0\0\x02\x04\0\x0aget-stdout\x01\x03\x03\0\x15wasi:cli/stdout@0.2.4\x05\ -\x12\x01B\x05\x02\x03\x02\x01\x08\x04\0\x0doutput-stream\x03\0\0\x01i\x01\x01@\0\ -\0\x02\x04\0\x0aget-stderr\x01\x03\x03\0\x15wasi:cli/stderr@0.2.4\x05\x13\x01B\x01\ -\x04\0\x0eterminal-input\x03\x01\x03\0\x1dwasi:cli/terminal-input@0.2.4\x05\x14\x01\ -B\x01\x04\0\x0fterminal-output\x03\x01\x03\0\x1ewasi:cli/terminal-output@0.2.4\x05\ -\x15\x02\x03\0\x0b\x0eterminal-input\x01B\x06\x02\x03\x02\x01\x16\x04\0\x0etermi\ -nal-input\x03\0\0\x01i\x01\x01k\x02\x01@\0\0\x03\x04\0\x12get-terminal-stdin\x01\ -\x04\x03\0\x1dwasi:cli/terminal-stdin@0.2.4\x05\x17\x02\x03\0\x0c\x0fterminal-ou\ -tput\x01B\x06\x02\x03\x02\x01\x18\x04\0\x0fterminal-output\x03\0\0\x01i\x01\x01k\ -\x02\x01@\0\0\x03\x04\0\x13get-terminal-stdout\x01\x04\x03\0\x1ewasi:cli/termina\ -l-stdout@0.2.4\x05\x19\x01B\x06\x02\x03\x02\x01\x18\x04\0\x0fterminal-output\x03\ -\0\0\x01i\x01\x01k\x02\x01@\0\0\x03\x04\0\x13get-terminal-stderr\x01\x04\x03\0\x1e\ -wasi:cli/terminal-stderr@0.2.4\x05\x1a\x01B\x05\x01r\x02\x07secondsw\x0bnanoseco\ -ndsy\x04\0\x08datetime\x03\0\0\x01@\0\0\x01\x04\0\x03now\x01\x02\x04\0\x0aresolu\ -tion\x01\x02\x03\0\x1cwasi:clocks/wall-clock@0.2.4\x05\x1b\x02\x03\0\x03\x05erro\ -r\x02\x03\0\x10\x08datetime\x01Br\x02\x03\x02\x01\x07\x04\0\x0cinput-stream\x03\0\ -\0\x02\x03\x02\x01\x08\x04\0\x0doutput-stream\x03\0\x02\x02\x03\x02\x01\x1c\x04\0\ -\x05error\x03\0\x04\x02\x03\x02\x01\x1d\x04\0\x08datetime\x03\0\x06\x01w\x04\0\x08\ -filesize\x03\0\x08\x01m\x08\x07unknown\x0cblock-device\x10character-device\x09di\ -rectory\x04fifo\x0dsymbolic-link\x0cregular-file\x06socket\x04\0\x0fdescriptor-t\ -ype\x03\0\x0a\x01n\x06\x04read\x05write\x13file-integrity-sync\x13data-integrity\ --sync\x14requested-write-sync\x10mutate-directory\x04\0\x10descriptor-flags\x03\0\ -\x0c\x01n\x01\x0esymlink-follow\x04\0\x0apath-flags\x03\0\x0e\x01n\x04\x06create\ -\x09directory\x09exclusive\x08truncate\x04\0\x0aopen-flags\x03\0\x10\x01w\x04\0\x0a\ -link-count\x03\0\x12\x01k\x07\x01r\x06\x04type\x0b\x0alink-count\x13\x04size\x09\ -\x15data-access-timestamp\x14\x1bdata-modification-timestamp\x14\x17status-chang\ -e-timestamp\x14\x04\0\x0fdescriptor-stat\x03\0\x15\x01q\x03\x09no-change\0\0\x03\ -now\0\0\x09timestamp\x01\x07\0\x04\0\x0dnew-timestamp\x03\0\x17\x01r\x02\x04type\ -\x0b\x04names\x04\0\x0fdirectory-entry\x03\0\x19\x01m%\x06access\x0bwould-block\x07\ -already\x0ebad-descriptor\x04busy\x08deadlock\x05quota\x05exist\x0efile-too-larg\ -e\x15illegal-byte-sequence\x0bin-progress\x0binterrupted\x07invalid\x02io\x0cis-\ -directory\x04loop\x0etoo-many-links\x0cmessage-size\x0dname-too-long\x09no-devic\ -e\x08no-entry\x07no-lock\x13insufficient-memory\x12insufficient-space\x0dnot-dir\ -ectory\x09not-empty\x0fnot-recoverable\x0bunsupported\x06no-tty\x0eno-such-devic\ -e\x08overflow\x0dnot-permitted\x04pipe\x09read-only\x0cinvalid-seek\x0etext-file\ --busy\x0ccross-device\x04\0\x0aerror-code\x03\0\x1b\x01m\x06\x06normal\x0asequen\ -tial\x06random\x09will-need\x09dont-need\x08no-reuse\x04\0\x06advice\x03\0\x1d\x01\ -r\x02\x05lowerw\x05upperw\x04\0\x13metadata-hash-value\x03\0\x1f\x04\0\x0adescri\ -ptor\x03\x01\x04\0\x16directory-entry-stream\x03\x01\x01h!\x01i\x01\x01j\x01$\x01\ -\x1c\x01@\x02\x04self#\x06offset\x09\0%\x04\0\"[method]descriptor.read-via-strea\ -m\x01&\x01i\x03\x01j\x01'\x01\x1c\x01@\x02\x04self#\x06offset\x09\0(\x04\0#[meth\ -od]descriptor.write-via-stream\x01)\x01@\x01\x04self#\0(\x04\0$[method]descripto\ -r.append-via-stream\x01*\x01j\0\x01\x1c\x01@\x04\x04self#\x06offset\x09\x06lengt\ -h\x09\x06advice\x1e\0+\x04\0\x19[method]descriptor.advise\x01,\x01@\x01\x04self#\ -\0+\x04\0\x1c[method]descriptor.sync-data\x01-\x01j\x01\x0d\x01\x1c\x01@\x01\x04\ -self#\0.\x04\0\x1c[method]descriptor.get-flags\x01/\x01j\x01\x0b\x01\x1c\x01@\x01\ -\x04self#\00\x04\0\x1b[method]descriptor.get-type\x011\x01@\x02\x04self#\x04size\ -\x09\0+\x04\0\x1b[method]descriptor.set-size\x012\x01@\x03\x04self#\x15data-acce\ -ss-timestamp\x18\x1bdata-modification-timestamp\x18\0+\x04\0\x1c[method]descript\ -or.set-times\x013\x01p}\x01o\x024\x7f\x01j\x015\x01\x1c\x01@\x03\x04self#\x06len\ -gth\x09\x06offset\x09\06\x04\0\x17[method]descriptor.read\x017\x01j\x01\x09\x01\x1c\ -\x01@\x03\x04self#\x06buffer4\x06offset\x09\08\x04\0\x18[method]descriptor.write\ -\x019\x01i\"\x01j\x01:\x01\x1c\x01@\x01\x04self#\0;\x04\0![method]descriptor.rea\ -d-directory\x01<\x04\0\x17[method]descriptor.sync\x01-\x01@\x02\x04self#\x04path\ -s\0+\x04\0&[method]descriptor.create-directory-at\x01=\x01j\x01\x16\x01\x1c\x01@\ -\x01\x04self#\0>\x04\0\x17[method]descriptor.stat\x01?\x01@\x03\x04self#\x0apath\ --flags\x0f\x04paths\0>\x04\0\x1a[method]descriptor.stat-at\x01@\x01@\x05\x04self\ -#\x0apath-flags\x0f\x04paths\x15data-access-timestamp\x18\x1bdata-modification-t\ -imestamp\x18\0+\x04\0\x1f[method]descriptor.set-times-at\x01A\x01@\x05\x04self#\x0e\ -old-path-flags\x0f\x08old-paths\x0enew-descriptor#\x08new-paths\0+\x04\0\x1a[met\ -hod]descriptor.link-at\x01B\x01i!\x01j\x01\xc3\0\x01\x1c\x01@\x05\x04self#\x0apa\ -th-flags\x0f\x04paths\x0aopen-flags\x11\x05flags\x0d\0\xc4\0\x04\0\x1a[method]de\ -scriptor.open-at\x01E\x01j\x01s\x01\x1c\x01@\x02\x04self#\x04paths\0\xc6\0\x04\0\ -\x1e[method]descriptor.readlink-at\x01G\x04\0&[method]descriptor.remove-director\ -y-at\x01=\x01@\x04\x04self#\x08old-paths\x0enew-descriptor#\x08new-paths\0+\x04\0\ -\x1c[method]descriptor.rename-at\x01H\x01@\x03\x04self#\x08old-paths\x08new-path\ -s\0+\x04\0\x1d[method]descriptor.symlink-at\x01I\x04\0![method]descriptor.unlink\ --file-at\x01=\x01@\x02\x04self#\x05other#\0\x7f\x04\0![method]descriptor.is-same\ --object\x01J\x01j\x01\x20\x01\x1c\x01@\x01\x04self#\0\xcb\0\x04\0\x20[method]des\ -criptor.metadata-hash\x01L\x01@\x03\x04self#\x0apath-flags\x0f\x04paths\0\xcb\0\x04\ -\0#[method]descriptor.metadata-hash-at\x01M\x01h\"\x01k\x1a\x01j\x01\xcf\0\x01\x1c\ -\x01@\x01\x04self\xce\0\0\xd0\0\x04\03[method]directory-entry-stream.read-direct\ -ory-entry\x01Q\x01h\x05\x01k\x1c\x01@\x01\x03err\xd2\0\0\xd3\0\x04\0\x15filesyst\ -em-error-code\x01T\x03\0\x1bwasi:filesystem/types@0.2.4\x05\x1e\x02\x03\0\x11\x0a\ -descriptor\x01B\x07\x02\x03\x02\x01\x1f\x04\0\x0adescriptor\x03\0\0\x01i\x01\x01\ -o\x02\x02s\x01p\x03\x01@\0\0\x04\x04\0\x0fget-directories\x01\x05\x03\0\x1ewasi:\ -filesystem/preopens@0.2.4\x05\x20\x01B\x11\x04\0\x07network\x03\x01\x01m\x15\x07\ -unknown\x0daccess-denied\x0dnot-supported\x10invalid-argument\x0dout-of-memory\x07\ -timeout\x14concurrency-conflict\x0fnot-in-progress\x0bwould-block\x0dinvalid-sta\ -te\x10new-socket-limit\x14address-not-bindable\x0eaddress-in-use\x12remote-unrea\ -chable\x12connection-refused\x10connection-reset\x12connection-aborted\x12datagr\ -am-too-large\x11name-unresolvable\x1atemporary-resolver-failure\x1apermanent-res\ -olver-failure\x04\0\x0aerror-code\x03\0\x01\x01m\x02\x04ipv4\x04ipv6\x04\0\x11ip\ --address-family\x03\0\x03\x01o\x04}}}}\x04\0\x0cipv4-address\x03\0\x05\x01o\x08{\ -{{{{{{{\x04\0\x0cipv6-address\x03\0\x07\x01q\x02\x04ipv4\x01\x06\0\x04ipv6\x01\x08\ -\0\x04\0\x0aip-address\x03\0\x09\x01r\x02\x04port{\x07address\x06\x04\0\x13ipv4-\ -socket-address\x03\0\x0b\x01r\x04\x04port{\x09flow-infoy\x07address\x08\x08scope\ --idy\x04\0\x13ipv6-socket-address\x03\0\x0d\x01q\x02\x04ipv4\x01\x0c\0\x04ipv6\x01\ -\x0e\0\x04\0\x11ip-socket-address\x03\0\x0f\x03\0\x1awasi:sockets/network@0.2.4\x05\ -!\x02\x03\0\x13\x07network\x01B\x05\x02\x03\x02\x01\"\x04\0\x07network\x03\0\0\x01\ -i\x01\x01@\0\0\x02\x04\0\x10instance-network\x01\x03\x03\0#wasi:sockets/instance\ --network@0.2.4\x05#\x02\x03\0\x13\x0aerror-code\x02\x03\0\x13\x11ip-socket-addre\ -ss\x02\x03\0\x13\x11ip-address-family\x01BD\x02\x03\x02\x01\x01\x04\0\x08pollabl\ -e\x03\0\0\x02\x03\x02\x01\"\x04\0\x07network\x03\0\x02\x02\x03\x02\x01$\x04\0\x0a\ -error-code\x03\0\x04\x02\x03\x02\x01%\x04\0\x11ip-socket-address\x03\0\x06\x02\x03\ -\x02\x01&\x04\0\x11ip-address-family\x03\0\x08\x01p}\x01r\x02\x04data\x0a\x0erem\ -ote-address\x07\x04\0\x11incoming-datagram\x03\0\x0b\x01k\x07\x01r\x02\x04data\x0a\ -\x0eremote-address\x0d\x04\0\x11outgoing-datagram\x03\0\x0e\x04\0\x0audp-socket\x03\ -\x01\x04\0\x18incoming-datagram-stream\x03\x01\x04\0\x18outgoing-datagram-stream\ -\x03\x01\x01h\x10\x01h\x03\x01j\0\x01\x05\x01@\x03\x04self\x13\x07network\x14\x0d\ -local-address\x07\0\x15\x04\0\x1d[method]udp-socket.start-bind\x01\x16\x01@\x01\x04\ -self\x13\0\x15\x04\0\x1e[method]udp-socket.finish-bind\x01\x17\x01i\x11\x01i\x12\ -\x01o\x02\x18\x19\x01j\x01\x1a\x01\x05\x01@\x02\x04self\x13\x0eremote-address\x0d\ -\0\x1b\x04\0\x19[method]udp-socket.stream\x01\x1c\x01j\x01\x07\x01\x05\x01@\x01\x04\ -self\x13\0\x1d\x04\0\x20[method]udp-socket.local-address\x01\x1e\x04\0![method]u\ -dp-socket.remote-address\x01\x1e\x01@\x01\x04self\x13\0\x09\x04\0![method]udp-so\ -cket.address-family\x01\x1f\x01j\x01}\x01\x05\x01@\x01\x04self\x13\0\x20\x04\0$[\ -method]udp-socket.unicast-hop-limit\x01!\x01@\x02\x04self\x13\x05value}\0\x15\x04\ -\0([method]udp-socket.set-unicast-hop-limit\x01\"\x01j\x01w\x01\x05\x01@\x01\x04\ -self\x13\0#\x04\0&[method]udp-socket.receive-buffer-size\x01$\x01@\x02\x04self\x13\ -\x05valuew\0\x15\x04\0*[method]udp-socket.set-receive-buffer-size\x01%\x04\0#[me\ -thod]udp-socket.send-buffer-size\x01$\x04\0'[method]udp-socket.set-send-buffer-s\ -ize\x01%\x01i\x01\x01@\x01\x04self\x13\0&\x04\0\x1c[method]udp-socket.subscribe\x01\ -'\x01h\x11\x01p\x0c\x01j\x01)\x01\x05\x01@\x02\x04self(\x0bmax-resultsw\0*\x04\0\ -([method]incoming-datagram-stream.receive\x01+\x01@\x01\x04self(\0&\x04\0*[metho\ -d]incoming-datagram-stream.subscribe\x01,\x01h\x12\x01@\x01\x04self-\0#\x04\0+[m\ -ethod]outgoing-datagram-stream.check-send\x01.\x01p\x0f\x01@\x02\x04self-\x09dat\ -agrams/\0#\x04\0%[method]outgoing-datagram-stream.send\x010\x01@\x01\x04self-\0&\ -\x04\0*[method]outgoing-datagram-stream.subscribe\x011\x03\0\x16wasi:sockets/udp\ -@0.2.4\x05'\x02\x03\0\x15\x0audp-socket\x01B\x0c\x02\x03\x02\x01\"\x04\0\x07netw\ -ork\x03\0\0\x02\x03\x02\x01$\x04\0\x0aerror-code\x03\0\x02\x02\x03\x02\x01&\x04\0\ -\x11ip-address-family\x03\0\x04\x02\x03\x02\x01(\x04\0\x0audp-socket\x03\0\x06\x01\ +pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 10730] = *b"\ +\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xecR\x01A\x02\x01AG\x01\ +B\x0a\x01o\x02ss\x01p\0\x01@\0\0\x01\x04\0\x0fget-environment\x01\x02\x01ps\x01@\ +\0\0\x03\x04\0\x0dget-arguments\x01\x04\x01ks\x01@\0\0\x05\x04\0\x0binitial-cwd\x01\ +\x06\x03\0\x1awasi:cli/environment@0.2.4\x05\0\x01B\x03\x01j\0\0\x01@\x01\x06sta\ +tus\0\x01\0\x04\0\x04exit\x01\x01\x03\0\x13wasi:cli/exit@0.2.4\x05\x01\x01B\x04\x04\ +\0\x05error\x03\x01\x01h\0\x01@\x01\x04self\x01\0s\x04\0\x1d[method]error.to-deb\ +ug-string\x01\x02\x03\0\x13wasi:io/error@0.2.4\x05\x02\x01B\x0a\x04\0\x08pollabl\ +e\x03\x01\x01h\0\x01@\x01\x04self\x01\0\x7f\x04\0\x16[method]pollable.ready\x01\x02\ +\x01@\x01\x04self\x01\x01\0\x04\0\x16[method]pollable.block\x01\x03\x01p\x01\x01\ +py\x01@\x01\x02in\x04\0\x05\x04\0\x04poll\x01\x06\x03\0\x12wasi:io/poll@0.2.4\x05\ +\x03\x02\x03\0\x02\x05error\x02\x03\0\x03\x08pollable\x01B(\x02\x03\x02\x01\x04\x04\ +\0\x05error\x03\0\0\x02\x03\x02\x01\x05\x04\0\x08pollable\x03\0\x02\x01i\x01\x01\ +q\x02\x15last-operation-failed\x01\x04\0\x06closed\0\0\x04\0\x0cstream-error\x03\ +\0\x05\x04\0\x0cinput-stream\x03\x01\x04\0\x0doutput-stream\x03\x01\x01h\x07\x01\ +p}\x01j\x01\x0a\x01\x06\x01@\x02\x04self\x09\x03lenw\0\x0b\x04\0\x19[method]inpu\ +t-stream.read\x01\x0c\x04\0\"[method]input-stream.blocking-read\x01\x0c\x01j\x01\ +w\x01\x06\x01@\x02\x04self\x09\x03lenw\0\x0d\x04\0\x19[method]input-stream.skip\x01\ +\x0e\x04\0\"[method]input-stream.blocking-skip\x01\x0e\x01i\x03\x01@\x01\x04self\ +\x09\0\x0f\x04\0\x1e[method]input-stream.subscribe\x01\x10\x01h\x08\x01@\x01\x04\ +self\x11\0\x0d\x04\0![method]output-stream.check-write\x01\x12\x01j\0\x01\x06\x01\ +@\x02\x04self\x11\x08contents\x0a\0\x13\x04\0\x1b[method]output-stream.write\x01\ +\x14\x04\0.[method]output-stream.blocking-write-and-flush\x01\x14\x01@\x01\x04se\ +lf\x11\0\x13\x04\0\x1b[method]output-stream.flush\x01\x15\x04\0$[method]output-s\ +tream.blocking-flush\x01\x15\x01@\x01\x04self\x11\0\x0f\x04\0\x1f[method]output-\ +stream.subscribe\x01\x16\x01@\x02\x04self\x11\x03lenw\0\x13\x04\0\"[method]outpu\ +t-stream.write-zeroes\x01\x17\x04\05[method]output-stream.blocking-write-zeroes-\ +and-flush\x01\x17\x01@\x03\x04self\x11\x03src\x09\x03lenw\0\x0d\x04\0\x1c[method\ +]output-stream.splice\x01\x18\x04\0%[method]output-stream.blocking-splice\x01\x18\ +\x03\0\x15wasi:io/streams@0.2.4\x05\x06\x02\x03\0\x04\x0cinput-stream\x01B\x05\x02\ +\x03\x02\x01\x07\x04\0\x0cinput-stream\x03\0\0\x01i\x01\x01@\0\0\x02\x04\0\x09ge\ +t-stdin\x01\x03\x03\0\x14wasi:cli/stdin@0.2.4\x05\x08\x02\x03\0\x04\x0doutput-st\ +ream\x01B\x05\x02\x03\x02\x01\x09\x04\0\x0doutput-stream\x03\0\0\x01i\x01\x01@\0\ +\0\x02\x04\0\x0aget-stdout\x01\x03\x03\0\x15wasi:cli/stdout@0.2.4\x05\x0a\x01B\x05\ +\x02\x03\x02\x01\x09\x04\0\x0doutput-stream\x03\0\0\x01i\x01\x01@\0\0\x02\x04\0\x0a\ +get-stderr\x01\x03\x03\0\x15wasi:cli/stderr@0.2.4\x05\x0b\x01B\x01\x04\0\x0eterm\ +inal-input\x03\x01\x03\0\x1dwasi:cli/terminal-input@0.2.4\x05\x0c\x01B\x01\x04\0\ +\x0fterminal-output\x03\x01\x03\0\x1ewasi:cli/terminal-output@0.2.4\x05\x0d\x02\x03\ +\0\x08\x0eterminal-input\x01B\x06\x02\x03\x02\x01\x0e\x04\0\x0eterminal-input\x03\ +\0\0\x01i\x01\x01k\x02\x01@\0\0\x03\x04\0\x12get-terminal-stdin\x01\x04\x03\0\x1d\ +wasi:cli/terminal-stdin@0.2.4\x05\x0f\x02\x03\0\x09\x0fterminal-output\x01B\x06\x02\ +\x03\x02\x01\x10\x04\0\x0fterminal-output\x03\0\0\x01i\x01\x01k\x02\x01@\0\0\x03\ +\x04\0\x13get-terminal-stdout\x01\x04\x03\0\x1ewasi:cli/terminal-stdout@0.2.4\x05\ +\x11\x01B\x06\x02\x03\x02\x01\x10\x04\0\x0fterminal-output\x03\0\0\x01i\x01\x01k\ +\x02\x01@\0\0\x03\x04\0\x13get-terminal-stderr\x01\x04\x03\0\x1ewasi:cli/termina\ +l-stderr@0.2.4\x05\x12\x01B\x0f\x02\x03\x02\x01\x05\x04\0\x08pollable\x03\0\0\x01\ +w\x04\0\x07instant\x03\0\x02\x01w\x04\0\x08duration\x03\0\x04\x01@\0\0\x03\x04\0\ +\x03now\x01\x06\x01@\0\0\x05\x04\0\x0aresolution\x01\x07\x01i\x01\x01@\x01\x04wh\ +en\x03\0\x08\x04\0\x11subscribe-instant\x01\x09\x01@\x01\x04when\x05\0\x08\x04\0\ +\x12subscribe-duration\x01\x0a\x03\0!wasi:clocks/monotonic-clock@0.2.4\x05\x13\x01\ +B\x05\x01r\x02\x07secondsw\x0bnanosecondsy\x04\0\x08datetime\x03\0\0\x01@\0\0\x01\ +\x04\0\x03now\x01\x02\x04\0\x0aresolution\x01\x02\x03\0\x1cwasi:clocks/wall-cloc\ +k@0.2.4\x05\x14\x02\x03\0\x04\x05error\x02\x03\0\x0e\x08datetime\x01Br\x02\x03\x02\ +\x01\x07\x04\0\x0cinput-stream\x03\0\0\x02\x03\x02\x01\x09\x04\0\x0doutput-strea\ +m\x03\0\x02\x02\x03\x02\x01\x15\x04\0\x05error\x03\0\x04\x02\x03\x02\x01\x16\x04\ +\0\x08datetime\x03\0\x06\x01w\x04\0\x08filesize\x03\0\x08\x01m\x08\x07unknown\x0c\ +block-device\x10character-device\x09directory\x04fifo\x0dsymbolic-link\x0cregula\ +r-file\x06socket\x04\0\x0fdescriptor-type\x03\0\x0a\x01n\x06\x04read\x05write\x13\ +file-integrity-sync\x13data-integrity-sync\x14requested-write-sync\x10mutate-dir\ +ectory\x04\0\x10descriptor-flags\x03\0\x0c\x01n\x01\x0esymlink-follow\x04\0\x0ap\ +ath-flags\x03\0\x0e\x01n\x04\x06create\x09directory\x09exclusive\x08truncate\x04\ +\0\x0aopen-flags\x03\0\x10\x01w\x04\0\x0alink-count\x03\0\x12\x01k\x07\x01r\x06\x04\ +type\x0b\x0alink-count\x13\x04size\x09\x15data-access-timestamp\x14\x1bdata-modi\ +fication-timestamp\x14\x17status-change-timestamp\x14\x04\0\x0fdescriptor-stat\x03\ +\0\x15\x01q\x03\x09no-change\0\0\x03now\0\0\x09timestamp\x01\x07\0\x04\0\x0dnew-\ +timestamp\x03\0\x17\x01r\x02\x04type\x0b\x04names\x04\0\x0fdirectory-entry\x03\0\ +\x19\x01m%\x06access\x0bwould-block\x07already\x0ebad-descriptor\x04busy\x08dead\ +lock\x05quota\x05exist\x0efile-too-large\x15illegal-byte-sequence\x0bin-progress\ +\x0binterrupted\x07invalid\x02io\x0cis-directory\x04loop\x0etoo-many-links\x0cme\ +ssage-size\x0dname-too-long\x09no-device\x08no-entry\x07no-lock\x13insufficient-\ +memory\x12insufficient-space\x0dnot-directory\x09not-empty\x0fnot-recoverable\x0b\ +unsupported\x06no-tty\x0eno-such-device\x08overflow\x0dnot-permitted\x04pipe\x09\ +read-only\x0cinvalid-seek\x0etext-file-busy\x0ccross-device\x04\0\x0aerror-code\x03\ +\0\x1b\x01m\x06\x06normal\x0asequential\x06random\x09will-need\x09dont-need\x08n\ +o-reuse\x04\0\x06advice\x03\0\x1d\x01r\x02\x05lowerw\x05upperw\x04\0\x13metadata\ +-hash-value\x03\0\x1f\x04\0\x0adescriptor\x03\x01\x04\0\x16directory-entry-strea\ +m\x03\x01\x01h!\x01i\x01\x01j\x01$\x01\x1c\x01@\x02\x04self#\x06offset\x09\0%\x04\ +\0\"[method]descriptor.read-via-stream\x01&\x01i\x03\x01j\x01'\x01\x1c\x01@\x02\x04\ +self#\x06offset\x09\0(\x04\0#[method]descriptor.write-via-stream\x01)\x01@\x01\x04\ +self#\0(\x04\0$[method]descriptor.append-via-stream\x01*\x01j\0\x01\x1c\x01@\x04\ +\x04self#\x06offset\x09\x06length\x09\x06advice\x1e\0+\x04\0\x19[method]descript\ +or.advise\x01,\x01@\x01\x04self#\0+\x04\0\x1c[method]descriptor.sync-data\x01-\x01\ +j\x01\x0d\x01\x1c\x01@\x01\x04self#\0.\x04\0\x1c[method]descriptor.get-flags\x01\ +/\x01j\x01\x0b\x01\x1c\x01@\x01\x04self#\00\x04\0\x1b[method]descriptor.get-type\ +\x011\x01@\x02\x04self#\x04size\x09\0+\x04\0\x1b[method]descriptor.set-size\x012\ +\x01@\x03\x04self#\x15data-access-timestamp\x18\x1bdata-modification-timestamp\x18\ +\0+\x04\0\x1c[method]descriptor.set-times\x013\x01p}\x01o\x024\x7f\x01j\x015\x01\ +\x1c\x01@\x03\x04self#\x06length\x09\x06offset\x09\06\x04\0\x17[method]descripto\ +r.read\x017\x01j\x01\x09\x01\x1c\x01@\x03\x04self#\x06buffer4\x06offset\x09\08\x04\ +\0\x18[method]descriptor.write\x019\x01i\"\x01j\x01:\x01\x1c\x01@\x01\x04self#\0\ +;\x04\0![method]descriptor.read-directory\x01<\x04\0\x17[method]descriptor.sync\x01\ +-\x01@\x02\x04self#\x04paths\0+\x04\0&[method]descriptor.create-directory-at\x01\ +=\x01j\x01\x16\x01\x1c\x01@\x01\x04self#\0>\x04\0\x17[method]descriptor.stat\x01\ +?\x01@\x03\x04self#\x0apath-flags\x0f\x04paths\0>\x04\0\x1a[method]descriptor.st\ +at-at\x01@\x01@\x05\x04self#\x0apath-flags\x0f\x04paths\x15data-access-timestamp\ +\x18\x1bdata-modification-timestamp\x18\0+\x04\0\x1f[method]descriptor.set-times\ +-at\x01A\x01@\x05\x04self#\x0eold-path-flags\x0f\x08old-paths\x0enew-descriptor#\ +\x08new-paths\0+\x04\0\x1a[method]descriptor.link-at\x01B\x01i!\x01j\x01\xc3\0\x01\ +\x1c\x01@\x05\x04self#\x0apath-flags\x0f\x04paths\x0aopen-flags\x11\x05flags\x0d\ +\0\xc4\0\x04\0\x1a[method]descriptor.open-at\x01E\x01j\x01s\x01\x1c\x01@\x02\x04\ +self#\x04paths\0\xc6\0\x04\0\x1e[method]descriptor.readlink-at\x01G\x04\0&[metho\ +d]descriptor.remove-directory-at\x01=\x01@\x04\x04self#\x08old-paths\x0enew-desc\ +riptor#\x08new-paths\0+\x04\0\x1c[method]descriptor.rename-at\x01H\x01@\x03\x04s\ +elf#\x08old-paths\x08new-paths\0+\x04\0\x1d[method]descriptor.symlink-at\x01I\x04\ +\0![method]descriptor.unlink-file-at\x01=\x01@\x02\x04self#\x05other#\0\x7f\x04\0\ +![method]descriptor.is-same-object\x01J\x01j\x01\x20\x01\x1c\x01@\x01\x04self#\0\ +\xcb\0\x04\0\x20[method]descriptor.metadata-hash\x01L\x01@\x03\x04self#\x0apath-\ +flags\x0f\x04paths\0\xcb\0\x04\0#[method]descriptor.metadata-hash-at\x01M\x01h\"\ +\x01k\x1a\x01j\x01\xcf\0\x01\x1c\x01@\x01\x04self\xce\0\0\xd0\0\x04\03[method]di\ +rectory-entry-stream.read-directory-entry\x01Q\x01h\x05\x01k\x1c\x01@\x01\x03err\ +\xd2\0\0\xd3\0\x04\0\x15filesystem-error-code\x01T\x03\0\x1bwasi:filesystem/type\ +s@0.2.4\x05\x17\x02\x03\0\x0f\x0adescriptor\x01B\x07\x02\x03\x02\x01\x18\x04\0\x0a\ +descriptor\x03\0\0\x01i\x01\x01o\x02\x02s\x01p\x03\x01@\0\0\x04\x04\0\x0fget-dir\ +ectories\x01\x05\x03\0\x1ewasi:filesystem/preopens@0.2.4\x05\x19\x01B\x11\x04\0\x07\ +network\x03\x01\x01m\x15\x07unknown\x0daccess-denied\x0dnot-supported\x10invalid\ +-argument\x0dout-of-memory\x07timeout\x14concurrency-conflict\x0fnot-in-progress\ +\x0bwould-block\x0dinvalid-state\x10new-socket-limit\x14address-not-bindable\x0e\ +address-in-use\x12remote-unreachable\x12connection-refused\x10connection-reset\x12\ +connection-aborted\x12datagram-too-large\x11name-unresolvable\x1atemporary-resol\ +ver-failure\x1apermanent-resolver-failure\x04\0\x0aerror-code\x03\0\x01\x01m\x02\ +\x04ipv4\x04ipv6\x04\0\x11ip-address-family\x03\0\x03\x01o\x04}}}}\x04\0\x0cipv4\ +-address\x03\0\x05\x01o\x08{{{{{{{{\x04\0\x0cipv6-address\x03\0\x07\x01q\x02\x04\ +ipv4\x01\x06\0\x04ipv6\x01\x08\0\x04\0\x0aip-address\x03\0\x09\x01r\x02\x04port{\ +\x07address\x06\x04\0\x13ipv4-socket-address\x03\0\x0b\x01r\x04\x04port{\x09flow\ +-infoy\x07address\x08\x08scope-idy\x04\0\x13ipv6-socket-address\x03\0\x0d\x01q\x02\ +\x04ipv4\x01\x0c\0\x04ipv6\x01\x0e\0\x04\0\x11ip-socket-address\x03\0\x0f\x03\0\x1a\ +wasi:sockets/network@0.2.4\x05\x1a\x02\x03\0\x11\x07network\x01B\x05\x02\x03\x02\ +\x01\x1b\x04\0\x07network\x03\0\0\x01i\x01\x01@\0\0\x02\x04\0\x10instance-networ\ +k\x01\x03\x03\0#wasi:sockets/instance-network@0.2.4\x05\x1c\x02\x03\0\x11\x0aerr\ +or-code\x02\x03\0\x11\x11ip-socket-address\x02\x03\0\x11\x11ip-address-family\x01\ +BD\x02\x03\x02\x01\x05\x04\0\x08pollable\x03\0\0\x02\x03\x02\x01\x1b\x04\0\x07ne\ +twork\x03\0\x02\x02\x03\x02\x01\x1d\x04\0\x0aerror-code\x03\0\x04\x02\x03\x02\x01\ +\x1e\x04\0\x11ip-socket-address\x03\0\x06\x02\x03\x02\x01\x1f\x04\0\x11ip-addres\ +s-family\x03\0\x08\x01p}\x01r\x02\x04data\x0a\x0eremote-address\x07\x04\0\x11inc\ +oming-datagram\x03\0\x0b\x01k\x07\x01r\x02\x04data\x0a\x0eremote-address\x0d\x04\ +\0\x11outgoing-datagram\x03\0\x0e\x04\0\x0audp-socket\x03\x01\x04\0\x18incoming-\ +datagram-stream\x03\x01\x04\0\x18outgoing-datagram-stream\x03\x01\x01h\x10\x01h\x03\ +\x01j\0\x01\x05\x01@\x03\x04self\x13\x07network\x14\x0dlocal-address\x07\0\x15\x04\ +\0\x1d[method]udp-socket.start-bind\x01\x16\x01@\x01\x04self\x13\0\x15\x04\0\x1e\ +[method]udp-socket.finish-bind\x01\x17\x01i\x11\x01i\x12\x01o\x02\x18\x19\x01j\x01\ +\x1a\x01\x05\x01@\x02\x04self\x13\x0eremote-address\x0d\0\x1b\x04\0\x19[method]u\ +dp-socket.stream\x01\x1c\x01j\x01\x07\x01\x05\x01@\x01\x04self\x13\0\x1d\x04\0\x20\ +[method]udp-socket.local-address\x01\x1e\x04\0![method]udp-socket.remote-address\ +\x01\x1e\x01@\x01\x04self\x13\0\x09\x04\0![method]udp-socket.address-family\x01\x1f\ +\x01j\x01}\x01\x05\x01@\x01\x04self\x13\0\x20\x04\0$[method]udp-socket.unicast-h\ +op-limit\x01!\x01@\x02\x04self\x13\x05value}\0\x15\x04\0([method]udp-socket.set-\ +unicast-hop-limit\x01\"\x01j\x01w\x01\x05\x01@\x01\x04self\x13\0#\x04\0&[method]\ +udp-socket.receive-buffer-size\x01$\x01@\x02\x04self\x13\x05valuew\0\x15\x04\0*[\ +method]udp-socket.set-receive-buffer-size\x01%\x04\0#[method]udp-socket.send-buf\ +fer-size\x01$\x04\0'[method]udp-socket.set-send-buffer-size\x01%\x01i\x01\x01@\x01\ +\x04self\x13\0&\x04\0\x1c[method]udp-socket.subscribe\x01'\x01h\x11\x01p\x0c\x01\ +j\x01)\x01\x05\x01@\x02\x04self(\x0bmax-resultsw\0*\x04\0([method]incoming-datag\ +ram-stream.receive\x01+\x01@\x01\x04self(\0&\x04\0*[method]incoming-datagram-str\ +eam.subscribe\x01,\x01h\x12\x01@\x01\x04self-\0#\x04\0+[method]outgoing-datagram\ +-stream.check-send\x01.\x01p\x0f\x01@\x02\x04self-\x09datagrams/\0#\x04\0%[metho\ +d]outgoing-datagram-stream.send\x010\x01@\x01\x04self-\0&\x04\0*[method]outgoing\ +-datagram-stream.subscribe\x011\x03\0\x16wasi:sockets/udp@0.2.4\x05\x20\x02\x03\0\ +\x13\x0audp-socket\x01B\x0c\x02\x03\x02\x01\x1b\x04\0\x07network\x03\0\0\x02\x03\ +\x02\x01\x1d\x04\0\x0aerror-code\x03\0\x02\x02\x03\x02\x01\x1f\x04\0\x11ip-addre\ +ss-family\x03\0\x04\x02\x03\x02\x01!\x04\0\x0audp-socket\x03\0\x06\x01i\x07\x01j\ +\x01\x08\x01\x03\x01@\x01\x0eaddress-family\x05\0\x09\x04\0\x11create-udp-socket\ +\x01\x0a\x03\0$wasi:sockets/udp-create-socket@0.2.4\x05\"\x02\x03\0\x0d\x08durat\ +ion\x01BT\x02\x03\x02\x01\x07\x04\0\x0cinput-stream\x03\0\0\x02\x03\x02\x01\x09\x04\ +\0\x0doutput-stream\x03\0\x02\x02\x03\x02\x01\x05\x04\0\x08pollable\x03\0\x04\x02\ +\x03\x02\x01#\x04\0\x08duration\x03\0\x06\x02\x03\x02\x01\x1b\x04\0\x07network\x03\ +\0\x08\x02\x03\x02\x01\x1d\x04\0\x0aerror-code\x03\0\x0a\x02\x03\x02\x01\x1e\x04\ +\0\x11ip-socket-address\x03\0\x0c\x02\x03\x02\x01\x1f\x04\0\x11ip-address-family\ +\x03\0\x0e\x01m\x03\x07receive\x04send\x04both\x04\0\x0dshutdown-type\x03\0\x10\x04\ +\0\x0atcp-socket\x03\x01\x01h\x12\x01h\x09\x01j\0\x01\x0b\x01@\x03\x04self\x13\x07\ +network\x14\x0dlocal-address\x0d\0\x15\x04\0\x1d[method]tcp-socket.start-bind\x01\ +\x16\x01@\x01\x04self\x13\0\x15\x04\0\x1e[method]tcp-socket.finish-bind\x01\x17\x01\ +@\x03\x04self\x13\x07network\x14\x0eremote-address\x0d\0\x15\x04\0\x20[method]tc\ +p-socket.start-connect\x01\x18\x01i\x01\x01i\x03\x01o\x02\x19\x1a\x01j\x01\x1b\x01\ +\x0b\x01@\x01\x04self\x13\0\x1c\x04\0![method]tcp-socket.finish-connect\x01\x1d\x04\ +\0\x1f[method]tcp-socket.start-listen\x01\x17\x04\0\x20[method]tcp-socket.finish\ +-listen\x01\x17\x01i\x12\x01o\x03\x1e\x19\x1a\x01j\x01\x1f\x01\x0b\x01@\x01\x04s\ +elf\x13\0\x20\x04\0\x19[method]tcp-socket.accept\x01!\x01j\x01\x0d\x01\x0b\x01@\x01\ +\x04self\x13\0\"\x04\0\x20[method]tcp-socket.local-address\x01#\x04\0![method]tc\ +p-socket.remote-address\x01#\x01@\x01\x04self\x13\0\x7f\x04\0\x1f[method]tcp-soc\ +ket.is-listening\x01$\x01@\x01\x04self\x13\0\x0f\x04\0![method]tcp-socket.addres\ +s-family\x01%\x01@\x02\x04self\x13\x05valuew\0\x15\x04\0*[method]tcp-socket.set-\ +listen-backlog-size\x01&\x01j\x01\x7f\x01\x0b\x01@\x01\x04self\x13\0'\x04\0%[met\ +hod]tcp-socket.keep-alive-enabled\x01(\x01@\x02\x04self\x13\x05value\x7f\0\x15\x04\ +\0)[method]tcp-socket.set-keep-alive-enabled\x01)\x01j\x01\x07\x01\x0b\x01@\x01\x04\ +self\x13\0*\x04\0'[method]tcp-socket.keep-alive-idle-time\x01+\x01@\x02\x04self\x13\ +\x05value\x07\0\x15\x04\0+[method]tcp-socket.set-keep-alive-idle-time\x01,\x04\0\ +&[method]tcp-socket.keep-alive-interval\x01+\x04\0*[method]tcp-socket.set-keep-a\ +live-interval\x01,\x01j\x01y\x01\x0b\x01@\x01\x04self\x13\0-\x04\0#[method]tcp-s\ +ocket.keep-alive-count\x01.\x01@\x02\x04self\x13\x05valuey\0\x15\x04\0'[method]t\ +cp-socket.set-keep-alive-count\x01/\x01j\x01}\x01\x0b\x01@\x01\x04self\x13\00\x04\ +\0\x1c[method]tcp-socket.hop-limit\x011\x01@\x02\x04self\x13\x05value}\0\x15\x04\ +\0\x20[method]tcp-socket.set-hop-limit\x012\x01j\x01w\x01\x0b\x01@\x01\x04self\x13\ +\03\x04\0&[method]tcp-socket.receive-buffer-size\x014\x04\0*[method]tcp-socket.s\ +et-receive-buffer-size\x01&\x04\0#[method]tcp-socket.send-buffer-size\x014\x04\0\ +'[method]tcp-socket.set-send-buffer-size\x01&\x01i\x05\x01@\x01\x04self\x13\05\x04\ +\0\x1c[method]tcp-socket.subscribe\x016\x01@\x02\x04self\x13\x0dshutdown-type\x11\ +\0\x15\x04\0\x1b[method]tcp-socket.shutdown\x017\x03\0\x16wasi:sockets/tcp@0.2.4\ +\x05$\x02\x03\0\x15\x0atcp-socket\x01B\x0c\x02\x03\x02\x01\x1b\x04\0\x07network\x03\ +\0\0\x02\x03\x02\x01\x1d\x04\0\x0aerror-code\x03\0\x02\x02\x03\x02\x01\x1f\x04\0\ +\x11ip-address-family\x03\0\x04\x02\x03\x02\x01%\x04\0\x0atcp-socket\x03\0\x06\x01\ i\x07\x01j\x01\x08\x01\x03\x01@\x01\x0eaddress-family\x05\0\x09\x04\0\x11create-\ -udp-socket\x01\x0a\x03\0$wasi:sockets/udp-create-socket@0.2.4\x05)\x01BT\x02\x03\ -\x02\x01\x07\x04\0\x0cinput-stream\x03\0\0\x02\x03\x02\x01\x08\x04\0\x0doutput-s\ -tream\x03\0\x02\x02\x03\x02\x01\x01\x04\0\x08pollable\x03\0\x04\x02\x03\x02\x01\x06\ -\x04\0\x08duration\x03\0\x06\x02\x03\x02\x01\"\x04\0\x07network\x03\0\x08\x02\x03\ -\x02\x01$\x04\0\x0aerror-code\x03\0\x0a\x02\x03\x02\x01%\x04\0\x11ip-socket-addr\ -ess\x03\0\x0c\x02\x03\x02\x01&\x04\0\x11ip-address-family\x03\0\x0e\x01m\x03\x07\ -receive\x04send\x04both\x04\0\x0dshutdown-type\x03\0\x10\x04\0\x0atcp-socket\x03\ -\x01\x01h\x12\x01h\x09\x01j\0\x01\x0b\x01@\x03\x04self\x13\x07network\x14\x0dloc\ -al-address\x0d\0\x15\x04\0\x1d[method]tcp-socket.start-bind\x01\x16\x01@\x01\x04\ -self\x13\0\x15\x04\0\x1e[method]tcp-socket.finish-bind\x01\x17\x01@\x03\x04self\x13\ -\x07network\x14\x0eremote-address\x0d\0\x15\x04\0\x20[method]tcp-socket.start-co\ -nnect\x01\x18\x01i\x01\x01i\x03\x01o\x02\x19\x1a\x01j\x01\x1b\x01\x0b\x01@\x01\x04\ -self\x13\0\x1c\x04\0![method]tcp-socket.finish-connect\x01\x1d\x04\0\x1f[method]\ -tcp-socket.start-listen\x01\x17\x04\0\x20[method]tcp-socket.finish-listen\x01\x17\ -\x01i\x12\x01o\x03\x1e\x19\x1a\x01j\x01\x1f\x01\x0b\x01@\x01\x04self\x13\0\x20\x04\ -\0\x19[method]tcp-socket.accept\x01!\x01j\x01\x0d\x01\x0b\x01@\x01\x04self\x13\0\ -\"\x04\0\x20[method]tcp-socket.local-address\x01#\x04\0![method]tcp-socket.remot\ -e-address\x01#\x01@\x01\x04self\x13\0\x7f\x04\0\x1f[method]tcp-socket.is-listeni\ -ng\x01$\x01@\x01\x04self\x13\0\x0f\x04\0![method]tcp-socket.address-family\x01%\x01\ -@\x02\x04self\x13\x05valuew\0\x15\x04\0*[method]tcp-socket.set-listen-backlog-si\ -ze\x01&\x01j\x01\x7f\x01\x0b\x01@\x01\x04self\x13\0'\x04\0%[method]tcp-socket.ke\ -ep-alive-enabled\x01(\x01@\x02\x04self\x13\x05value\x7f\0\x15\x04\0)[method]tcp-\ -socket.set-keep-alive-enabled\x01)\x01j\x01\x07\x01\x0b\x01@\x01\x04self\x13\0*\x04\ -\0'[method]tcp-socket.keep-alive-idle-time\x01+\x01@\x02\x04self\x13\x05value\x07\ -\0\x15\x04\0+[method]tcp-socket.set-keep-alive-idle-time\x01,\x04\0&[method]tcp-\ -socket.keep-alive-interval\x01+\x04\0*[method]tcp-socket.set-keep-alive-interval\ -\x01,\x01j\x01y\x01\x0b\x01@\x01\x04self\x13\0-\x04\0#[method]tcp-socket.keep-al\ -ive-count\x01.\x01@\x02\x04self\x13\x05valuey\0\x15\x04\0'[method]tcp-socket.set\ --keep-alive-count\x01/\x01j\x01}\x01\x0b\x01@\x01\x04self\x13\00\x04\0\x1c[metho\ -d]tcp-socket.hop-limit\x011\x01@\x02\x04self\x13\x05value}\0\x15\x04\0\x20[metho\ -d]tcp-socket.set-hop-limit\x012\x01j\x01w\x01\x0b\x01@\x01\x04self\x13\03\x04\0&\ -[method]tcp-socket.receive-buffer-size\x014\x04\0*[method]tcp-socket.set-receive\ --buffer-size\x01&\x04\0#[method]tcp-socket.send-buffer-size\x014\x04\0'[method]t\ -cp-socket.set-send-buffer-size\x01&\x01i\x05\x01@\x01\x04self\x13\05\x04\0\x1c[m\ -ethod]tcp-socket.subscribe\x016\x01@\x02\x04self\x13\x0dshutdown-type\x11\0\x15\x04\ -\0\x1b[method]tcp-socket.shutdown\x017\x03\0\x16wasi:sockets/tcp@0.2.4\x05*\x02\x03\ -\0\x17\x0atcp-socket\x01B\x0c\x02\x03\x02\x01\"\x04\0\x07network\x03\0\0\x02\x03\ -\x02\x01$\x04\0\x0aerror-code\x03\0\x02\x02\x03\x02\x01&\x04\0\x11ip-address-fam\ -ily\x03\0\x04\x02\x03\x02\x01+\x04\0\x0atcp-socket\x03\0\x06\x01i\x07\x01j\x01\x08\ -\x01\x03\x01@\x01\x0eaddress-family\x05\0\x09\x04\0\x11create-tcp-socket\x01\x0a\ -\x03\0$wasi:sockets/tcp-create-socket@0.2.4\x05,\x02\x03\0\x13\x0aip-address\x01\ -B\x16\x02\x03\x02\x01\x01\x04\0\x08pollable\x03\0\0\x02\x03\x02\x01\"\x04\0\x07n\ -etwork\x03\0\x02\x02\x03\x02\x01$\x04\0\x0aerror-code\x03\0\x04\x02\x03\x02\x01-\ -\x04\0\x0aip-address\x03\0\x06\x04\0\x16resolve-address-stream\x03\x01\x01h\x08\x01\ -k\x07\x01j\x01\x0a\x01\x05\x01@\x01\x04self\x09\0\x0b\x04\03[method]resolve-addr\ -ess-stream.resolve-next-address\x01\x0c\x01i\x01\x01@\x01\x04self\x09\0\x0d\x04\0\ -([method]resolve-address-stream.subscribe\x01\x0e\x01h\x03\x01i\x08\x01j\x01\x10\ -\x01\x05\x01@\x02\x07network\x0f\x04names\0\x11\x04\0\x11resolve-addresses\x01\x12\ -\x03\0!wasi:sockets/ip-name-lookup@0.2.4\x05.\x01B\x05\x01p}\x01@\x01\x03lenw\0\0\ -\x04\0\x10get-random-bytes\x01\x01\x01@\0\0w\x04\0\x0eget-random-u64\x01\x02\x03\ -\0\x18wasi:random/random@0.2.4\x05/\x01B\x05\x01p}\x01@\x01\x03lenw\0\0\x04\0\x19\ -get-insecure-random-bytes\x01\x01\x01@\0\0w\x04\0\x17get-insecure-random-u64\x01\ -\x02\x03\0\x1awasi:random/insecure@0.2.4\x050\x01B\x03\x01o\x02ww\x01@\0\0\0\x04\ -\0\x0dinsecure-seed\x01\x01\x03\0\x1fwasi:random/insecure-seed@0.2.4\x051\x04\0\x12\ -rust:wasi/bindings\x04\0\x0b\x0e\x01\0\x08bindings\x03\0\0\0G\x09producers\x01\x0c\ -processed-by\x02\x0dwit-component\x070.238.0\x10wit-bindgen-rust\x060.45.0"; +tcp-socket\x01\x0a\x03\0$wasi:sockets/tcp-create-socket@0.2.4\x05&\x02\x03\0\x11\ +\x0aip-address\x01B\x16\x02\x03\x02\x01\x05\x04\0\x08pollable\x03\0\0\x02\x03\x02\ +\x01\x1b\x04\0\x07network\x03\0\x02\x02\x03\x02\x01\x1d\x04\0\x0aerror-code\x03\0\ +\x04\x02\x03\x02\x01'\x04\0\x0aip-address\x03\0\x06\x04\0\x16resolve-address-str\ +eam\x03\x01\x01h\x08\x01k\x07\x01j\x01\x0a\x01\x05\x01@\x01\x04self\x09\0\x0b\x04\ +\03[method]resolve-address-stream.resolve-next-address\x01\x0c\x01i\x01\x01@\x01\ +\x04self\x09\0\x0d\x04\0([method]resolve-address-stream.subscribe\x01\x0e\x01h\x03\ +\x01i\x08\x01j\x01\x10\x01\x05\x01@\x02\x07network\x0f\x04names\0\x11\x04\0\x11r\ +esolve-addresses\x01\x12\x03\0!wasi:sockets/ip-name-lookup@0.2.4\x05(\x01B\x05\x01\ +p}\x01@\x01\x03lenw\0\0\x04\0\x10get-random-bytes\x01\x01\x01@\0\0w\x04\0\x0eget\ +-random-u64\x01\x02\x03\0\x18wasi:random/random@0.2.4\x05)\x01B\x05\x01p}\x01@\x01\ +\x03lenw\0\0\x04\0\x19get-insecure-random-bytes\x01\x01\x01@\0\0w\x04\0\x17get-i\ +nsecure-random-u64\x01\x02\x03\0\x1awasi:random/insecure@0.2.4\x05*\x01B\x03\x01\ +o\x02ww\x01@\0\0\0\x04\0\x0dinsecure-seed\x01\x01\x03\0\x1fwasi:random/insecure-\ +seed@0.2.4\x05+\x04\0\x16wasi:cli/imports@0.2.4\x04\0\x0b\x0d\x01\0\x07imports\x03\ +\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.238.0\x10wit-\ +bindgen-rust\x060.45.0"; #[inline(never)] #[doc(hidden)] pub fn __link_custom_section_describing_imports() { diff --git a/src/lib.rs b/src/lib.rs index 1da4179..dae4577 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -181,22 +181,22 @@ extern crate std; pub mod ext; // These modules are all auto-generated by `./ci/regenerate.sh` -mod bindings; #[allow(unused_imports)] mod command; +mod imports; #[allow(unused_imports)] mod proxy; // generated bindings start with the package namespace, which in this case is // `wasi`, but the crate is already called wasi, so lift everything up one level // to the root of this crate. -pub use bindings::wasi::*; +pub use imports::wasi::*; // Expand the `cli` and `http` modules with `export!` macros for the // command/proxy worlds, but also retain all the contents defined in the // `bindings` module as well. pub mod cli { - pub use super::bindings::wasi::cli::*; + pub use super::imports::wasi::cli::*; pub mod command { /// Generate an exported instance of the `wasi:cli/command` world. @@ -237,7 +237,7 @@ pub mod cli { } pub mod http { - pub use super::bindings::wasi::http::*; + pub use super::proxy::wasi::http::*; pub mod proxy { /// Generate an exported instance of the `wasi:http/proxy` world. diff --git a/src/proxy.rs b/src/proxy.rs index 527bc52..a09418b 100644 --- a/src/proxy.rs +++ b/src/proxy.rs @@ -10,8 +10,6 @@ // * with "wasi:io/poll@0.2.4" = "crate::io::poll" // * with "wasi:io/streams@0.2.4" = "crate::io::streams" // * with "wasi:random/random@0.2.4" = "crate::random::random" -// * with "wasi:http/types@0.2.4" = "crate::http::types" -// * with "wasi:http/outgoing-handler@0.2.4" = "crate::http::outgoing_handler" // * type_section_suffix: "rust-wasi-from-crates-io-proxy-world" // * default-bindings-module: "wasi" // * export-macro-name: _export_proxy @@ -25,8 +23,6820 @@ use crate::io::streams as __with_name5; use crate::cli::stdout as __with_name6; use crate::cli::stderr as __with_name7; use crate::cli::stdin as __with_name8; -use crate::http::types as __with_name9; -use crate::http::outgoing_handler as __with_name10; +#[rustfmt::skip] +#[allow(dead_code, clippy::all)] +pub mod wasi { + pub mod http { + /// This interface defines all of the types and methods for implementing + /// HTTP Requests and Responses, both incoming and outgoing, as well as + /// their headers, trailers, and bodies. + #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] + pub mod types { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + pub type Duration = super::super::super::__with_name1::Duration; + pub type InputStream = super::super::super::__with_name5::InputStream; + pub type OutputStream = super::super::super::__with_name5::OutputStream; + pub type IoError = super::super::super::__with_name4::Error; + pub type Pollable = super::super::super::__with_name0::Pollable; + /// This type corresponds to HTTP standard Methods. + #[derive(Clone)] + pub enum Method { + Get, + Head, + Post, + Put, + Delete, + Connect, + Options, + Trace, + Patch, + Other(_rt::String), + } + impl ::core::fmt::Debug for Method { + fn fmt( + &self, + f: &mut ::core::fmt::Formatter<'_>, + ) -> ::core::fmt::Result { + match self { + Method::Get => f.debug_tuple("Method::Get").finish(), + Method::Head => f.debug_tuple("Method::Head").finish(), + Method::Post => f.debug_tuple("Method::Post").finish(), + Method::Put => f.debug_tuple("Method::Put").finish(), + Method::Delete => f.debug_tuple("Method::Delete").finish(), + Method::Connect => f.debug_tuple("Method::Connect").finish(), + Method::Options => f.debug_tuple("Method::Options").finish(), + Method::Trace => f.debug_tuple("Method::Trace").finish(), + Method::Patch => f.debug_tuple("Method::Patch").finish(), + Method::Other(e) => { + f.debug_tuple("Method::Other").field(e).finish() + } + } + } + } + /// This type corresponds to HTTP standard Related Schemes. + #[derive(Clone)] + pub enum Scheme { + Http, + Https, + Other(_rt::String), + } + impl ::core::fmt::Debug for Scheme { + fn fmt( + &self, + f: &mut ::core::fmt::Formatter<'_>, + ) -> ::core::fmt::Result { + match self { + Scheme::Http => f.debug_tuple("Scheme::Http").finish(), + Scheme::Https => f.debug_tuple("Scheme::Https").finish(), + Scheme::Other(e) => { + f.debug_tuple("Scheme::Other").field(e).finish() + } + } + } + } + /// Defines the case payload type for `DNS-error` above: + #[derive(Clone)] + pub struct DnsErrorPayload { + pub rcode: Option<_rt::String>, + pub info_code: Option, + } + impl ::core::fmt::Debug for DnsErrorPayload { + fn fmt( + &self, + f: &mut ::core::fmt::Formatter<'_>, + ) -> ::core::fmt::Result { + f.debug_struct("DnsErrorPayload") + .field("rcode", &self.rcode) + .field("info-code", &self.info_code) + .finish() + } + } + /// Defines the case payload type for `TLS-alert-received` above: + #[derive(Clone)] + pub struct TlsAlertReceivedPayload { + pub alert_id: Option, + pub alert_message: Option<_rt::String>, + } + impl ::core::fmt::Debug for TlsAlertReceivedPayload { + fn fmt( + &self, + f: &mut ::core::fmt::Formatter<'_>, + ) -> ::core::fmt::Result { + f.debug_struct("TlsAlertReceivedPayload") + .field("alert-id", &self.alert_id) + .field("alert-message", &self.alert_message) + .finish() + } + } + /// Defines the case payload type for `HTTP-response-{header,trailer}-size` above: + #[derive(Clone)] + pub struct FieldSizePayload { + pub field_name: Option<_rt::String>, + pub field_size: Option, + } + impl ::core::fmt::Debug for FieldSizePayload { + fn fmt( + &self, + f: &mut ::core::fmt::Formatter<'_>, + ) -> ::core::fmt::Result { + f.debug_struct("FieldSizePayload") + .field("field-name", &self.field_name) + .field("field-size", &self.field_size) + .finish() + } + } + /// These cases are inspired by the IANA HTTP Proxy Error Types: + /// + #[derive(Clone)] + pub enum ErrorCode { + DnsTimeout, + DnsError(DnsErrorPayload), + DestinationNotFound, + DestinationUnavailable, + DestinationIpProhibited, + DestinationIpUnroutable, + ConnectionRefused, + ConnectionTerminated, + ConnectionTimeout, + ConnectionReadTimeout, + ConnectionWriteTimeout, + ConnectionLimitReached, + TlsProtocolError, + TlsCertificateError, + TlsAlertReceived(TlsAlertReceivedPayload), + HttpRequestDenied, + HttpRequestLengthRequired, + HttpRequestBodySize(Option), + HttpRequestMethodInvalid, + HttpRequestUriInvalid, + HttpRequestUriTooLong, + HttpRequestHeaderSectionSize(Option), + HttpRequestHeaderSize(Option), + HttpRequestTrailerSectionSize(Option), + HttpRequestTrailerSize(FieldSizePayload), + HttpResponseIncomplete, + HttpResponseHeaderSectionSize(Option), + HttpResponseHeaderSize(FieldSizePayload), + HttpResponseBodySize(Option), + HttpResponseTrailerSectionSize(Option), + HttpResponseTrailerSize(FieldSizePayload), + HttpResponseTransferCoding(Option<_rt::String>), + HttpResponseContentCoding(Option<_rt::String>), + HttpResponseTimeout, + HttpUpgradeFailed, + HttpProtocolError, + LoopDetected, + ConfigurationError, + /// This is a catch-all error for anything that doesn't fit cleanly into a + /// more specific case. It also includes an optional string for an + /// unstructured description of the error. Users should not depend on the + /// string for diagnosing errors, as it's not required to be consistent + /// between implementations. + InternalError(Option<_rt::String>), + } + impl ::core::fmt::Debug for ErrorCode { + fn fmt( + &self, + f: &mut ::core::fmt::Formatter<'_>, + ) -> ::core::fmt::Result { + match self { + ErrorCode::DnsTimeout => { + f.debug_tuple("ErrorCode::DnsTimeout").finish() + } + ErrorCode::DnsError(e) => { + f.debug_tuple("ErrorCode::DnsError").field(e).finish() + } + ErrorCode::DestinationNotFound => { + f.debug_tuple("ErrorCode::DestinationNotFound").finish() + } + ErrorCode::DestinationUnavailable => { + f.debug_tuple("ErrorCode::DestinationUnavailable").finish() + } + ErrorCode::DestinationIpProhibited => { + f.debug_tuple("ErrorCode::DestinationIpProhibited").finish() + } + ErrorCode::DestinationIpUnroutable => { + f.debug_tuple("ErrorCode::DestinationIpUnroutable").finish() + } + ErrorCode::ConnectionRefused => { + f.debug_tuple("ErrorCode::ConnectionRefused").finish() + } + ErrorCode::ConnectionTerminated => { + f.debug_tuple("ErrorCode::ConnectionTerminated").finish() + } + ErrorCode::ConnectionTimeout => { + f.debug_tuple("ErrorCode::ConnectionTimeout").finish() + } + ErrorCode::ConnectionReadTimeout => { + f.debug_tuple("ErrorCode::ConnectionReadTimeout").finish() + } + ErrorCode::ConnectionWriteTimeout => { + f.debug_tuple("ErrorCode::ConnectionWriteTimeout").finish() + } + ErrorCode::ConnectionLimitReached => { + f.debug_tuple("ErrorCode::ConnectionLimitReached").finish() + } + ErrorCode::TlsProtocolError => { + f.debug_tuple("ErrorCode::TlsProtocolError").finish() + } + ErrorCode::TlsCertificateError => { + f.debug_tuple("ErrorCode::TlsCertificateError").finish() + } + ErrorCode::TlsAlertReceived(e) => { + f.debug_tuple("ErrorCode::TlsAlertReceived") + .field(e) + .finish() + } + ErrorCode::HttpRequestDenied => { + f.debug_tuple("ErrorCode::HttpRequestDenied").finish() + } + ErrorCode::HttpRequestLengthRequired => { + f.debug_tuple("ErrorCode::HttpRequestLengthRequired") + .finish() + } + ErrorCode::HttpRequestBodySize(e) => { + f.debug_tuple("ErrorCode::HttpRequestBodySize") + .field(e) + .finish() + } + ErrorCode::HttpRequestMethodInvalid => { + f.debug_tuple("ErrorCode::HttpRequestMethodInvalid").finish() + } + ErrorCode::HttpRequestUriInvalid => { + f.debug_tuple("ErrorCode::HttpRequestUriInvalid").finish() + } + ErrorCode::HttpRequestUriTooLong => { + f.debug_tuple("ErrorCode::HttpRequestUriTooLong").finish() + } + ErrorCode::HttpRequestHeaderSectionSize(e) => { + f.debug_tuple("ErrorCode::HttpRequestHeaderSectionSize") + .field(e) + .finish() + } + ErrorCode::HttpRequestHeaderSize(e) => { + f.debug_tuple("ErrorCode::HttpRequestHeaderSize") + .field(e) + .finish() + } + ErrorCode::HttpRequestTrailerSectionSize(e) => { + f.debug_tuple("ErrorCode::HttpRequestTrailerSectionSize") + .field(e) + .finish() + } + ErrorCode::HttpRequestTrailerSize(e) => { + f.debug_tuple("ErrorCode::HttpRequestTrailerSize") + .field(e) + .finish() + } + ErrorCode::HttpResponseIncomplete => { + f.debug_tuple("ErrorCode::HttpResponseIncomplete").finish() + } + ErrorCode::HttpResponseHeaderSectionSize(e) => { + f.debug_tuple("ErrorCode::HttpResponseHeaderSectionSize") + .field(e) + .finish() + } + ErrorCode::HttpResponseHeaderSize(e) => { + f.debug_tuple("ErrorCode::HttpResponseHeaderSize") + .field(e) + .finish() + } + ErrorCode::HttpResponseBodySize(e) => { + f.debug_tuple("ErrorCode::HttpResponseBodySize") + .field(e) + .finish() + } + ErrorCode::HttpResponseTrailerSectionSize(e) => { + f.debug_tuple("ErrorCode::HttpResponseTrailerSectionSize") + .field(e) + .finish() + } + ErrorCode::HttpResponseTrailerSize(e) => { + f.debug_tuple("ErrorCode::HttpResponseTrailerSize") + .field(e) + .finish() + } + ErrorCode::HttpResponseTransferCoding(e) => { + f.debug_tuple("ErrorCode::HttpResponseTransferCoding") + .field(e) + .finish() + } + ErrorCode::HttpResponseContentCoding(e) => { + f.debug_tuple("ErrorCode::HttpResponseContentCoding") + .field(e) + .finish() + } + ErrorCode::HttpResponseTimeout => { + f.debug_tuple("ErrorCode::HttpResponseTimeout").finish() + } + ErrorCode::HttpUpgradeFailed => { + f.debug_tuple("ErrorCode::HttpUpgradeFailed").finish() + } + ErrorCode::HttpProtocolError => { + f.debug_tuple("ErrorCode::HttpProtocolError").finish() + } + ErrorCode::LoopDetected => { + f.debug_tuple("ErrorCode::LoopDetected").finish() + } + ErrorCode::ConfigurationError => { + f.debug_tuple("ErrorCode::ConfigurationError").finish() + } + ErrorCode::InternalError(e) => { + f.debug_tuple("ErrorCode::InternalError").field(e).finish() + } + } + } + } + impl ::core::fmt::Display for ErrorCode { + fn fmt( + &self, + f: &mut ::core::fmt::Formatter<'_>, + ) -> ::core::fmt::Result { + write!(f, "{:?}", self) + } + } + #[cfg(feature = "std")] + impl std::error::Error for ErrorCode {} + /// This type enumerates the different kinds of errors that may occur when + /// setting or appending to a `fields` resource. + #[derive(Clone, Copy)] + pub enum HeaderError { + /// This error indicates that a `field-name` or `field-value` was + /// syntactically invalid when used with an operation that sets headers in a + /// `fields`. + InvalidSyntax, + /// This error indicates that a forbidden `field-name` was used when trying + /// to set a header in a `fields`. + Forbidden, + /// This error indicates that the operation on the `fields` was not + /// permitted because the fields are immutable. + Immutable, + } + impl ::core::fmt::Debug for HeaderError { + fn fmt( + &self, + f: &mut ::core::fmt::Formatter<'_>, + ) -> ::core::fmt::Result { + match self { + HeaderError::InvalidSyntax => { + f.debug_tuple("HeaderError::InvalidSyntax").finish() + } + HeaderError::Forbidden => { + f.debug_tuple("HeaderError::Forbidden").finish() + } + HeaderError::Immutable => { + f.debug_tuple("HeaderError::Immutable").finish() + } + } + } + } + impl ::core::fmt::Display for HeaderError { + fn fmt( + &self, + f: &mut ::core::fmt::Formatter<'_>, + ) -> ::core::fmt::Result { + write!(f, "{:?}", self) + } + } + #[cfg(feature = "std")] + impl std::error::Error for HeaderError {} + /// Field keys are always strings. + /// + /// Field keys should always be treated as case insensitive by the `fields` + /// resource for the purposes of equality checking. + /// + /// # Deprecation + /// + /// This type has been deprecated in favor of the `field-name` type. + pub type FieldKey = _rt::String; + /// Field names are always strings. + /// + /// Field names should always be treated as case insensitive by the `fields` + /// resource for the purposes of equality checking. + pub type FieldName = FieldKey; + /// Field values should always be ASCII strings. However, in + /// reality, HTTP implementations often have to interpret malformed values, + /// so they are provided as a list of bytes. + pub type FieldValue = _rt::Vec; + /// This following block defines the `fields` resource which corresponds to + /// HTTP standard Fields. Fields are a common representation used for both + /// Headers and Trailers. + /// + /// A `fields` may be mutable or immutable. A `fields` created using the + /// constructor, `from-list`, or `clone` will be mutable, but a `fields` + /// resource given by other means (including, but not limited to, + /// `incoming-request.headers`, `outgoing-request.headers`) might be + /// immutable. In an immutable fields, the `set`, `append`, and `delete` + /// operations will fail with `header-error.immutable`. + #[derive(Debug)] + #[repr(transparent)] + pub struct Fields { + handle: _rt::Resource, + } + impl Fields { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for Fields { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]fields"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + /// Headers is an alias for Fields. + pub type Headers = Fields; + /// Trailers is an alias for Fields. + pub type Trailers = Fields; + /// Represents an incoming HTTP Request. + #[derive(Debug)] + #[repr(transparent)] + pub struct IncomingRequest { + handle: _rt::Resource, + } + impl IncomingRequest { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for IncomingRequest { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]incoming-request"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + /// Represents an outgoing HTTP Request. + #[derive(Debug)] + #[repr(transparent)] + pub struct OutgoingRequest { + handle: _rt::Resource, + } + impl OutgoingRequest { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for OutgoingRequest { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]outgoing-request"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + /// Parameters for making an HTTP Request. Each of these parameters is + /// currently an optional timeout applicable to the transport layer of the + /// HTTP protocol. + /// + /// These timeouts are separate from any the user may use to bound a + /// blocking call to `wasi:io/poll.poll`. + #[derive(Debug)] + #[repr(transparent)] + pub struct RequestOptions { + handle: _rt::Resource, + } + impl RequestOptions { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for RequestOptions { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]request-options"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + /// Represents the ability to send an HTTP Response. + /// + /// This resource is used by the `wasi:http/incoming-handler` interface to + /// allow a Response to be sent corresponding to the Request provided as the + /// other argument to `incoming-handler.handle`. + #[derive(Debug)] + #[repr(transparent)] + pub struct ResponseOutparam { + handle: _rt::Resource, + } + impl ResponseOutparam { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for ResponseOutparam { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]response-outparam"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + /// This type corresponds to the HTTP standard Status Code. + pub type StatusCode = u16; + /// Represents an incoming HTTP Response. + #[derive(Debug)] + #[repr(transparent)] + pub struct IncomingResponse { + handle: _rt::Resource, + } + impl IncomingResponse { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for IncomingResponse { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]incoming-response"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + /// Represents an incoming HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, indicating that the full contents of the + /// body have been received. This resource represents the contents as + /// an `input-stream` and the delivery of trailers as a `future-trailers`, + /// and ensures that the user of this interface may only be consuming either + /// the body contents or waiting on trailers at any given time. + #[derive(Debug)] + #[repr(transparent)] + pub struct IncomingBody { + handle: _rt::Resource, + } + impl IncomingBody { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for IncomingBody { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]incoming-body"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + /// Represents a future which may eventually return trailers, or an error. + /// + /// In the case that the incoming HTTP Request or Response did not have any + /// trailers, this future will resolve to the empty set of trailers once the + /// complete Request or Response body has been received. + #[derive(Debug)] + #[repr(transparent)] + pub struct FutureTrailers { + handle: _rt::Resource, + } + impl FutureTrailers { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for FutureTrailers { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]future-trailers"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + /// Represents an outgoing HTTP Response. + #[derive(Debug)] + #[repr(transparent)] + pub struct OutgoingResponse { + handle: _rt::Resource, + } + impl OutgoingResponse { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for OutgoingResponse { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]outgoing-response"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + /// Represents an outgoing HTTP Request or Response's Body. + /// + /// A body has both its contents - a stream of bytes - and a (possibly + /// empty) set of trailers, inducating the full contents of the body + /// have been sent. This resource represents the contents as an + /// `output-stream` child resource, and the completion of the body (with + /// optional trailers) with a static function that consumes the + /// `outgoing-body` resource, and ensures that the user of this interface + /// may not write to the body contents after the body has been finished. + /// + /// If the user code drops this resource, as opposed to calling the static + /// method `finish`, the implementation should treat the body as incomplete, + /// and that an error has occurred. The implementation should propagate this + /// error to the HTTP protocol by whatever means it has available, + /// including: corrupting the body on the wire, aborting the associated + /// Request, or sending a late status code for the Response. + #[derive(Debug)] + #[repr(transparent)] + pub struct OutgoingBody { + handle: _rt::Resource, + } + impl OutgoingBody { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for OutgoingBody { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]outgoing-body"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + /// Represents a future which may eventually return an incoming HTTP + /// Response, or an error. + /// + /// This resource is returned by the `wasi:http/outgoing-handler` interface to + /// provide the HTTP Response corresponding to the sent Request. + #[derive(Debug)] + #[repr(transparent)] + pub struct FutureIncomingResponse { + handle: _rt::Resource, + } + impl FutureIncomingResponse { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + Self { + handle: unsafe { _rt::Resource::from_handle(handle) }, + } + } + #[doc(hidden)] + pub fn take_handle(&self) -> u32 { + _rt::Resource::take_handle(&self.handle) + } + #[doc(hidden)] + pub fn handle(&self) -> u32 { + _rt::Resource::handle(&self.handle) + } + } + unsafe impl _rt::WasmResource for FutureIncomingResponse { + #[inline] + unsafe fn drop(_handle: u32) { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[resource-drop]future-incoming-response"] + fn drop(_: i32); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn drop(_: i32) { + unreachable!() + } + unsafe { + drop(_handle as i32); + } + } + } + #[allow(unused_unsafe, clippy::all)] + /// Attempts to extract a http-related `error` from the wasi:io `error` + /// provided. + /// + /// Stream operations which return + /// `wasi:io/stream/stream-error::last-operation-failed` have a payload of + /// type `wasi:io/error/error` with more information about the operation + /// that failed. This payload can be passed through to this function to see + /// if there's http-related information about the error to return. + /// + /// Note that this function is fallible because not all io-errors are + /// http-related errors. + #[allow(async_fn_in_trait)] + pub fn http_error_code(err: &IoError) -> Option { + unsafe { + #[repr(align(8))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 24 + 4 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 24 + + 4 * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "http-error-code"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((err).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result66 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = i32::from(*ptr0.add(8).cast::()); + let v65 = match l3 { + 0 => ErrorCode::DnsTimeout, + 1 => { + let e65 = { + let l4 = i32::from(*ptr0.add(16).cast::()); + let l8 = i32::from( + *ptr0 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + DnsErrorPayload { + rcode: match l4 { + 0 => None, + 1 => { + let e = { + let l5 = *ptr0 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l6 = *ptr0 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len7 = l6; + let bytes7 = _rt::Vec::from_raw_parts( + l5.cast(), + len7, + len7, + ); + _rt::string_lift(bytes7) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + info_code: match l8 { + 0 => None, + 1 => { + let e = { + let l9 = i32::from( + *ptr0 + .add(18 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + l9 as u16 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::DnsError(e65) + } + 2 => ErrorCode::DestinationNotFound, + 3 => ErrorCode::DestinationUnavailable, + 4 => ErrorCode::DestinationIpProhibited, + 5 => ErrorCode::DestinationIpUnroutable, + 6 => ErrorCode::ConnectionRefused, + 7 => ErrorCode::ConnectionTerminated, + 8 => ErrorCode::ConnectionTimeout, + 9 => ErrorCode::ConnectionReadTimeout, + 10 => ErrorCode::ConnectionWriteTimeout, + 11 => ErrorCode::ConnectionLimitReached, + 12 => ErrorCode::TlsProtocolError, + 13 => ErrorCode::TlsCertificateError, + 14 => { + let e65 = { + let l10 = i32::from(*ptr0.add(16).cast::()); + let l12 = i32::from( + *ptr0 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + TlsAlertReceivedPayload { + alert_id: match l10 { + 0 => None, + 1 => { + let e = { + let l11 = i32::from(*ptr0.add(17).cast::()); + l11 as u8 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + alert_message: match l12 { + 0 => None, + 1 => { + let e = { + let l13 = *ptr0 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l14 = *ptr0 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len15 = l14; + let bytes15 = _rt::Vec::from_raw_parts( + l13.cast(), + len15, + len15, + ); + _rt::string_lift(bytes15) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::TlsAlertReceived(e65) + } + 15 => ErrorCode::HttpRequestDenied, + 16 => ErrorCode::HttpRequestLengthRequired, + 17 => { + let e65 = { + let l16 = i32::from(*ptr0.add(16).cast::()); + match l16 { + 0 => None, + 1 => { + let e = { + let l17 = *ptr0.add(24).cast::(); + l17 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestBodySize(e65) + } + 18 => ErrorCode::HttpRequestMethodInvalid, + 19 => ErrorCode::HttpRequestUriInvalid, + 20 => ErrorCode::HttpRequestUriTooLong, + 21 => { + let e65 = { + let l18 = i32::from(*ptr0.add(16).cast::()); + match l18 { + 0 => None, + 1 => { + let e = { + let l19 = *ptr0.add(20).cast::(); + l19 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSectionSize(e65) + } + 22 => { + let e65 = { + let l20 = i32::from(*ptr0.add(16).cast::()); + match l20 { + 0 => None, + 1 => { + let e = { + let l21 = i32::from( + *ptr0 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + let l25 = i32::from( + *ptr0 + .add(16 + 4 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l21 { + 0 => None, + 1 => { + let e = { + let l22 = *ptr0 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l23 = *ptr0 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len24 = l23; + let bytes24 = _rt::Vec::from_raw_parts( + l22.cast(), + len24, + len24, + ); + _rt::string_lift(bytes24) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l25 { + 0 => None, + 1 => { + let e = { + let l26 = *ptr0 + .add(20 + 4 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l26 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSize(e65) + } + 23 => { + let e65 = { + let l27 = i32::from(*ptr0.add(16).cast::()); + match l27 { + 0 => None, + 1 => { + let e = { + let l28 = *ptr0.add(20).cast::(); + l28 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestTrailerSectionSize(e65) + } + 24 => { + let e65 = { + let l29 = i32::from(*ptr0.add(16).cast::()); + let l33 = i32::from( + *ptr0 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l29 { + 0 => None, + 1 => { + let e = { + let l30 = *ptr0 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l31 = *ptr0 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len32 = l31; + let bytes32 = _rt::Vec::from_raw_parts( + l30.cast(), + len32, + len32, + ); + _rt::string_lift(bytes32) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l33 { + 0 => None, + 1 => { + let e = { + let l34 = *ptr0 + .add(20 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l34 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpRequestTrailerSize(e65) + } + 25 => ErrorCode::HttpResponseIncomplete, + 26 => { + let e65 = { + let l35 = i32::from(*ptr0.add(16).cast::()); + match l35 { + 0 => None, + 1 => { + let e = { + let l36 = *ptr0.add(20).cast::(); + l36 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseHeaderSectionSize(e65) + } + 27 => { + let e65 = { + let l37 = i32::from(*ptr0.add(16).cast::()); + let l41 = i32::from( + *ptr0 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l37 { + 0 => None, + 1 => { + let e = { + let l38 = *ptr0 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l39 = *ptr0 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len40 = l39; + let bytes40 = _rt::Vec::from_raw_parts( + l38.cast(), + len40, + len40, + ); + _rt::string_lift(bytes40) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l41 { + 0 => None, + 1 => { + let e = { + let l42 = *ptr0 + .add(20 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l42 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseHeaderSize(e65) + } + 28 => { + let e65 = { + let l43 = i32::from(*ptr0.add(16).cast::()); + match l43 { + 0 => None, + 1 => { + let e = { + let l44 = *ptr0.add(24).cast::(); + l44 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseBodySize(e65) + } + 29 => { + let e65 = { + let l45 = i32::from(*ptr0.add(16).cast::()); + match l45 { + 0 => None, + 1 => { + let e = { + let l46 = *ptr0.add(20).cast::(); + l46 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTrailerSectionSize(e65) + } + 30 => { + let e65 = { + let l47 = i32::from(*ptr0.add(16).cast::()); + let l51 = i32::from( + *ptr0 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l47 { + 0 => None, + 1 => { + let e = { + let l48 = *ptr0 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l49 = *ptr0 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len50 = l49; + let bytes50 = _rt::Vec::from_raw_parts( + l48.cast(), + len50, + len50, + ); + _rt::string_lift(bytes50) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l51 { + 0 => None, + 1 => { + let e = { + let l52 = *ptr0 + .add(20 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l52 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseTrailerSize(e65) + } + 31 => { + let e65 = { + let l53 = i32::from(*ptr0.add(16).cast::()); + match l53 { + 0 => None, + 1 => { + let e = { + let l54 = *ptr0 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l55 = *ptr0 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len56 = l55; + let bytes56 = _rt::Vec::from_raw_parts( + l54.cast(), + len56, + len56, + ); + _rt::string_lift(bytes56) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTransferCoding(e65) + } + 32 => { + let e65 = { + let l57 = i32::from(*ptr0.add(16).cast::()); + match l57 { + 0 => None, + 1 => { + let e = { + let l58 = *ptr0 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l59 = *ptr0 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len60 = l59; + let bytes60 = _rt::Vec::from_raw_parts( + l58.cast(), + len60, + len60, + ); + _rt::string_lift(bytes60) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseContentCoding(e65) + } + 33 => ErrorCode::HttpResponseTimeout, + 34 => ErrorCode::HttpUpgradeFailed, + 35 => ErrorCode::HttpProtocolError, + 36 => ErrorCode::LoopDetected, + 37 => ErrorCode::ConfigurationError, + n => { + debug_assert_eq!(n, 38, "invalid enum discriminant"); + let e65 = { + let l61 = i32::from(*ptr0.add(16).cast::()); + match l61 { + 0 => None, + 1 => { + let e = { + let l62 = *ptr0 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l63 = *ptr0 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len64 = l63; + let bytes64 = _rt::Vec::from_raw_parts( + l62.cast(), + len64, + len64, + ); + _rt::string_lift(bytes64) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::InternalError(e65) + } + }; + v65 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result66 + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + /// Construct an empty HTTP Fields. + /// + /// The resulting `fields` is mutable. + #[allow(async_fn_in_trait)] + pub fn new() -> Self { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[constructor]fields"] + fn wit_import0() -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0() -> i32 { + unreachable!() + } + let ret = wit_import0(); + Fields::from_handle(ret as u32) + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + /// Construct an HTTP Fields. + /// + /// The resulting `fields` is mutable. + /// + /// The list represents each name-value pair in the Fields. Names + /// which have multiple values are represented by multiple entries in this + /// list with the same name. + /// + /// The tuple is a pair of the field name, represented as a string, and + /// Value, represented as a list of bytes. + /// + /// An error result will be returned if any `field-name` or `field-value` is + /// syntactically invalid, or if a field is forbidden. + #[allow(async_fn_in_trait)] + pub fn from_list( + entries: &[(FieldName, FieldValue)], + ) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 8], + ); + let vec3 = entries; + let len3 = vec3.len(); + let layout3 = _rt::alloc::Layout::from_size_align( + vec3.len() * (4 * ::core::mem::size_of::<*const u8>()), + ::core::mem::size_of::<*const u8>(), + ) + .unwrap(); + let (result3, _cleanup3) = wit_bindgen::rt::Cleanup::new( + layout3, + ); + for (i, e) in vec3.into_iter().enumerate() { + let base = result3 + .add(i * (4 * ::core::mem::size_of::<*const u8>())); + { + let (t0_0, t0_1) = e; + let vec1 = t0_0; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + *base + .add(::core::mem::size_of::<*const u8>()) + .cast::() = len1; + *base.add(0).cast::<*mut u8>() = ptr1.cast_mut(); + let vec2 = t0_1; + let ptr2 = vec2.as_ptr().cast::(); + let len2 = vec2.len(); + *base + .add(3 * ::core::mem::size_of::<*const u8>()) + .cast::() = len2; + *base + .add(2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>() = ptr2.cast_mut(); + } + } + let ptr4 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[static]fields.from-list"] + fn wit_import5(_: *mut u8, _: usize, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import5( + _: *mut u8, + _: usize, + _: *mut u8, + ) { + unreachable!() + } + wit_import5(result3, len3, ptr4); + let l6 = i32::from(*ptr4.add(0).cast::()); + let result10 = match l6 { + 0 => { + let e = { + let l7 = *ptr4.add(4).cast::(); + Fields::from_handle(l7 as u32) + }; + Ok(e) + } + 1 => { + let e = { + let l8 = i32::from(*ptr4.add(4).cast::()); + let v9 = match l8 { + 0 => HeaderError::InvalidSyntax, + 1 => HeaderError::Forbidden, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + HeaderError::Immutable + } + }; + v9 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result10 + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + /// Get all of the values corresponding to a name. If the name is not present + /// in this `fields` or is syntactically invalid, an empty list is returned. + /// However, if the name is present but empty, this is represented by a list + /// with one or more empty field-values present. + #[allow(async_fn_in_trait)] + pub fn get(&self, name: &str) -> _rt::Vec { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 2 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 2 + * ::core::mem::size_of::<*const u8>()], + ); + let vec0 = name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]fields.get"] + fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import2( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + ) { + unreachable!() + } + wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); + let l3 = *ptr1.add(0).cast::<*mut u8>(); + let l4 = *ptr1 + .add(::core::mem::size_of::<*const u8>()) + .cast::(); + let base8 = l3; + let len8 = l4; + let mut result8 = _rt::Vec::with_capacity(len8); + for i in 0..len8 { + let base = base8 + .add(i * (2 * ::core::mem::size_of::<*const u8>())); + let e8 = { + let l5 = *base.add(0).cast::<*mut u8>(); + let l6 = *base + .add(::core::mem::size_of::<*const u8>()) + .cast::(); + let len7 = l6; + _rt::Vec::from_raw_parts(l5.cast(), len7, len7) + }; + result8.push(e8); + } + _rt::cabi_dealloc( + base8, + len8 * (2 * ::core::mem::size_of::<*const u8>()), + ::core::mem::size_of::<*const u8>(), + ); + let result9 = result8; + result9 + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + /// Returns `true` when the name is present in this `fields`. If the name is + /// syntactically invalid, `false` is returned. + #[allow(async_fn_in_trait)] + pub fn has(&self, name: &str) -> bool { + unsafe { + let vec0 = name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]fields.has"] + fn wit_import1(_: i32, _: *mut u8, _: usize) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1( + _: i32, + _: *mut u8, + _: usize, + ) -> i32 { + unreachable!() + } + let ret = wit_import1( + (self).handle() as i32, + ptr0.cast_mut(), + len0, + ); + _rt::bool_lift(ret as u8) + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + /// Set all of the values for a name. Clears any existing values for that + /// name, if they have been set. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-name` or any of + /// the `field-value`s are syntactically invalid. + #[allow(async_fn_in_trait)] + pub fn set( + &self, + name: &str, + value: &[FieldValue], + ) -> Result<(), HeaderError> { + unsafe { + #[repr(align(1))] + struct RetArea([::core::mem::MaybeUninit; 2]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 2], + ); + let vec0 = name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let vec2 = value; + let len2 = vec2.len(); + let layout2 = _rt::alloc::Layout::from_size_align( + vec2.len() * (2 * ::core::mem::size_of::<*const u8>()), + ::core::mem::size_of::<*const u8>(), + ) + .unwrap(); + let (result2, _cleanup2) = wit_bindgen::rt::Cleanup::new( + layout2, + ); + for (i, e) in vec2.into_iter().enumerate() { + let base = result2 + .add(i * (2 * ::core::mem::size_of::<*const u8>())); + { + let vec1 = e; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + *base + .add(::core::mem::size_of::<*const u8>()) + .cast::() = len1; + *base.add(0).cast::<*mut u8>() = ptr1.cast_mut(); + } + } + let ptr3 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]fields.set"] + fn wit_import4( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import4( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ) { + unreachable!() + } + wit_import4( + (self).handle() as i32, + ptr0.cast_mut(), + len0, + result2, + len2, + ptr3, + ); + let l5 = i32::from(*ptr3.add(0).cast::()); + let result8 = match l5 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l6 = i32::from(*ptr3.add(1).cast::()); + let v7 = match l6 { + 0 => HeaderError::InvalidSyntax, + 1 => HeaderError::Forbidden, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + HeaderError::Immutable + } + }; + v7 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result8 + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + /// Delete all values for a name. Does nothing if no values for the name + /// exist. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-name` is + /// syntactically invalid. + #[allow(async_fn_in_trait)] + pub fn delete(&self, name: &str) -> Result<(), HeaderError> { + unsafe { + #[repr(align(1))] + struct RetArea([::core::mem::MaybeUninit; 2]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 2], + ); + let vec0 = name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]fields.delete"] + fn wit_import2(_: i32, _: *mut u8, _: usize, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import2( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + ) { + unreachable!() + } + wit_import2((self).handle() as i32, ptr0.cast_mut(), len0, ptr1); + let l3 = i32::from(*ptr1.add(0).cast::()); + let result6 = match l3 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l4 = i32::from(*ptr1.add(1).cast::()); + let v5 = match l4 { + 0 => HeaderError::InvalidSyntax, + 1 => HeaderError::Forbidden, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + HeaderError::Immutable + } + }; + v5 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result6 + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + /// Append a value for a name. Does not change or delete any existing + /// values for that name. + /// + /// Fails with `header-error.immutable` if the `fields` are immutable. + /// + /// Fails with `header-error.invalid-syntax` if the `field-name` or + /// `field-value` are syntactically invalid. + #[allow(async_fn_in_trait)] + pub fn append( + &self, + name: &str, + value: &[u8], + ) -> Result<(), HeaderError> { + unsafe { + #[repr(align(1))] + struct RetArea([::core::mem::MaybeUninit; 2]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 2], + ); + let vec0 = name; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + let vec1 = value; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + let ptr2 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]fields.append"] + fn wit_import3( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import3( + _: i32, + _: *mut u8, + _: usize, + _: *mut u8, + _: usize, + _: *mut u8, + ) { + unreachable!() + } + wit_import3( + (self).handle() as i32, + ptr0.cast_mut(), + len0, + ptr1.cast_mut(), + len1, + ptr2, + ); + let l4 = i32::from(*ptr2.add(0).cast::()); + let result7 = match l4 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l5 = i32::from(*ptr2.add(1).cast::()); + let v6 = match l5 { + 0 => HeaderError::InvalidSyntax, + 1 => HeaderError::Forbidden, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + HeaderError::Immutable + } + }; + v6 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result7 + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + /// Retrieve the full set of names and values in the Fields. Like the + /// constructor, the list represents each name-value pair. + /// + /// The outer list represents each name-value pair in the Fields. Names + /// which have multiple values are represented by multiple entries in this + /// list with the same name. + /// + /// The names and values are always returned in the original casing and in + /// the order in which they will be serialized for transport. + #[allow(async_fn_in_trait)] + pub fn entries(&self) -> _rt::Vec<(FieldName, FieldValue)> { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 2 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 2 + * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]fields.entries"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = *ptr0.add(0).cast::<*mut u8>(); + let l3 = *ptr0 + .add(::core::mem::size_of::<*const u8>()) + .cast::(); + let base10 = l2; + let len10 = l3; + let mut result10 = _rt::Vec::with_capacity(len10); + for i in 0..len10 { + let base = base10 + .add(i * (4 * ::core::mem::size_of::<*const u8>())); + let e10 = { + let l4 = *base.add(0).cast::<*mut u8>(); + let l5 = *base + .add(::core::mem::size_of::<*const u8>()) + .cast::(); + let len6 = l5; + let bytes6 = _rt::Vec::from_raw_parts( + l4.cast(), + len6, + len6, + ); + let l7 = *base + .add(2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l8 = *base + .add(3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len9 = l8; + ( + _rt::string_lift(bytes6), + _rt::Vec::from_raw_parts(l7.cast(), len9, len9), + ) + }; + result10.push(e10); + } + _rt::cabi_dealloc( + base10, + len10 * (4 * ::core::mem::size_of::<*const u8>()), + ::core::mem::size_of::<*const u8>(), + ); + let result11 = result10; + result11 + } + } + } + impl Fields { + #[allow(unused_unsafe, clippy::all)] + /// Make a deep copy of the Fields. Equivalent in behavior to calling the + /// `fields` constructor on the return value of `entries`. The resulting + /// `fields` is mutable. + #[allow(async_fn_in_trait)] + pub fn clone(&self) -> Fields { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]fields.clone"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((self).handle() as i32); + Fields::from_handle(ret as u32) + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Returns the method of the incoming request. + #[allow(async_fn_in_trait)] + pub fn method(&self) -> Method { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 3 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 3 + * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]incoming-request.method"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let v6 = match l2 { + 0 => Method::Get, + 1 => Method::Head, + 2 => Method::Post, + 3 => Method::Put, + 4 => Method::Delete, + 5 => Method::Connect, + 6 => Method::Options, + 7 => Method::Trace, + 8 => Method::Patch, + n => { + debug_assert_eq!(n, 9, "invalid enum discriminant"); + let e6 = { + let l3 = *ptr0 + .add(::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l4 = *ptr0 + .add(2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len5 = l4; + let bytes5 = _rt::Vec::from_raw_parts( + l3.cast(), + len5, + len5, + ); + _rt::string_lift(bytes5) + }; + Method::Other(e6) + } + }; + let result7 = v6; + result7 + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Returns the path with query parameters from the request, as a string. + #[allow(async_fn_in_trait)] + pub fn path_with_query(&self) -> Option<_rt::String> { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 3 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 3 + * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]incoming-request.path-with-query"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result6 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = *ptr0 + .add(::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l4 = *ptr0 + .add(2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len5 = l4; + let bytes5 = _rt::Vec::from_raw_parts( + l3.cast(), + len5, + len5, + ); + _rt::string_lift(bytes5) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result6 + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Returns the protocol scheme from the request. + #[allow(async_fn_in_trait)] + pub fn scheme(&self) -> Option { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 4 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 4 + * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]incoming-request.scheme"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result8 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = i32::from( + *ptr0.add(::core::mem::size_of::<*const u8>()).cast::(), + ); + let v7 = match l3 { + 0 => Scheme::Http, + 1 => Scheme::Https, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + let e7 = { + let l4 = *ptr0 + .add(2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l5 = *ptr0 + .add(3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len6 = l5; + let bytes6 = _rt::Vec::from_raw_parts( + l4.cast(), + len6, + len6, + ); + _rt::string_lift(bytes6) + }; + Scheme::Other(e7) + } + }; + v7 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result8 + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Returns the authority of the Request's target URI, if present. + #[allow(async_fn_in_trait)] + pub fn authority(&self) -> Option<_rt::String> { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 3 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 3 + * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]incoming-request.authority"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result6 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = *ptr0 + .add(::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l4 = *ptr0 + .add(2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len5 = l4; + let bytes5 = _rt::Vec::from_raw_parts( + l3.cast(), + len5, + len5, + ); + _rt::string_lift(bytes5) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result6 + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Get the `headers` associated with the request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// The `headers` returned are a child resource: it must be dropped before + /// the parent `incoming-request` is dropped. Dropping this + /// `incoming-request` before all children are dropped will trap. + #[allow(async_fn_in_trait)] + pub fn headers(&self) -> Headers { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]incoming-request.headers"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((self).handle() as i32); + Fields::from_handle(ret as u32) + } + } + } + impl IncomingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Gives the `incoming-body` associated with this request. Will only + /// return success at most once, and subsequent calls will return error. + #[allow(async_fn_in_trait)] + pub fn consume(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 8], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]incoming-request.consume"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result4 = match l2 { + 0 => { + let e = { + let l3 = *ptr0.add(4).cast::(); + IncomingBody::from_handle(l3 as u32) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result4 + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Construct a new `outgoing-request` with a default `method` of `GET`, and + /// `none` values for `path-with-query`, `scheme`, and `authority`. + /// + /// * `headers` is the HTTP Headers for the Request. + /// + /// It is possible to construct, or manipulate with the accessor functions + /// below, an `outgoing-request` with an invalid combination of `scheme` + /// and `authority`, or `headers` which are not permitted to be sent. + /// It is the obligation of the `outgoing-handler.handle` implementation + /// to reject invalid constructions of `outgoing-request`. + #[allow(async_fn_in_trait)] + pub fn new(headers: Headers) -> Self { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[constructor]outgoing-request"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((&headers).take_handle() as i32); + OutgoingRequest::from_handle(ret as u32) + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Returns the resource corresponding to the outgoing Body for this + /// Request. + /// + /// Returns success on the first call: the `outgoing-body` resource for + /// this `outgoing-request` can be retrieved at most once. Subsequent + /// calls will return error. + #[allow(async_fn_in_trait)] + pub fn body(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 8], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-request.body"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result4 = match l2 { + 0 => { + let e = { + let l3 = *ptr0.add(4).cast::(); + OutgoingBody::from_handle(l3 as u32) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result4 + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Get the Method for the Request. + #[allow(async_fn_in_trait)] + pub fn method(&self) -> Method { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 3 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 3 + * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-request.method"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let v6 = match l2 { + 0 => Method::Get, + 1 => Method::Head, + 2 => Method::Post, + 3 => Method::Put, + 4 => Method::Delete, + 5 => Method::Connect, + 6 => Method::Options, + 7 => Method::Trace, + 8 => Method::Patch, + n => { + debug_assert_eq!(n, 9, "invalid enum discriminant"); + let e6 = { + let l3 = *ptr0 + .add(::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l4 = *ptr0 + .add(2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len5 = l4; + let bytes5 = _rt::Vec::from_raw_parts( + l3.cast(), + len5, + len5, + ); + _rt::string_lift(bytes5) + }; + Method::Other(e6) + } + }; + let result7 = v6; + result7 + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Set the Method for the Request. Fails if the string present in a + /// `method.other` argument is not a syntactically valid method. + #[allow(async_fn_in_trait)] + pub fn set_method(&self, method: &Method) -> Result<(), ()> { + unsafe { + let (result1_0, result1_1, result1_2) = match method { + Method::Get => (0i32, ::core::ptr::null_mut(), 0usize), + Method::Head => (1i32, ::core::ptr::null_mut(), 0usize), + Method::Post => (2i32, ::core::ptr::null_mut(), 0usize), + Method::Put => (3i32, ::core::ptr::null_mut(), 0usize), + Method::Delete => (4i32, ::core::ptr::null_mut(), 0usize), + Method::Connect => (5i32, ::core::ptr::null_mut(), 0usize), + Method::Options => (6i32, ::core::ptr::null_mut(), 0usize), + Method::Trace => (7i32, ::core::ptr::null_mut(), 0usize), + Method::Patch => (8i32, ::core::ptr::null_mut(), 0usize), + Method::Other(e) => { + let vec0 = e; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + (9i32, ptr0.cast_mut(), len0) + } + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-request.set-method"] + fn wit_import2(_: i32, _: i32, _: *mut u8, _: usize) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import2( + _: i32, + _: i32, + _: *mut u8, + _: usize, + ) -> i32 { + unreachable!() + } + let ret = wit_import2( + (self).handle() as i32, + result1_0, + result1_1, + result1_2, + ); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Get the combination of the HTTP Path and Query for the Request. + /// When `none`, this represents an empty Path and empty Query. + #[allow(async_fn_in_trait)] + pub fn path_with_query(&self) -> Option<_rt::String> { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 3 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 3 + * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-request.path-with-query"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result6 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = *ptr0 + .add(::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l4 = *ptr0 + .add(2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len5 = l4; + let bytes5 = _rt::Vec::from_raw_parts( + l3.cast(), + len5, + len5, + ); + _rt::string_lift(bytes5) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result6 + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Set the combination of the HTTP Path and Query for the Request. + /// When `none`, this represents an empty Path and empty Query. Fails is the + /// string given is not a syntactically valid path and query uri component. + #[allow(async_fn_in_trait)] + pub fn set_path_with_query( + &self, + path_with_query: Option<&str>, + ) -> Result<(), ()> { + unsafe { + let (result1_0, result1_1, result1_2) = match path_with_query { + Some(e) => { + let vec0 = e; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + (1i32, ptr0.cast_mut(), len0) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-request.set-path-with-query"] + fn wit_import2(_: i32, _: i32, _: *mut u8, _: usize) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import2( + _: i32, + _: i32, + _: *mut u8, + _: usize, + ) -> i32 { + unreachable!() + } + let ret = wit_import2( + (self).handle() as i32, + result1_0, + result1_1, + result1_2, + ); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Get the HTTP Related Scheme for the Request. When `none`, the + /// implementation may choose an appropriate default scheme. + #[allow(async_fn_in_trait)] + pub fn scheme(&self) -> Option { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 4 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 4 + * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-request.scheme"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result8 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = i32::from( + *ptr0.add(::core::mem::size_of::<*const u8>()).cast::(), + ); + let v7 = match l3 { + 0 => Scheme::Http, + 1 => Scheme::Https, + n => { + debug_assert_eq!(n, 2, "invalid enum discriminant"); + let e7 = { + let l4 = *ptr0 + .add(2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l5 = *ptr0 + .add(3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len6 = l5; + let bytes6 = _rt::Vec::from_raw_parts( + l4.cast(), + len6, + len6, + ); + _rt::string_lift(bytes6) + }; + Scheme::Other(e7) + } + }; + v7 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result8 + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Set the HTTP Related Scheme for the Request. When `none`, the + /// implementation may choose an appropriate default scheme. Fails if the + /// string given is not a syntactically valid uri scheme. + #[allow(async_fn_in_trait)] + pub fn set_scheme(&self, scheme: Option<&Scheme>) -> Result<(), ()> { + unsafe { + let (result2_0, result2_1, result2_2, result2_3) = match scheme { + Some(e) => { + let (result1_0, result1_1, result1_2) = match e { + Scheme::Http => (0i32, ::core::ptr::null_mut(), 0usize), + Scheme::Https => (1i32, ::core::ptr::null_mut(), 0usize), + Scheme::Other(e) => { + let vec0 = e; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + (2i32, ptr0.cast_mut(), len0) + } + }; + (1i32, result1_0, result1_1, result1_2) + } + None => (0i32, 0i32, ::core::ptr::null_mut(), 0usize), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-request.set-scheme"] + fn wit_import3( + _: i32, + _: i32, + _: i32, + _: *mut u8, + _: usize, + ) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import3( + _: i32, + _: i32, + _: i32, + _: *mut u8, + _: usize, + ) -> i32 { + unreachable!() + } + let ret = wit_import3( + (self).handle() as i32, + result2_0, + result2_1, + result2_2, + result2_3, + ); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Get the authority of the Request's target URI. A value of `none` may be used + /// with Related Schemes which do not require an authority. The HTTP and + /// HTTPS schemes always require an authority. + #[allow(async_fn_in_trait)] + pub fn authority(&self) -> Option<_rt::String> { + unsafe { + #[cfg_attr(target_pointer_width = "64", repr(align(8)))] + #[cfg_attr(target_pointer_width = "32", repr(align(4)))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 3 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 3 + * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-request.authority"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result6 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = *ptr0 + .add(::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l4 = *ptr0 + .add(2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len5 = l4; + let bytes5 = _rt::Vec::from_raw_parts( + l3.cast(), + len5, + len5, + ); + _rt::string_lift(bytes5) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result6 + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Set the authority of the Request's target URI. A value of `none` may be used + /// with Related Schemes which do not require an authority. The HTTP and + /// HTTPS schemes always require an authority. Fails if the string given is + /// not a syntactically valid URI authority. + #[allow(async_fn_in_trait)] + pub fn set_authority(&self, authority: Option<&str>) -> Result<(), ()> { + unsafe { + let (result1_0, result1_1, result1_2) = match authority { + Some(e) => { + let vec0 = e; + let ptr0 = vec0.as_ptr().cast::(); + let len0 = vec0.len(); + (1i32, ptr0.cast_mut(), len0) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-request.set-authority"] + fn wit_import2(_: i32, _: i32, _: *mut u8, _: usize) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import2( + _: i32, + _: i32, + _: *mut u8, + _: usize, + ) -> i32 { + unreachable!() + } + let ret = wit_import2( + (self).handle() as i32, + result1_0, + result1_1, + result1_2, + ); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingRequest { + #[allow(unused_unsafe, clippy::all)] + /// Get the headers associated with the Request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `outgoing-request` is dropped, or its ownership is transferred to + /// another component by e.g. `outgoing-handler.handle`. + #[allow(async_fn_in_trait)] + pub fn headers(&self) -> Headers { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-request.headers"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((self).handle() as i32); + Fields::from_handle(ret as u32) + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + /// Construct a default `request-options` value. + #[allow(async_fn_in_trait)] + pub fn new() -> Self { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[constructor]request-options"] + fn wit_import0() -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0() -> i32 { + unreachable!() + } + let ret = wit_import0(); + RequestOptions::from_handle(ret as u32) + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + /// The timeout for the initial connect to the HTTP Server. + #[allow(async_fn_in_trait)] + pub fn connect_timeout(&self) -> Option { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 16], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]request-options.connect-timeout"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result4 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = *ptr0.add(8).cast::(); + l3 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result4 + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + /// Set the timeout for the initial connect to the HTTP Server. An error + /// return value indicates that this timeout is not supported. + #[allow(async_fn_in_trait)] + pub fn set_connect_timeout( + &self, + duration: Option, + ) -> Result<(), ()> { + unsafe { + let (result0_0, result0_1) = match duration { + Some(e) => (1i32, _rt::as_i64(e)), + None => (0i32, 0i64), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]request-options.set-connect-timeout"] + fn wit_import1(_: i32, _: i32, _: i64) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: i32, _: i64) -> i32 { + unreachable!() + } + let ret = wit_import1( + (self).handle() as i32, + result0_0, + result0_1, + ); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + /// The timeout for receiving the first byte of the Response body. + #[allow(async_fn_in_trait)] + pub fn first_byte_timeout(&self) -> Option { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 16], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]request-options.first-byte-timeout"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result4 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = *ptr0.add(8).cast::(); + l3 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result4 + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + /// Set the timeout for receiving the first byte of the Response body. An + /// error return value indicates that this timeout is not supported. + #[allow(async_fn_in_trait)] + pub fn set_first_byte_timeout( + &self, + duration: Option, + ) -> Result<(), ()> { + unsafe { + let (result0_0, result0_1) = match duration { + Some(e) => (1i32, _rt::as_i64(e)), + None => (0i32, 0i64), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]request-options.set-first-byte-timeout"] + fn wit_import1(_: i32, _: i32, _: i64) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: i32, _: i64) -> i32 { + unreachable!() + } + let ret = wit_import1( + (self).handle() as i32, + result0_0, + result0_1, + ); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + /// The timeout for receiving subsequent chunks of bytes in the Response + /// body stream. + #[allow(async_fn_in_trait)] + pub fn between_bytes_timeout(&self) -> Option { + unsafe { + #[repr(align(8))] + struct RetArea([::core::mem::MaybeUninit; 16]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 16], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]request-options.between-bytes-timeout"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result4 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = *ptr0.add(8).cast::(); + l3 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result4 + } + } + } + impl RequestOptions { + #[allow(unused_unsafe, clippy::all)] + /// Set the timeout for receiving subsequent chunks of bytes in the Response + /// body stream. An error return value indicates that this timeout is not + /// supported. + #[allow(async_fn_in_trait)] + pub fn set_between_bytes_timeout( + &self, + duration: Option, + ) -> Result<(), ()> { + unsafe { + let (result0_0, result0_1) = match duration { + Some(e) => (1i32, _rt::as_i64(e)), + None => (0i32, 0i64), + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]request-options.set-between-bytes-timeout"] + fn wit_import1(_: i32, _: i32, _: i64) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: i32, _: i64) -> i32 { + unreachable!() + } + let ret = wit_import1( + (self).handle() as i32, + result0_0, + result0_1, + ); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl ResponseOutparam { + #[allow(unused_unsafe, clippy::all)] + /// Set the value of the `response-outparam` to either send a response, + /// or indicate an error. + /// + /// This method consumes the `response-outparam` to ensure that it is + /// called at most once. If it is never called, the implementation + /// will respond with an error. + /// + /// The user may provide an `error` to `response` to allow the + /// implementation determine how to respond with an HTTP error response. + #[allow(async_fn_in_trait)] + pub fn set( + param: ResponseOutparam, + response: Result, + ) -> () { + unsafe { + let ( + result38_0, + result38_1, + result38_2, + result38_3, + result38_4, + result38_5, + result38_6, + result38_7, + ) = match &response { + Ok(e) => { + ( + 0i32, + (e).take_handle() as i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + Err(e) => { + let ( + result37_0, + result37_1, + result37_2, + result37_3, + result37_4, + result37_5, + result37_6, + ) = match e { + ErrorCode::DnsTimeout => { + ( + 0i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::DnsError(e) => { + let DnsErrorPayload { + rcode: rcode0, + info_code: info_code0, + } = e; + let (result2_0, result2_1, result2_2) = match rcode0 { + Some(e) => { + let vec1 = e; + let ptr1 = vec1.as_ptr().cast::(); + let len1 = vec1.len(); + (1i32, ptr1.cast_mut(), len1) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + let (result3_0, result3_1) = match info_code0 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 1i32, + result2_0, + { + let mut t = ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result2_1); + t + }, + result2_2 as *mut u8, + result3_0 as *mut u8, + result3_1 as usize, + 0i32, + ) + } + ErrorCode::DestinationNotFound => { + ( + 2i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::DestinationUnavailable => { + ( + 3i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::DestinationIpProhibited => { + ( + 4i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::DestinationIpUnroutable => { + ( + 5i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::ConnectionRefused => { + ( + 6i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::ConnectionTerminated => { + ( + 7i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::ConnectionTimeout => { + ( + 8i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::ConnectionReadTimeout => { + ( + 9i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::ConnectionWriteTimeout => { + ( + 10i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::ConnectionLimitReached => { + ( + 11i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::TlsProtocolError => { + ( + 12i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::TlsCertificateError => { + ( + 13i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::TlsAlertReceived(e) => { + let TlsAlertReceivedPayload { + alert_id: alert_id4, + alert_message: alert_message4, + } = e; + let (result5_0, result5_1) = match alert_id4 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + let (result7_0, result7_1, result7_2) = match alert_message4 { + Some(e) => { + let vec6 = e; + let ptr6 = vec6.as_ptr().cast::(); + let len6 = vec6.len(); + (1i32, ptr6.cast_mut(), len6) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + ( + 14i32, + result5_0, + ::core::mem::MaybeUninit::new(i64::from(result5_1) as u64), + result7_0 as *mut u8, + result7_1, + result7_2, + 0i32, + ) + } + ErrorCode::HttpRequestDenied => { + ( + 15i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpRequestLengthRequired => { + ( + 16i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpRequestBodySize(e) => { + let (result8_0, result8_1) = match e { + Some(e) => (1i32, _rt::as_i64(e)), + None => (0i32, 0i64), + }; + ( + 17i32, + result8_0, + ::core::mem::MaybeUninit::new(result8_1 as u64), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpRequestMethodInvalid => { + ( + 18i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpRequestUriInvalid => { + ( + 19i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpRequestUriTooLong => { + ( + 20i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpRequestHeaderSectionSize(e) => { + let (result9_0, result9_1) = match e { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 21i32, + result9_0, + ::core::mem::MaybeUninit::new(i64::from(result9_1) as u64), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpRequestHeaderSize(e) => { + let ( + result14_0, + result14_1, + result14_2, + result14_3, + result14_4, + result14_5, + ) = match e { + Some(e) => { + let FieldSizePayload { + field_name: field_name10, + field_size: field_size10, + } = e; + let (result12_0, result12_1, result12_2) = match field_name10 { + Some(e) => { + let vec11 = e; + let ptr11 = vec11.as_ptr().cast::(); + let len11 = vec11.len(); + (1i32, ptr11.cast_mut(), len11) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + let (result13_0, result13_1) = match field_size10 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 1i32, + result12_0, + result12_1, + result12_2, + result13_0, + result13_1, + ) + } + None => { + (0i32, 0i32, ::core::ptr::null_mut(), 0usize, 0i32, 0i32) + } + }; + ( + 22i32, + result14_0, + ::core::mem::MaybeUninit::new(i64::from(result14_1) as u64), + result14_2, + result14_3 as *mut u8, + result14_4 as usize, + result14_5, + ) + } + ErrorCode::HttpRequestTrailerSectionSize(e) => { + let (result15_0, result15_1) = match e { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 23i32, + result15_0, + ::core::mem::MaybeUninit::new(i64::from(result15_1) as u64), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpRequestTrailerSize(e) => { + let FieldSizePayload { + field_name: field_name16, + field_size: field_size16, + } = e; + let (result18_0, result18_1, result18_2) = match field_name16 { + Some(e) => { + let vec17 = e; + let ptr17 = vec17.as_ptr().cast::(); + let len17 = vec17.len(); + (1i32, ptr17.cast_mut(), len17) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + let (result19_0, result19_1) = match field_size16 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 24i32, + result18_0, + { + let mut t = ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result18_1); + t + }, + result18_2 as *mut u8, + result19_0 as *mut u8, + result19_1 as usize, + 0i32, + ) + } + ErrorCode::HttpResponseIncomplete => { + ( + 25i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpResponseHeaderSectionSize(e) => { + let (result20_0, result20_1) = match e { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 26i32, + result20_0, + ::core::mem::MaybeUninit::new(i64::from(result20_1) as u64), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpResponseHeaderSize(e) => { + let FieldSizePayload { + field_name: field_name21, + field_size: field_size21, + } = e; + let (result23_0, result23_1, result23_2) = match field_name21 { + Some(e) => { + let vec22 = e; + let ptr22 = vec22.as_ptr().cast::(); + let len22 = vec22.len(); + (1i32, ptr22.cast_mut(), len22) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + let (result24_0, result24_1) = match field_size21 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 27i32, + result23_0, + { + let mut t = ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result23_1); + t + }, + result23_2 as *mut u8, + result24_0 as *mut u8, + result24_1 as usize, + 0i32, + ) + } + ErrorCode::HttpResponseBodySize(e) => { + let (result25_0, result25_1) = match e { + Some(e) => (1i32, _rt::as_i64(e)), + None => (0i32, 0i64), + }; + ( + 28i32, + result25_0, + ::core::mem::MaybeUninit::new(result25_1 as u64), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpResponseTrailerSectionSize(e) => { + let (result26_0, result26_1) = match e { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 29i32, + result26_0, + ::core::mem::MaybeUninit::new(i64::from(result26_1) as u64), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpResponseTrailerSize(e) => { + let FieldSizePayload { + field_name: field_name27, + field_size: field_size27, + } = e; + let (result29_0, result29_1, result29_2) = match field_name27 { + Some(e) => { + let vec28 = e; + let ptr28 = vec28.as_ptr().cast::(); + let len28 = vec28.len(); + (1i32, ptr28.cast_mut(), len28) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + let (result30_0, result30_1) = match field_size27 { + Some(e) => (1i32, _rt::as_i32(e)), + None => (0i32, 0i32), + }; + ( + 30i32, + result29_0, + { + let mut t = ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result29_1); + t + }, + result29_2 as *mut u8, + result30_0 as *mut u8, + result30_1 as usize, + 0i32, + ) + } + ErrorCode::HttpResponseTransferCoding(e) => { + let (result32_0, result32_1, result32_2) = match e { + Some(e) => { + let vec31 = e; + let ptr31 = vec31.as_ptr().cast::(); + let len31 = vec31.len(); + (1i32, ptr31.cast_mut(), len31) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + ( + 31i32, + result32_0, + { + let mut t = ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result32_1); + t + }, + result32_2 as *mut u8, + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpResponseContentCoding(e) => { + let (result34_0, result34_1, result34_2) = match e { + Some(e) => { + let vec33 = e; + let ptr33 = vec33.as_ptr().cast::(); + let len33 = vec33.len(); + (1i32, ptr33.cast_mut(), len33) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + ( + 32i32, + result34_0, + { + let mut t = ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result34_1); + t + }, + result34_2 as *mut u8, + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpResponseTimeout => { + ( + 33i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpUpgradeFailed => { + ( + 34i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::HttpProtocolError => { + ( + 35i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::LoopDetected => { + ( + 36i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::ConfigurationError => { + ( + 37i32, + 0i32, + ::core::mem::MaybeUninit::::zeroed(), + ::core::ptr::null_mut(), + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + ErrorCode::InternalError(e) => { + let (result36_0, result36_1, result36_2) = match e { + Some(e) => { + let vec35 = e; + let ptr35 = vec35.as_ptr().cast::(); + let len35 = vec35.len(); + (1i32, ptr35.cast_mut(), len35) + } + None => (0i32, ::core::ptr::null_mut(), 0usize), + }; + ( + 38i32, + result36_0, + { + let mut t = ::core::mem::MaybeUninit::::uninit(); + t.as_mut_ptr().cast::<*mut u8>().write(result36_1); + t + }, + result36_2 as *mut u8, + ::core::ptr::null_mut(), + 0usize, + 0i32, + ) + } + }; + ( + 1i32, + result37_0, + result37_1, + result37_2, + result37_3, + result37_4, + result37_5, + result37_6, + ) + } + }; + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[static]response-outparam.set"] + fn wit_import39( + _: i32, + _: i32, + _: i32, + _: i32, + _: ::core::mem::MaybeUninit, + _: *mut u8, + _: *mut u8, + _: usize, + _: i32, + ); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import39( + _: i32, + _: i32, + _: i32, + _: i32, + _: ::core::mem::MaybeUninit, + _: *mut u8, + _: *mut u8, + _: usize, + _: i32, + ) { + unreachable!() + } + wit_import39( + (¶m).take_handle() as i32, + result38_0, + result38_1, + result38_2, + result38_3, + result38_4, + result38_5, + result38_6, + result38_7, + ); + } + } + } + impl IncomingResponse { + #[allow(unused_unsafe, clippy::all)] + /// Returns the status code from the incoming response. + #[allow(async_fn_in_trait)] + pub fn status(&self) -> StatusCode { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]incoming-response.status"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((self).handle() as i32); + ret as u16 + } + } + } + impl IncomingResponse { + #[allow(unused_unsafe, clippy::all)] + /// Returns the headers from the incoming response. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `incoming-response` is dropped. + #[allow(async_fn_in_trait)] + pub fn headers(&self) -> Headers { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]incoming-response.headers"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((self).handle() as i32); + Fields::from_handle(ret as u32) + } + } + } + impl IncomingResponse { + #[allow(unused_unsafe, clippy::all)] + /// Returns the incoming body. May be called at most once. Returns error + /// if called additional times. + #[allow(async_fn_in_trait)] + pub fn consume(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 8], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]incoming-response.consume"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result4 = match l2 { + 0 => { + let e = { + let l3 = *ptr0.add(4).cast::(); + IncomingBody::from_handle(l3 as u32) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result4 + } + } + } + impl IncomingBody { + #[allow(unused_unsafe, clippy::all)] + /// Returns the contents of the body, as a stream of bytes. + /// + /// Returns success on first call: the stream representing the contents + /// can be retrieved at most once. Subsequent calls will return error. + /// + /// The returned `input-stream` resource is a child: it must be dropped + /// before the parent `incoming-body` is dropped, or consumed by + /// `incoming-body.finish`. + /// + /// This invariant ensures that the implementation can determine whether + /// the user is consuming the contents of the body, waiting on the + /// `future-trailers` to be ready, or neither. This allows for network + /// backpressure is to be applied when the user is consuming the body, + /// and for that backpressure to not inhibit delivery of the trailers if + /// the user does not read the entire body. + #[allow(async_fn_in_trait)] + pub fn stream(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 8], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]incoming-body.stream"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result4 = match l2 { + 0 => { + let e = { + let l3 = *ptr0.add(4).cast::(); + super::super::super::__with_name5::InputStream::from_handle( + l3 as u32, + ) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result4 + } + } + } + impl IncomingBody { + #[allow(unused_unsafe, clippy::all)] + /// Takes ownership of `incoming-body`, and returns a `future-trailers`. + /// This function will trap if the `input-stream` child is still alive. + #[allow(async_fn_in_trait)] + pub fn finish(this: IncomingBody) -> FutureTrailers { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[static]incoming-body.finish"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((&this).take_handle() as i32); + FutureTrailers::from_handle(ret as u32) + } + } + } + impl FutureTrailers { + #[allow(unused_unsafe, clippy::all)] + /// Returns a pollable which becomes ready when either the trailers have + /// been received, or an error has occurred. When this pollable is ready, + /// the `get` method will return `some`. + #[allow(async_fn_in_trait)] + pub fn subscribe(&self) -> Pollable { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]future-trailers.subscribe"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((self).handle() as i32); + super::super::super::__with_name0::Pollable::from_handle( + ret as u32, + ) + } + } + } + impl FutureTrailers { + #[allow(unused_unsafe, clippy::all)] + /// Returns the contents of the trailers, or an error which occurred, + /// once the future is ready. + /// + /// The outer `option` represents future readiness. Users can wait on this + /// `option` to become `some` using the `subscribe` method. + /// + /// The outer `result` is used to retrieve the trailers or error at most + /// once. It will be success on the first call in which the outer option + /// is `some`, and error on subsequent calls. + /// + /// The inner `result` represents that either the HTTP Request or Response + /// body, as well as any trailers, were received successfully, or that an + /// error occurred receiving them. The optional `trailers` indicates whether + /// or not trailers were present in the body. + /// + /// When some `trailers` are returned by this method, the `trailers` + /// resource is immutable, and a child. Use of the `set`, `append`, or + /// `delete` methods will return an error, and the resource must be + /// dropped before the parent `future-trailers` is dropped. + #[allow(async_fn_in_trait)] + pub fn get( + &self, + ) -> Option, ErrorCode>, ()>> { + unsafe { + #[repr(align(8))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 40 + 4 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 40 + + 4 * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]future-trailers.get"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result70 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = i32::from(*ptr0.add(8).cast::()); + match l3 { + 0 => { + let e = { + let l4 = i32::from(*ptr0.add(16).cast::()); + match l4 { + 0 => { + let e = { + let l5 = i32::from(*ptr0.add(24).cast::()); + match l5 { + 0 => None, + 1 => { + let e = { + let l6 = *ptr0.add(28).cast::(); + Fields::from_handle(l6 as u32) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + Ok(e) + } + 1 => { + let e = { + let l7 = i32::from(*ptr0.add(24).cast::()); + let v69 = match l7 { + 0 => ErrorCode::DnsTimeout, + 1 => { + let e69 = { + let l8 = i32::from(*ptr0.add(32).cast::()); + let l12 = i32::from( + *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + DnsErrorPayload { + rcode: match l8 { + 0 => None, + 1 => { + let e = { + let l9 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l10 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len11 = l10; + let bytes11 = _rt::Vec::from_raw_parts( + l9.cast(), + len11, + len11, + ); + _rt::string_lift(bytes11) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + info_code: match l12 { + 0 => None, + 1 => { + let e = { + let l13 = i32::from( + *ptr0 + .add(34 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + l13 as u16 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::DnsError(e69) + } + 2 => ErrorCode::DestinationNotFound, + 3 => ErrorCode::DestinationUnavailable, + 4 => ErrorCode::DestinationIpProhibited, + 5 => ErrorCode::DestinationIpUnroutable, + 6 => ErrorCode::ConnectionRefused, + 7 => ErrorCode::ConnectionTerminated, + 8 => ErrorCode::ConnectionTimeout, + 9 => ErrorCode::ConnectionReadTimeout, + 10 => ErrorCode::ConnectionWriteTimeout, + 11 => ErrorCode::ConnectionLimitReached, + 12 => ErrorCode::TlsProtocolError, + 13 => ErrorCode::TlsCertificateError, + 14 => { + let e69 = { + let l14 = i32::from(*ptr0.add(32).cast::()); + let l16 = i32::from( + *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + TlsAlertReceivedPayload { + alert_id: match l14 { + 0 => None, + 1 => { + let e = { + let l15 = i32::from(*ptr0.add(33).cast::()); + l15 as u8 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + alert_message: match l16 { + 0 => None, + 1 => { + let e = { + let l17 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l18 = *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len19 = l18; + let bytes19 = _rt::Vec::from_raw_parts( + l17.cast(), + len19, + len19, + ); + _rt::string_lift(bytes19) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::TlsAlertReceived(e69) + } + 15 => ErrorCode::HttpRequestDenied, + 16 => ErrorCode::HttpRequestLengthRequired, + 17 => { + let e69 = { + let l20 = i32::from(*ptr0.add(32).cast::()); + match l20 { + 0 => None, + 1 => { + let e = { + let l21 = *ptr0.add(40).cast::(); + l21 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestBodySize(e69) + } + 18 => ErrorCode::HttpRequestMethodInvalid, + 19 => ErrorCode::HttpRequestUriInvalid, + 20 => ErrorCode::HttpRequestUriTooLong, + 21 => { + let e69 = { + let l22 = i32::from(*ptr0.add(32).cast::()); + match l22 { + 0 => None, + 1 => { + let e = { + let l23 = *ptr0.add(36).cast::(); + l23 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSectionSize(e69) + } + 22 => { + let e69 = { + let l24 = i32::from(*ptr0.add(32).cast::()); + match l24 { + 0 => None, + 1 => { + let e = { + let l25 = i32::from( + *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + let l29 = i32::from( + *ptr0 + .add(32 + 4 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l25 { + 0 => None, + 1 => { + let e = { + let l26 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l27 = *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len28 = l27; + let bytes28 = _rt::Vec::from_raw_parts( + l26.cast(), + len28, + len28, + ); + _rt::string_lift(bytes28) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l29 { + 0 => None, + 1 => { + let e = { + let l30 = *ptr0 + .add(36 + 4 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l30 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSize(e69) + } + 23 => { + let e69 = { + let l31 = i32::from(*ptr0.add(32).cast::()); + match l31 { + 0 => None, + 1 => { + let e = { + let l32 = *ptr0.add(36).cast::(); + l32 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestTrailerSectionSize(e69) + } + 24 => { + let e69 = { + let l33 = i32::from(*ptr0.add(32).cast::()); + let l37 = i32::from( + *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l33 { + 0 => None, + 1 => { + let e = { + let l34 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l35 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len36 = l35; + let bytes36 = _rt::Vec::from_raw_parts( + l34.cast(), + len36, + len36, + ); + _rt::string_lift(bytes36) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l37 { + 0 => None, + 1 => { + let e = { + let l38 = *ptr0 + .add(36 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l38 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpRequestTrailerSize(e69) + } + 25 => ErrorCode::HttpResponseIncomplete, + 26 => { + let e69 = { + let l39 = i32::from(*ptr0.add(32).cast::()); + match l39 { + 0 => None, + 1 => { + let e = { + let l40 = *ptr0.add(36).cast::(); + l40 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseHeaderSectionSize(e69) + } + 27 => { + let e69 = { + let l41 = i32::from(*ptr0.add(32).cast::()); + let l45 = i32::from( + *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l41 { + 0 => None, + 1 => { + let e = { + let l42 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l43 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len44 = l43; + let bytes44 = _rt::Vec::from_raw_parts( + l42.cast(), + len44, + len44, + ); + _rt::string_lift(bytes44) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l45 { + 0 => None, + 1 => { + let e = { + let l46 = *ptr0 + .add(36 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l46 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseHeaderSize(e69) + } + 28 => { + let e69 = { + let l47 = i32::from(*ptr0.add(32).cast::()); + match l47 { + 0 => None, + 1 => { + let e = { + let l48 = *ptr0.add(40).cast::(); + l48 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseBodySize(e69) + } + 29 => { + let e69 = { + let l49 = i32::from(*ptr0.add(32).cast::()); + match l49 { + 0 => None, + 1 => { + let e = { + let l50 = *ptr0.add(36).cast::(); + l50 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTrailerSectionSize(e69) + } + 30 => { + let e69 = { + let l51 = i32::from(*ptr0.add(32).cast::()); + let l55 = i32::from( + *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l51 { + 0 => None, + 1 => { + let e = { + let l52 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l53 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len54 = l53; + let bytes54 = _rt::Vec::from_raw_parts( + l52.cast(), + len54, + len54, + ); + _rt::string_lift(bytes54) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l55 { + 0 => None, + 1 => { + let e = { + let l56 = *ptr0 + .add(36 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l56 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseTrailerSize(e69) + } + 31 => { + let e69 = { + let l57 = i32::from(*ptr0.add(32).cast::()); + match l57 { + 0 => None, + 1 => { + let e = { + let l58 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l59 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len60 = l59; + let bytes60 = _rt::Vec::from_raw_parts( + l58.cast(), + len60, + len60, + ); + _rt::string_lift(bytes60) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTransferCoding(e69) + } + 32 => { + let e69 = { + let l61 = i32::from(*ptr0.add(32).cast::()); + match l61 { + 0 => None, + 1 => { + let e = { + let l62 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l63 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len64 = l63; + let bytes64 = _rt::Vec::from_raw_parts( + l62.cast(), + len64, + len64, + ); + _rt::string_lift(bytes64) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseContentCoding(e69) + } + 33 => ErrorCode::HttpResponseTimeout, + 34 => ErrorCode::HttpUpgradeFailed, + 35 => ErrorCode::HttpProtocolError, + 36 => ErrorCode::LoopDetected, + 37 => ErrorCode::ConfigurationError, + n => { + debug_assert_eq!(n, 38, "invalid enum discriminant"); + let e69 = { + let l65 = i32::from(*ptr0.add(32).cast::()); + match l65 { + 0 => None, + 1 => { + let e = { + let l66 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l67 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len68 = l67; + let bytes68 = _rt::Vec::from_raw_parts( + l66.cast(), + len68, + len68, + ); + _rt::string_lift(bytes68) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::InternalError(e69) + } + }; + v69 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result70 + } + } + } + impl OutgoingResponse { + #[allow(unused_unsafe, clippy::all)] + /// Construct an `outgoing-response`, with a default `status-code` of `200`. + /// If a different `status-code` is needed, it must be set via the + /// `set-status-code` method. + /// + /// * `headers` is the HTTP Headers for the Response. + #[allow(async_fn_in_trait)] + pub fn new(headers: Headers) -> Self { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[constructor]outgoing-response"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((&headers).take_handle() as i32); + OutgoingResponse::from_handle(ret as u32) + } + } + } + impl OutgoingResponse { + #[allow(unused_unsafe, clippy::all)] + /// Get the HTTP Status Code for the Response. + #[allow(async_fn_in_trait)] + pub fn status_code(&self) -> StatusCode { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-response.status-code"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((self).handle() as i32); + ret as u16 + } + } + } + impl OutgoingResponse { + #[allow(unused_unsafe, clippy::all)] + /// Set the HTTP Status Code for the Response. Fails if the status-code + /// given is not a valid http status code. + #[allow(async_fn_in_trait)] + pub fn set_status_code( + &self, + status_code: StatusCode, + ) -> Result<(), ()> { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-response.set-status-code"] + fn wit_import0(_: i32, _: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32, _: i32) -> i32 { + unreachable!() + } + let ret = wit_import0( + (self).handle() as i32, + _rt::as_i32(status_code), + ); + match ret { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + } + } + } + impl OutgoingResponse { + #[allow(unused_unsafe, clippy::all)] + /// Get the headers associated with the Request. + /// + /// The returned `headers` resource is immutable: `set`, `append`, and + /// `delete` operations will fail with `header-error.immutable`. + /// + /// This headers resource is a child: it must be dropped before the parent + /// `outgoing-request` is dropped, or its ownership is transferred to + /// another component by e.g. `outgoing-handler.handle`. + #[allow(async_fn_in_trait)] + pub fn headers(&self) -> Headers { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-response.headers"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((self).handle() as i32); + Fields::from_handle(ret as u32) + } + } + } + impl OutgoingResponse { + #[allow(unused_unsafe, clippy::all)] + /// Returns the resource corresponding to the outgoing Body for this Response. + /// + /// Returns success on the first call: the `outgoing-body` resource for + /// this `outgoing-response` can be retrieved at most once. Subsequent + /// calls will return error. + #[allow(async_fn_in_trait)] + pub fn body(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 8], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-response.body"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result4 = match l2 { + 0 => { + let e = { + let l3 = *ptr0.add(4).cast::(); + OutgoingBody::from_handle(l3 as u32) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result4 + } + } + } + impl OutgoingBody { + #[allow(unused_unsafe, clippy::all)] + /// Returns a stream for writing the body contents. + /// + /// The returned `output-stream` is a child resource: it must be dropped + /// before the parent `outgoing-body` resource is dropped (or finished), + /// otherwise the `outgoing-body` drop or `finish` will trap. + /// + /// Returns success on the first call: the `output-stream` resource for + /// this `outgoing-body` may be retrieved at most once. Subsequent calls + /// will return error. + #[allow(async_fn_in_trait)] + pub fn write(&self) -> Result { + unsafe { + #[repr(align(4))] + struct RetArea([::core::mem::MaybeUninit; 8]); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 8], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]outgoing-body.write"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result4 = match l2 { + 0 => { + let e = { + let l3 = *ptr0.add(4).cast::(); + super::super::super::__with_name5::OutputStream::from_handle( + l3 as u32, + ) + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result4 + } + } + } + impl OutgoingBody { + #[allow(unused_unsafe, clippy::all)] + /// Finalize an outgoing body, optionally providing trailers. This must be + /// called to signal that the response is complete. If the `outgoing-body` + /// is dropped without calling `outgoing-body.finalize`, the implementation + /// should treat the body as corrupted. + /// + /// Fails if the body's `outgoing-request` or `outgoing-response` was + /// constructed with a Content-Length header, and the contents written + /// to the body (via `write`) does not match the value given in the + /// Content-Length. + #[allow(async_fn_in_trait)] + pub fn finish( + this: OutgoingBody, + trailers: Option, + ) -> Result<(), ErrorCode> { + unsafe { + #[repr(align(8))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 24 + 4 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 24 + + 4 * ::core::mem::size_of::<*const u8>()], + ); + let (result0_0, result0_1) = match &trailers { + Some(e) => (1i32, (e).take_handle() as i32), + None => (0i32, 0i32), + }; + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[static]outgoing-body.finish"] + fn wit_import2(_: i32, _: i32, _: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import2( + _: i32, + _: i32, + _: i32, + _: *mut u8, + ) { + unreachable!() + } + wit_import2( + (&this).take_handle() as i32, + result0_0, + result0_1, + ptr1, + ); + let l3 = i32::from(*ptr1.add(0).cast::()); + let result67 = match l3 { + 0 => { + let e = (); + Ok(e) + } + 1 => { + let e = { + let l4 = i32::from(*ptr1.add(8).cast::()); + let v66 = match l4 { + 0 => ErrorCode::DnsTimeout, + 1 => { + let e66 = { + let l5 = i32::from(*ptr1.add(16).cast::()); + let l9 = i32::from( + *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + DnsErrorPayload { + rcode: match l5 { + 0 => None, + 1 => { + let e = { + let l6 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l7 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len8 = l7; + let bytes8 = _rt::Vec::from_raw_parts( + l6.cast(), + len8, + len8, + ); + _rt::string_lift(bytes8) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + info_code: match l9 { + 0 => None, + 1 => { + let e = { + let l10 = i32::from( + *ptr1 + .add(18 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + l10 as u16 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::DnsError(e66) + } + 2 => ErrorCode::DestinationNotFound, + 3 => ErrorCode::DestinationUnavailable, + 4 => ErrorCode::DestinationIpProhibited, + 5 => ErrorCode::DestinationIpUnroutable, + 6 => ErrorCode::ConnectionRefused, + 7 => ErrorCode::ConnectionTerminated, + 8 => ErrorCode::ConnectionTimeout, + 9 => ErrorCode::ConnectionReadTimeout, + 10 => ErrorCode::ConnectionWriteTimeout, + 11 => ErrorCode::ConnectionLimitReached, + 12 => ErrorCode::TlsProtocolError, + 13 => ErrorCode::TlsCertificateError, + 14 => { + let e66 = { + let l11 = i32::from(*ptr1.add(16).cast::()); + let l13 = i32::from( + *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + TlsAlertReceivedPayload { + alert_id: match l11 { + 0 => None, + 1 => { + let e = { + let l12 = i32::from(*ptr1.add(17).cast::()); + l12 as u8 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + alert_message: match l13 { + 0 => None, + 1 => { + let e = { + let l14 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l15 = *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len16 = l15; + let bytes16 = _rt::Vec::from_raw_parts( + l14.cast(), + len16, + len16, + ); + _rt::string_lift(bytes16) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::TlsAlertReceived(e66) + } + 15 => ErrorCode::HttpRequestDenied, + 16 => ErrorCode::HttpRequestLengthRequired, + 17 => { + let e66 = { + let l17 = i32::from(*ptr1.add(16).cast::()); + match l17 { + 0 => None, + 1 => { + let e = { + let l18 = *ptr1.add(24).cast::(); + l18 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestBodySize(e66) + } + 18 => ErrorCode::HttpRequestMethodInvalid, + 19 => ErrorCode::HttpRequestUriInvalid, + 20 => ErrorCode::HttpRequestUriTooLong, + 21 => { + let e66 = { + let l19 = i32::from(*ptr1.add(16).cast::()); + match l19 { + 0 => None, + 1 => { + let e = { + let l20 = *ptr1.add(20).cast::(); + l20 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSectionSize(e66) + } + 22 => { + let e66 = { + let l21 = i32::from(*ptr1.add(16).cast::()); + match l21 { + 0 => None, + 1 => { + let e = { + let l22 = i32::from( + *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + let l26 = i32::from( + *ptr1 + .add(16 + 4 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l22 { + 0 => None, + 1 => { + let e = { + let l23 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l24 = *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len25 = l24; + let bytes25 = _rt::Vec::from_raw_parts( + l23.cast(), + len25, + len25, + ); + _rt::string_lift(bytes25) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l26 { + 0 => None, + 1 => { + let e = { + let l27 = *ptr1 + .add(20 + 4 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l27 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSize(e66) + } + 23 => { + let e66 = { + let l28 = i32::from(*ptr1.add(16).cast::()); + match l28 { + 0 => None, + 1 => { + let e = { + let l29 = *ptr1.add(20).cast::(); + l29 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestTrailerSectionSize(e66) + } + 24 => { + let e66 = { + let l30 = i32::from(*ptr1.add(16).cast::()); + let l34 = i32::from( + *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l30 { + 0 => None, + 1 => { + let e = { + let l31 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l32 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len33 = l32; + let bytes33 = _rt::Vec::from_raw_parts( + l31.cast(), + len33, + len33, + ); + _rt::string_lift(bytes33) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l34 { + 0 => None, + 1 => { + let e = { + let l35 = *ptr1 + .add(20 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l35 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpRequestTrailerSize(e66) + } + 25 => ErrorCode::HttpResponseIncomplete, + 26 => { + let e66 = { + let l36 = i32::from(*ptr1.add(16).cast::()); + match l36 { + 0 => None, + 1 => { + let e = { + let l37 = *ptr1.add(20).cast::(); + l37 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseHeaderSectionSize(e66) + } + 27 => { + let e66 = { + let l38 = i32::from(*ptr1.add(16).cast::()); + let l42 = i32::from( + *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l38 { + 0 => None, + 1 => { + let e = { + let l39 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l40 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len41 = l40; + let bytes41 = _rt::Vec::from_raw_parts( + l39.cast(), + len41, + len41, + ); + _rt::string_lift(bytes41) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l42 { + 0 => None, + 1 => { + let e = { + let l43 = *ptr1 + .add(20 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l43 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseHeaderSize(e66) + } + 28 => { + let e66 = { + let l44 = i32::from(*ptr1.add(16).cast::()); + match l44 { + 0 => None, + 1 => { + let e = { + let l45 = *ptr1.add(24).cast::(); + l45 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseBodySize(e66) + } + 29 => { + let e66 = { + let l46 = i32::from(*ptr1.add(16).cast::()); + match l46 { + 0 => None, + 1 => { + let e = { + let l47 = *ptr1.add(20).cast::(); + l47 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTrailerSectionSize(e66) + } + 30 => { + let e66 = { + let l48 = i32::from(*ptr1.add(16).cast::()); + let l52 = i32::from( + *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l48 { + 0 => None, + 1 => { + let e = { + let l49 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l50 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len51 = l50; + let bytes51 = _rt::Vec::from_raw_parts( + l49.cast(), + len51, + len51, + ); + _rt::string_lift(bytes51) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l52 { + 0 => None, + 1 => { + let e = { + let l53 = *ptr1 + .add(20 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l53 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseTrailerSize(e66) + } + 31 => { + let e66 = { + let l54 = i32::from(*ptr1.add(16).cast::()); + match l54 { + 0 => None, + 1 => { + let e = { + let l55 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l56 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len57 = l56; + let bytes57 = _rt::Vec::from_raw_parts( + l55.cast(), + len57, + len57, + ); + _rt::string_lift(bytes57) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTransferCoding(e66) + } + 32 => { + let e66 = { + let l58 = i32::from(*ptr1.add(16).cast::()); + match l58 { + 0 => None, + 1 => { + let e = { + let l59 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l60 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len61 = l60; + let bytes61 = _rt::Vec::from_raw_parts( + l59.cast(), + len61, + len61, + ); + _rt::string_lift(bytes61) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseContentCoding(e66) + } + 33 => ErrorCode::HttpResponseTimeout, + 34 => ErrorCode::HttpUpgradeFailed, + 35 => ErrorCode::HttpProtocolError, + 36 => ErrorCode::LoopDetected, + 37 => ErrorCode::ConfigurationError, + n => { + debug_assert_eq!(n, 38, "invalid enum discriminant"); + let e66 = { + let l62 = i32::from(*ptr1.add(16).cast::()); + match l62 { + 0 => None, + 1 => { + let e = { + let l63 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l64 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len65 = l64; + let bytes65 = _rt::Vec::from_raw_parts( + l63.cast(), + len65, + len65, + ); + _rt::string_lift(bytes65) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::InternalError(e66) + } + }; + v66 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result67 + } + } + } + impl FutureIncomingResponse { + #[allow(unused_unsafe, clippy::all)] + /// Returns a pollable which becomes ready when either the Response has + /// been received, or an error has occurred. When this pollable is ready, + /// the `get` method will return `some`. + #[allow(async_fn_in_trait)] + pub fn subscribe(&self) -> Pollable { + unsafe { + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]future-incoming-response.subscribe"] + fn wit_import0(_: i32) -> i32; + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import0(_: i32) -> i32 { + unreachable!() + } + let ret = wit_import0((self).handle() as i32); + super::super::super::__with_name0::Pollable::from_handle( + ret as u32, + ) + } + } + } + impl FutureIncomingResponse { + #[allow(unused_unsafe, clippy::all)] + /// Returns the incoming HTTP Response, or an error, once one is ready. + /// + /// The outer `option` represents future readiness. Users can wait on this + /// `option` to become `some` using the `subscribe` method. + /// + /// The outer `result` is used to retrieve the response or error at most + /// once. It will be success on the first call in which the outer option + /// is `some`, and error on subsequent calls. + /// + /// The inner `result` represents that either the incoming HTTP Response + /// status and headers have received successfully, or that an error + /// occurred. Errors may also occur while consuming the response body, + /// but those will be reported by the `incoming-body` and its + /// `output-stream` child. + #[allow(async_fn_in_trait)] + pub fn get( + &self, + ) -> Option, ()>> { + unsafe { + #[repr(align(8))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 40 + 4 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 40 + + 4 * ::core::mem::size_of::<*const u8>()], + ); + let ptr0 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/types@0.2.4")] + unsafe extern "C" { + #[link_name = "[method]future-incoming-response.get"] + fn wit_import1(_: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import1(_: i32, _: *mut u8) { + unreachable!() + } + wit_import1((self).handle() as i32, ptr0); + let l2 = i32::from(*ptr0.add(0).cast::()); + let result69 = match l2 { + 0 => None, + 1 => { + let e = { + let l3 = i32::from(*ptr0.add(8).cast::()); + match l3 { + 0 => { + let e = { + let l4 = i32::from(*ptr0.add(16).cast::()); + match l4 { + 0 => { + let e = { + let l5 = *ptr0.add(24).cast::(); + IncomingResponse::from_handle(l5 as u32) + }; + Ok(e) + } + 1 => { + let e = { + let l6 = i32::from(*ptr0.add(24).cast::()); + let v68 = match l6 { + 0 => ErrorCode::DnsTimeout, + 1 => { + let e68 = { + let l7 = i32::from(*ptr0.add(32).cast::()); + let l11 = i32::from( + *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + DnsErrorPayload { + rcode: match l7 { + 0 => None, + 1 => { + let e = { + let l8 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l9 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len10 = l9; + let bytes10 = _rt::Vec::from_raw_parts( + l8.cast(), + len10, + len10, + ); + _rt::string_lift(bytes10) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + info_code: match l11 { + 0 => None, + 1 => { + let e = { + let l12 = i32::from( + *ptr0 + .add(34 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + l12 as u16 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::DnsError(e68) + } + 2 => ErrorCode::DestinationNotFound, + 3 => ErrorCode::DestinationUnavailable, + 4 => ErrorCode::DestinationIpProhibited, + 5 => ErrorCode::DestinationIpUnroutable, + 6 => ErrorCode::ConnectionRefused, + 7 => ErrorCode::ConnectionTerminated, + 8 => ErrorCode::ConnectionTimeout, + 9 => ErrorCode::ConnectionReadTimeout, + 10 => ErrorCode::ConnectionWriteTimeout, + 11 => ErrorCode::ConnectionLimitReached, + 12 => ErrorCode::TlsProtocolError, + 13 => ErrorCode::TlsCertificateError, + 14 => { + let e68 = { + let l13 = i32::from(*ptr0.add(32).cast::()); + let l15 = i32::from( + *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + TlsAlertReceivedPayload { + alert_id: match l13 { + 0 => None, + 1 => { + let e = { + let l14 = i32::from(*ptr0.add(33).cast::()); + l14 as u8 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + alert_message: match l15 { + 0 => None, + 1 => { + let e = { + let l16 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l17 = *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len18 = l17; + let bytes18 = _rt::Vec::from_raw_parts( + l16.cast(), + len18, + len18, + ); + _rt::string_lift(bytes18) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::TlsAlertReceived(e68) + } + 15 => ErrorCode::HttpRequestDenied, + 16 => ErrorCode::HttpRequestLengthRequired, + 17 => { + let e68 = { + let l19 = i32::from(*ptr0.add(32).cast::()); + match l19 { + 0 => None, + 1 => { + let e = { + let l20 = *ptr0.add(40).cast::(); + l20 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestBodySize(e68) + } + 18 => ErrorCode::HttpRequestMethodInvalid, + 19 => ErrorCode::HttpRequestUriInvalid, + 20 => ErrorCode::HttpRequestUriTooLong, + 21 => { + let e68 = { + let l21 = i32::from(*ptr0.add(32).cast::()); + match l21 { + 0 => None, + 1 => { + let e = { + let l22 = *ptr0.add(36).cast::(); + l22 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSectionSize(e68) + } + 22 => { + let e68 = { + let l23 = i32::from(*ptr0.add(32).cast::()); + match l23 { + 0 => None, + 1 => { + let e = { + let l24 = i32::from( + *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + let l28 = i32::from( + *ptr0 + .add(32 + 4 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l24 { + 0 => None, + 1 => { + let e = { + let l25 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l26 = *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len27 = l26; + let bytes27 = _rt::Vec::from_raw_parts( + l25.cast(), + len27, + len27, + ); + _rt::string_lift(bytes27) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l28 { + 0 => None, + 1 => { + let e = { + let l29 = *ptr0 + .add(36 + 4 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l29 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestHeaderSize(e68) + } + 23 => { + let e68 = { + let l30 = i32::from(*ptr0.add(32).cast::()); + match l30 { + 0 => None, + 1 => { + let e = { + let l31 = *ptr0.add(36).cast::(); + l31 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpRequestTrailerSectionSize(e68) + } + 24 => { + let e68 = { + let l32 = i32::from(*ptr0.add(32).cast::()); + let l36 = i32::from( + *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l32 { + 0 => None, + 1 => { + let e = { + let l33 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l34 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len35 = l34; + let bytes35 = _rt::Vec::from_raw_parts( + l33.cast(), + len35, + len35, + ); + _rt::string_lift(bytes35) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l36 { + 0 => None, + 1 => { + let e = { + let l37 = *ptr0 + .add(36 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l37 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpRequestTrailerSize(e68) + } + 25 => ErrorCode::HttpResponseIncomplete, + 26 => { + let e68 = { + let l38 = i32::from(*ptr0.add(32).cast::()); + match l38 { + 0 => None, + 1 => { + let e = { + let l39 = *ptr0.add(36).cast::(); + l39 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseHeaderSectionSize(e68) + } + 27 => { + let e68 = { + let l40 = i32::from(*ptr0.add(32).cast::()); + let l44 = i32::from( + *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l40 { + 0 => None, + 1 => { + let e = { + let l41 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l42 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len43 = l42; + let bytes43 = _rt::Vec::from_raw_parts( + l41.cast(), + len43, + len43, + ); + _rt::string_lift(bytes43) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l44 { + 0 => None, + 1 => { + let e = { + let l45 = *ptr0 + .add(36 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l45 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseHeaderSize(e68) + } + 28 => { + let e68 = { + let l46 = i32::from(*ptr0.add(32).cast::()); + match l46 { + 0 => None, + 1 => { + let e = { + let l47 = *ptr0.add(40).cast::(); + l47 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseBodySize(e68) + } + 29 => { + let e68 = { + let l48 = i32::from(*ptr0.add(32).cast::()); + match l48 { + 0 => None, + 1 => { + let e = { + let l49 = *ptr0.add(36).cast::(); + l49 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTrailerSectionSize(e68) + } + 30 => { + let e68 = { + let l50 = i32::from(*ptr0.add(32).cast::()); + let l54 = i32::from( + *ptr0 + .add(32 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + FieldSizePayload { + field_name: match l50 { + 0 => None, + 1 => { + let e = { + let l51 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l52 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len53 = l52; + let bytes53 = _rt::Vec::from_raw_parts( + l51.cast(), + len53, + len53, + ); + _rt::string_lift(bytes53) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l54 { + 0 => None, + 1 => { + let e = { + let l55 = *ptr0 + .add(36 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l55 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + ErrorCode::HttpResponseTrailerSize(e68) + } + 31 => { + let e68 = { + let l56 = i32::from(*ptr0.add(32).cast::()); + match l56 { + 0 => None, + 1 => { + let e = { + let l57 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l58 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len59 = l58; + let bytes59 = _rt::Vec::from_raw_parts( + l57.cast(), + len59, + len59, + ); + _rt::string_lift(bytes59) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseTransferCoding(e68) + } + 32 => { + let e68 = { + let l60 = i32::from(*ptr0.add(32).cast::()); + match l60 { + 0 => None, + 1 => { + let e = { + let l61 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l62 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len63 = l62; + let bytes63 = _rt::Vec::from_raw_parts( + l61.cast(), + len63, + len63, + ); + _rt::string_lift(bytes63) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::HttpResponseContentCoding(e68) + } + 33 => ErrorCode::HttpResponseTimeout, + 34 => ErrorCode::HttpUpgradeFailed, + 35 => ErrorCode::HttpProtocolError, + 36 => ErrorCode::LoopDetected, + 37 => ErrorCode::ConfigurationError, + n => { + debug_assert_eq!(n, 38, "invalid enum discriminant"); + let e68 = { + let l64 = i32::from(*ptr0.add(32).cast::()); + match l64 { + 0 => None, + 1 => { + let e = { + let l65 = *ptr0 + .add(32 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l66 = *ptr0 + .add(32 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len67 = l66; + let bytes67 = _rt::Vec::from_raw_parts( + l65.cast(), + len67, + len67, + ); + _rt::string_lift(bytes67) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + ErrorCode::InternalError(e68) + } + }; + v68 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + Ok(e) + } + 1 => { + let e = (); + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result69 + } + } + } + } + /// This interface defines a handler of outgoing HTTP Requests. It should be + /// imported by components which wish to make HTTP Requests. + #[allow(dead_code, async_fn_in_trait, unused_imports, clippy::all)] + pub mod outgoing_handler { + #[used] + #[doc(hidden)] + static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports; + use super::super::super::_rt; + pub type OutgoingRequest = super::super::super::wasi::http::types::OutgoingRequest; + pub type RequestOptions = super::super::super::wasi::http::types::RequestOptions; + pub type FutureIncomingResponse = super::super::super::wasi::http::types::FutureIncomingResponse; + pub type ErrorCode = super::super::super::wasi::http::types::ErrorCode; + #[allow(unused_unsafe, clippy::all)] + /// This function is invoked with an outgoing HTTP Request, and it returns + /// a resource `future-incoming-response` which represents an HTTP Response + /// which may arrive in the future. + /// + /// The `options` argument accepts optional parameters for the HTTP + /// protocol's transport layer. + /// + /// This function may return an error if the `outgoing-request` is invalid + /// or not allowed to be made. Otherwise, protocol errors are reported + /// through the `future-incoming-response`. + #[allow(async_fn_in_trait)] + pub fn handle( + request: OutgoingRequest, + options: Option, + ) -> Result { + unsafe { + #[repr(align(8))] + struct RetArea( + [::core::mem::MaybeUninit< + u8, + >; 24 + 4 * ::core::mem::size_of::<*const u8>()], + ); + let mut ret_area = RetArea( + [::core::mem::MaybeUninit::uninit(); 24 + + 4 * ::core::mem::size_of::<*const u8>()], + ); + let (result0_0, result0_1) = match &options { + Some(e) => (1i32, (e).take_handle() as i32), + None => (0i32, 0i32), + }; + let ptr1 = ret_area.0.as_mut_ptr().cast::(); + #[cfg(target_arch = "wasm32")] + #[link(wasm_import_module = "wasi:http/outgoing-handler@0.2.4")] + unsafe extern "C" { + #[link_name = "handle"] + fn wit_import2(_: i32, _: i32, _: i32, _: *mut u8); + } + #[cfg(not(target_arch = "wasm32"))] + unsafe extern "C" fn wit_import2( + _: i32, + _: i32, + _: i32, + _: *mut u8, + ) { + unreachable!() + } + wit_import2( + (&request).take_handle() as i32, + result0_0, + result0_1, + ptr1, + ); + let l3 = i32::from(*ptr1.add(0).cast::()); + let result68 = match l3 { + 0 => { + let e = { + let l4 = *ptr1.add(8).cast::(); + super::super::super::wasi::http::types::FutureIncomingResponse::from_handle( + l4 as u32, + ) + }; + Ok(e) + } + 1 => { + let e = { + let l5 = i32::from(*ptr1.add(8).cast::()); + use super::super::super::wasi::http::types::ErrorCode as V67; + let v67 = match l5 { + 0 => V67::DnsTimeout, + 1 => { + let e67 = { + let l6 = i32::from(*ptr1.add(16).cast::()); + let l10 = i32::from( + *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + super::super::super::wasi::http::types::DnsErrorPayload { + rcode: match l6 { + 0 => None, + 1 => { + let e = { + let l7 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l8 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len9 = l8; + let bytes9 = _rt::Vec::from_raw_parts( + l7.cast(), + len9, + len9, + ); + _rt::string_lift(bytes9) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + info_code: match l10 { + 0 => None, + 1 => { + let e = { + let l11 = i32::from( + *ptr1 + .add(18 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + l11 as u16 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + V67::DnsError(e67) + } + 2 => V67::DestinationNotFound, + 3 => V67::DestinationUnavailable, + 4 => V67::DestinationIpProhibited, + 5 => V67::DestinationIpUnroutable, + 6 => V67::ConnectionRefused, + 7 => V67::ConnectionTerminated, + 8 => V67::ConnectionTimeout, + 9 => V67::ConnectionReadTimeout, + 10 => V67::ConnectionWriteTimeout, + 11 => V67::ConnectionLimitReached, + 12 => V67::TlsProtocolError, + 13 => V67::TlsCertificateError, + 14 => { + let e67 = { + let l12 = i32::from(*ptr1.add(16).cast::()); + let l14 = i32::from( + *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + super::super::super::wasi::http::types::TlsAlertReceivedPayload { + alert_id: match l12 { + 0 => None, + 1 => { + let e = { + let l13 = i32::from(*ptr1.add(17).cast::()); + l13 as u8 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + alert_message: match l14 { + 0 => None, + 1 => { + let e = { + let l15 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l16 = *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len17 = l16; + let bytes17 = _rt::Vec::from_raw_parts( + l15.cast(), + len17, + len17, + ); + _rt::string_lift(bytes17) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + V67::TlsAlertReceived(e67) + } + 15 => V67::HttpRequestDenied, + 16 => V67::HttpRequestLengthRequired, + 17 => { + let e67 = { + let l18 = i32::from(*ptr1.add(16).cast::()); + match l18 { + 0 => None, + 1 => { + let e = { + let l19 = *ptr1.add(24).cast::(); + l19 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V67::HttpRequestBodySize(e67) + } + 18 => V67::HttpRequestMethodInvalid, + 19 => V67::HttpRequestUriInvalid, + 20 => V67::HttpRequestUriTooLong, + 21 => { + let e67 = { + let l20 = i32::from(*ptr1.add(16).cast::()); + match l20 { + 0 => None, + 1 => { + let e = { + let l21 = *ptr1.add(20).cast::(); + l21 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V67::HttpRequestHeaderSectionSize(e67) + } + 22 => { + let e67 = { + let l22 = i32::from(*ptr1.add(16).cast::()); + match l22 { + 0 => None, + 1 => { + let e = { + let l23 = i32::from( + *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + let l27 = i32::from( + *ptr1 + .add(16 + 4 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + super::super::super::wasi::http::types::FieldSizePayload { + field_name: match l23 { + 0 => None, + 1 => { + let e = { + let l24 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l25 = *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len26 = l25; + let bytes26 = _rt::Vec::from_raw_parts( + l24.cast(), + len26, + len26, + ); + _rt::string_lift(bytes26) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l27 { + 0 => None, + 1 => { + let e = { + let l28 = *ptr1 + .add(20 + 4 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l28 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V67::HttpRequestHeaderSize(e67) + } + 23 => { + let e67 = { + let l29 = i32::from(*ptr1.add(16).cast::()); + match l29 { + 0 => None, + 1 => { + let e = { + let l30 = *ptr1.add(20).cast::(); + l30 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V67::HttpRequestTrailerSectionSize(e67) + } + 24 => { + let e67 = { + let l31 = i32::from(*ptr1.add(16).cast::()); + let l35 = i32::from( + *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + super::super::super::wasi::http::types::FieldSizePayload { + field_name: match l31 { + 0 => None, + 1 => { + let e = { + let l32 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l33 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len34 = l33; + let bytes34 = _rt::Vec::from_raw_parts( + l32.cast(), + len34, + len34, + ); + _rt::string_lift(bytes34) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l35 { + 0 => None, + 1 => { + let e = { + let l36 = *ptr1 + .add(20 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l36 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + V67::HttpRequestTrailerSize(e67) + } + 25 => V67::HttpResponseIncomplete, + 26 => { + let e67 = { + let l37 = i32::from(*ptr1.add(16).cast::()); + match l37 { + 0 => None, + 1 => { + let e = { + let l38 = *ptr1.add(20).cast::(); + l38 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V67::HttpResponseHeaderSectionSize(e67) + } + 27 => { + let e67 = { + let l39 = i32::from(*ptr1.add(16).cast::()); + let l43 = i32::from( + *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + super::super::super::wasi::http::types::FieldSizePayload { + field_name: match l39 { + 0 => None, + 1 => { + let e = { + let l40 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l41 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len42 = l41; + let bytes42 = _rt::Vec::from_raw_parts( + l40.cast(), + len42, + len42, + ); + _rt::string_lift(bytes42) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l43 { + 0 => None, + 1 => { + let e = { + let l44 = *ptr1 + .add(20 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l44 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + V67::HttpResponseHeaderSize(e67) + } + 28 => { + let e67 = { + let l45 = i32::from(*ptr1.add(16).cast::()); + match l45 { + 0 => None, + 1 => { + let e = { + let l46 = *ptr1.add(24).cast::(); + l46 as u64 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V67::HttpResponseBodySize(e67) + } + 29 => { + let e67 = { + let l47 = i32::from(*ptr1.add(16).cast::()); + match l47 { + 0 => None, + 1 => { + let e = { + let l48 = *ptr1.add(20).cast::(); + l48 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V67::HttpResponseTrailerSectionSize(e67) + } + 30 => { + let e67 = { + let l49 = i32::from(*ptr1.add(16).cast::()); + let l53 = i32::from( + *ptr1 + .add(16 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(), + ); + super::super::super::wasi::http::types::FieldSizePayload { + field_name: match l49 { + 0 => None, + 1 => { + let e = { + let l50 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l51 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len52 = l51; + let bytes52 = _rt::Vec::from_raw_parts( + l50.cast(), + len52, + len52, + ); + _rt::string_lift(bytes52) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + field_size: match l53 { + 0 => None, + 1 => { + let e = { + let l54 = *ptr1 + .add(20 + 3 * ::core::mem::size_of::<*const u8>()) + .cast::(); + l54 as u32 + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + }, + } + }; + V67::HttpResponseTrailerSize(e67) + } + 31 => { + let e67 = { + let l55 = i32::from(*ptr1.add(16).cast::()); + match l55 { + 0 => None, + 1 => { + let e = { + let l56 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l57 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len58 = l57; + let bytes58 = _rt::Vec::from_raw_parts( + l56.cast(), + len58, + len58, + ); + _rt::string_lift(bytes58) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V67::HttpResponseTransferCoding(e67) + } + 32 => { + let e67 = { + let l59 = i32::from(*ptr1.add(16).cast::()); + match l59 { + 0 => None, + 1 => { + let e = { + let l60 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l61 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len62 = l61; + let bytes62 = _rt::Vec::from_raw_parts( + l60.cast(), + len62, + len62, + ); + _rt::string_lift(bytes62) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V67::HttpResponseContentCoding(e67) + } + 33 => V67::HttpResponseTimeout, + 34 => V67::HttpUpgradeFailed, + 35 => V67::HttpProtocolError, + 36 => V67::LoopDetected, + 37 => V67::ConfigurationError, + n => { + debug_assert_eq!(n, 38, "invalid enum discriminant"); + let e67 = { + let l63 = i32::from(*ptr1.add(16).cast::()); + match l63 { + 0 => None, + 1 => { + let e = { + let l64 = *ptr1 + .add(16 + 1 * ::core::mem::size_of::<*const u8>()) + .cast::<*mut u8>(); + let l65 = *ptr1 + .add(16 + 2 * ::core::mem::size_of::<*const u8>()) + .cast::(); + let len66 = l65; + let bytes66 = _rt::Vec::from_raw_parts( + l64.cast(), + len66, + len66, + ); + _rt::string_lift(bytes66) + }; + Some(e) + } + _ => _rt::invalid_enum_discriminant(), + } + }; + V67::InternalError(e67) + } + }; + v67 + }; + Err(e) + } + _ => _rt::invalid_enum_discriminant(), + }; + result68 + } + } + } + } +} #[rustfmt::skip] #[allow(dead_code, clippy::all)] pub mod exports { @@ -40,8 +6850,8 @@ pub mod exports { #[doc(hidden)] static __FORCE_SECTION_REF: fn() = super::super::super::super::__link_custom_section_describing_imports; use super::super::super::super::_rt; - pub type IncomingRequest = super::super::super::super::__with_name9::IncomingRequest; - pub type ResponseOutparam = super::super::super::super::__with_name9::ResponseOutparam; + pub type IncomingRequest = super::super::super::super::wasi::http::types::IncomingRequest; + pub type ResponseOutparam = super::super::super::super::wasi::http::types::ResponseOutparam; #[doc(hidden)] #[allow(non_snake_case, unused_unsafe)] pub unsafe fn _export_handle_cabi(arg0: i32, arg1: i32) { @@ -49,10 +6859,10 @@ pub mod exports { #[cfg(target_arch = "wasm32")] _rt::run_ctors_once(); { T::handle( - super::super::super::super::__with_name9::IncomingRequest::from_handle( + super::super::super::super::wasi::http::types::IncomingRequest::from_handle( arg0 as u32, ), - super::super::super::super::__with_name9::ResponseOutparam::from_handle( + super::super::super::super::wasi::http::types::ResponseOutparam::from_handle( arg1 as u32, ), ) @@ -96,10 +6906,204 @@ pub mod exports { #[rustfmt::skip] mod _rt { #![allow(dead_code, clippy::all)] + pub use alloc_crate::string::String; + pub use alloc_crate::vec::Vec; + use core::fmt; + use core::marker; + use core::sync::atomic::{AtomicU32, Ordering::Relaxed}; + /// A type which represents a component model resource, either imported or + /// exported into this component. + /// + /// This is a low-level wrapper which handles the lifetime of the resource + /// (namely this has a destructor). The `T` provided defines the component model + /// intrinsics that this wrapper uses. + /// + /// One of the chief purposes of this type is to provide `Deref` implementations + /// to access the underlying data when it is owned. + /// + /// This type is primarily used in generated code for exported and imported + /// resources. + #[repr(transparent)] + pub struct Resource { + handle: AtomicU32, + _marker: marker::PhantomData, + } + /// A trait which all wasm resources implement, namely providing the ability to + /// drop a resource. + /// + /// This generally is implemented by generated code, not user-facing code. + #[allow(clippy::missing_safety_doc)] + pub unsafe trait WasmResource { + /// Invokes the `[resource-drop]...` intrinsic. + unsafe fn drop(handle: u32); + } + impl Resource { + #[doc(hidden)] + pub unsafe fn from_handle(handle: u32) -> Self { + debug_assert!(handle != 0 && handle != u32::MAX); + Self { + handle: AtomicU32::new(handle), + _marker: marker::PhantomData, + } + } + /// Takes ownership of the handle owned by `resource`. + /// + /// Note that this ideally would be `into_handle` taking `Resource` by + /// ownership. The code generator does not enable that in all situations, + /// unfortunately, so this is provided instead. + /// + /// Also note that `take_handle` is in theory only ever called on values + /// owned by a generated function. For example a generated function might + /// take `Resource` as an argument but then call `take_handle` on a + /// reference to that argument. In that sense the dynamic nature of + /// `take_handle` should only be exposed internally to generated code, not + /// to user code. + #[doc(hidden)] + pub fn take_handle(resource: &Resource) -> u32 { + resource.handle.swap(u32::MAX, Relaxed) + } + #[doc(hidden)] + pub fn handle(resource: &Resource) -> u32 { + resource.handle.load(Relaxed) + } + } + impl fmt::Debug for Resource { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Resource").field("handle", &self.handle).finish() + } + } + impl Drop for Resource { + fn drop(&mut self) { + unsafe { + match self.handle.load(Relaxed) { + u32::MAX => {} + other => T::drop(other), + } + } + } + } + pub unsafe fn string_lift(bytes: Vec) -> String { + if cfg!(debug_assertions) { + String::from_utf8(bytes).unwrap() + } else { + unsafe { String::from_utf8_unchecked(bytes) } + } + } + pub unsafe fn invalid_enum_discriminant() -> T { + if cfg!(debug_assertions) { + panic!("invalid enum discriminant") + } else { + unsafe { core::hint::unreachable_unchecked() } + } + } + pub use alloc_crate::alloc; + pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) { + if size == 0 { + return; + } + unsafe { + let layout = alloc::Layout::from_size_align_unchecked(size, align); + alloc::dealloc(ptr, layout); + } + } + pub unsafe fn bool_lift(val: u8) -> bool { + if cfg!(debug_assertions) { + match val { + 0 => false, + 1 => true, + _ => panic!("invalid bool discriminant"), + } + } else { + val != 0 + } + } + pub fn as_i64(t: T) -> i64 { + t.as_i64() + } + pub trait AsI64 { + fn as_i64(self) -> i64; + } + impl<'a, T: Copy + AsI64> AsI64 for &'a T { + fn as_i64(self) -> i64 { + (*self).as_i64() + } + } + impl AsI64 for i64 { + #[inline] + fn as_i64(self) -> i64 { + self as i64 + } + } + impl AsI64 for u64 { + #[inline] + fn as_i64(self) -> i64 { + self as i64 + } + } + pub fn as_i32(t: T) -> i32 { + t.as_i32() + } + pub trait AsI32 { + fn as_i32(self) -> i32; + } + impl<'a, T: Copy + AsI32> AsI32 for &'a T { + fn as_i32(self) -> i32 { + (*self).as_i32() + } + } + impl AsI32 for i32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u32 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for i16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u16 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for i8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for u8 { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for char { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } + impl AsI32 for usize { + #[inline] + fn as_i32(self) -> i32 { + self as i32 + } + } #[cfg(target_arch = "wasm32")] pub fn run_ctors_once() { wit_bindgen::rt::run_ctors_once(); } + extern crate alloc as alloc_crate; } /// Generates `#[unsafe(no_mangle)]` functions to export the specified type as /// the root implementation of all generated traits. diff --git a/wit/wasi-crate.wit b/wit/wasi-crate.wit index 1b1118c..7ff44fe 100644 --- a/wit/wasi-crate.wit +++ b/wit/wasi-crate.wit @@ -1,6 +1 @@ package rust:wasi; - -world bindings { - include wasi:cli/imports@0.2.4; - import wasi:http/outgoing-handler@0.2.4; -}