diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets
index db8aee3799b44..514b61cc1b91a 100644
--- a/eng/liveBuilds.targets
+++ b/eng/liveBuilds.targets
@@ -244,6 +244,7 @@
diff --git a/eng/testing/linker/SupportFiles/Directory.Build.targets b/eng/testing/linker/SupportFiles/Directory.Build.targets
index 6a43ace84f6f5..1ba8ed737f4df 100644
--- a/eng/testing/linker/SupportFiles/Directory.Build.targets
+++ b/eng/testing/linker/SupportFiles/Directory.Build.targets
@@ -10,7 +10,7 @@
+ Condition="'$(TargetOS)' == 'browser' or '$(TargetOS)' == 'wasi'" />
<_IlcReferencedAsPackage>false
diff --git a/eng/testing/tests.wasi.targets b/eng/testing/tests.wasi.targets
index 47d68ce7abe6f..e316863525fdc 100644
--- a/eng/testing/tests.wasi.targets
+++ b/eng/testing/tests.wasi.targets
@@ -47,7 +47,9 @@
<_XHarnessArgs Condition="'$(IsFunctionalTest)' == 'true'" >$(_XHarnessArgs) --expected-exit-code=$(ExpectedExitCode)
<_XHarnessArgs Condition="'$(WasmXHarnessArgs)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgs)
<_XHarnessArgs Condition="'$(WasmXHarnessTestsTimeout)' != ''" >$(_XHarnessArgs) "--timeout=$(WasmXHarnessTestsTimeout)"
- <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=-W --engine-arg=max-wasm-stack=134217728
+ <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasm --engine-arg=max-wasm-stack=134217728
+ <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--wasi --engine-arg=http
+ <_XHarnessArgs >$(_XHarnessArgs) --engine-arg=--env --engine-arg=DOTNET_WASI_PRINT_EXIT_CODE=1
<_XHarnessArgs Condition="'$(WasmXHarnessArgsCli)' != ''" >$(_XHarnessArgs) $(WasmXHarnessArgsCli)
<_InvariantGlobalization Condition="'$(InvariantGlobalization)' == 'true'">--env=DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=true
diff --git a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
index 69fbf0e5d44db..c38417c2af449 100644
--- a/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
+++ b/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props
@@ -270,6 +270,7 @@
+
diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/LocalEchoServer.props b/src/libraries/Common/tests/System/Net/Prerequisites/LocalEchoServer.props
index 53fe2308aa545..fe97a98899d19 100644
--- a/src/libraries/Common/tests/System/Net/Prerequisites/LocalEchoServer.props
+++ b/src/libraries/Common/tests/System/Net/Prerequisites/LocalEchoServer.props
@@ -1,5 +1,5 @@
-
+
<_TargetFrameworkForXHarness>$(AspNetCoreAppCurrent)
$(MSBuildThisFileDirectory)LocalEchoServer.helix.targets
@@ -19,7 +19,7 @@
$(WasmXHarnessArgs) --web-server-middleware=$(_TestEchoMiddleware)/NetCoreServer.dll,NetCoreServer.GenericHandler
-
+
diff --git a/src/libraries/System.Net.Http/src/System.Net.Http.csproj b/src/libraries/System.Net.Http/src/System.Net.Http.csproj
index 5a824c7c5aa7c..5c5f3a96bc579 100644
--- a/src/libraries/System.Net.Http/src/System.Net.Http.csproj
+++ b/src/libraries/System.Net.Http/src/System.Net.Http.csproj
@@ -455,6 +455,22 @@
Link="Common\System\Net\Http\HttpHandlerDefaults.cs" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs
index 5a34491ab4c9f..afba32455bc2f 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs
@@ -10,7 +10,11 @@
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics.Metrics;
-#if TARGET_BROWSER
+#if TARGET_WASI
+using System.Diagnostics;
+using System.Net.Http.Metrics;
+using HttpHandlerType = System.Net.Http.WasiHttpHandler;
+#elif TARGET_BROWSER
using System.Diagnostics;
using System.Net.Http.Metrics;
using HttpHandlerType = System.Net.Http.BrowserHttpHandler;
@@ -24,7 +28,7 @@ public partial class HttpClientHandler : HttpMessageHandler
{
private readonly HttpHandlerType _underlyingHandler;
-#if TARGET_BROWSER
+#if TARGET_BROWSER || TARGET_WASI
private IMeterFactory? _meterFactory;
private HttpMessageHandler? _firstHandler; // DiagnosticsHandler or MetricsHandler, depending on global configuration.
@@ -94,7 +98,7 @@ protected override void Dispose(bool disposing)
[CLSCompliant(false)]
public IMeterFactory? MeterFactory
{
-#if TARGET_BROWSER
+#if TARGET_BROWSER || TARGET_WASI
get => _meterFactory;
set
{
@@ -262,14 +266,14 @@ public ClientCertificateOption ClientCertificateOptions
switch (value)
{
case ClientCertificateOption.Manual:
-#if !TARGET_BROWSER
+#if !(TARGET_BROWSER || TARGET_WASI)
ThrowForModifiedManagedSslOptionsIfStarted();
_underlyingHandler.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate(_underlyingHandler.SslOptions.ClientCertificates)!;
#endif
break;
case ClientCertificateOption.Automatic:
-#if !TARGET_BROWSER
+#if !(TARGET_BROWSER || TARGET_WASI)
ThrowForModifiedManagedSslOptionsIfStarted();
_underlyingHandler.SslOptions.LocalCertificateSelectionCallback = (sender, targetHost, localCertificates, remoteCertificate, acceptableIssuers) => CertificateHelper.GetEligibleClientCertificate()!;
#endif
@@ -300,7 +304,7 @@ public X509CertificateCollection ClientCertificates
[UnsupportedOSPlatform("browser")]
public Func? ServerCertificateCustomValidationCallback
{
-#if TARGET_BROWSER
+#if TARGET_BROWSER || TARGET_WASI
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
#else
@@ -349,7 +353,7 @@ public SslProtocols SslProtocols
//[UnsupportedOSPlatform("tvos")]
protected internal override HttpResponseMessage Send(HttpRequestMessage request, CancellationToken cancellationToken)
{
-#if TARGET_BROWSER
+#if TARGET_BROWSER || TARGET_WASI
throw new PlatformNotSupportedException();
#else
ArgumentNullException.ThrowIfNull(request);
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttp.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttp.cs
new file mode 100644
index 0000000000000..0ad976a3bb7be
--- /dev/null
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttp.cs
@@ -0,0 +1,121 @@
+// Generated by `wit-bindgen` 0.27.0. DO NOT EDIT!
+//
+#nullable enable
+using System;
+using System.Runtime.CompilerServices;
+using System.Collections;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
+
+namespace WasiHttpWorld {
+
+ internal interface IWasiHttpWorld {
+ }
+
+ internal readonly struct None {}
+
+ [StructLayout(LayoutKind.Sequential)]
+ internal readonly struct Result
+ {
+ internal readonly byte Tag;
+ private readonly object value;
+
+ private Result(byte tag, object value)
+ {
+ Tag = tag;
+ this.value = value;
+ }
+
+ internal static Result ok(Ok ok)
+ {
+ return new Result(OK, ok!);
+ }
+
+ internal static Result err(Err err)
+ {
+ return new Result(ERR, err!);
+ }
+
+ internal bool IsOk => Tag == OK;
+ internal bool IsErr => Tag == ERR;
+
+ internal Ok AsOk
+ {
+ get
+ {
+ if (Tag == OK)
+ return (Ok)value;
+ else
+ throw new ArgumentException("expected OK, got " + Tag);
+ }
+ }
+
+ internal Err AsErr
+ {
+ get
+ {
+ if (Tag == ERR)
+ return (Err)value;
+ else
+ throw new ArgumentException("expected ERR, got " + Tag);
+ }
+ }
+
+ internal const byte OK = 0;
+ internal const byte ERR = 1;
+ }
+
+ internal class Option {
+ private static Option none = new ();
+
+ private Option()
+ {
+ HasValue = false;
+ }
+
+ internal Option(T v)
+ {
+ HasValue = true;
+ Value = v;
+ }
+
+ internal static Option None => none;
+
+ [MemberNotNullWhen(true, nameof(Value))]
+ internal bool HasValue { get; }
+
+ internal T? Value { get; }
+ }
+
+ internal static class InteropString
+ {
+ internal static IntPtr FromString(string input, out int length)
+ {
+ var utf8Bytes = Encoding.UTF8.GetBytes(input);
+ length = utf8Bytes.Length;
+ var gcHandle = GCHandle.Alloc(utf8Bytes, GCHandleType.Pinned);
+ return gcHandle.AddrOfPinnedObject();
+ }
+ }
+
+ internal class WitException: Exception {
+ internal object Value { get; }
+ internal uint NestingLevel { get; }
+
+ internal WitException(object v, uint level)
+ {
+ Value = v;
+ NestingLevel = level;
+ }
+ }
+
+ namespace exports {
+ internal static class WasiHttpWorld
+ {
+ }
+ }
+
+}
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs
new file mode 100644
index 0000000000000..ea6d9e600dadb
--- /dev/null
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpHandler.cs
@@ -0,0 +1,747 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Net.Http.Headers;
+using System.Net.Security;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using WasiHttpWorld;
+using WasiHttpWorld.wit.imports.wasi.http.v0_2_0;
+using WasiHttpWorld.wit.imports.wasi.io.v0_2_0;
+
+namespace System.Net.Http
+{
+ internal sealed class WasiHttpHandler : HttpMessageHandler
+ {
+ #region PlatformNotSupported
+#pragma warning disable CA1822
+ public bool UseCookies
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public CookieContainer CookieContainer
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public DecompressionMethods AutomaticDecompression
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public bool UseProxy
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public IWebProxy? Proxy
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public ICredentials? DefaultProxyCredentials
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public bool PreAuthenticate
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public ICredentials? Credentials
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public int MaxAutomaticRedirections
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public int MaxConnectionsPerServer
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public int MaxResponseHeadersLength
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public SslClientAuthenticationOptions SslOptions
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+
+ public bool AllowAutoRedirect
+ {
+ get => throw new PlatformNotSupportedException();
+ set => throw new PlatformNotSupportedException();
+ }
+#pragma warning restore CA1822
+ #endregion
+
+ internal ClientCertificateOption ClientCertificateOptions;
+
+ public const bool SupportsAutomaticDecompression = false;
+ public const bool SupportsProxy = false;
+ public const bool SupportsRedirectConfiguration = false;
+
+ private Dictionary? _properties;
+ public IDictionary Properties =>
+ _properties ??= new Dictionary();
+
+ protected internal override HttpResponseMessage Send(
+ HttpRequestMessage request,
+ CancellationToken cancellationToken
+ )
+ {
+ throw new PlatformNotSupportedException();
+ }
+
+ protected internal override async Task SendAsync(
+ HttpRequestMessage request,
+ CancellationToken cancellationToken
+ )
+ {
+ if (request.RequestUri is null)
+ {
+ throw new ArgumentException();
+ }
+
+ var requestMethod = request.Method.ToString();
+ var uri = request.RequestUri;
+
+ ITypes.Method method;
+ switch (requestMethod)
+ {
+ case "":
+ case "GET":
+ method = ITypes.Method.get();
+ break;
+ case "HEAD":
+ method = ITypes.Method.head();
+ break;
+ case "POST":
+ method = ITypes.Method.post();
+ break;
+ case "PUT":
+ method = ITypes.Method.put();
+ break;
+ case "DELETE":
+ method = ITypes.Method.delete();
+ break;
+ case "CONNECT":
+ method = ITypes.Method.connect();
+ break;
+ case "OPTIONS":
+ method = ITypes.Method.options();
+ break;
+ case "TRACE":
+ method = ITypes.Method.trace();
+ break;
+ case "PATCH":
+ method = ITypes.Method.patch();
+ break;
+ default:
+ method = ITypes.Method.other(requestMethod);
+ break;
+ }
+
+ ITypes.Scheme scheme;
+ switch (uri.Scheme)
+ {
+ case "":
+ case "http":
+ scheme = ITypes.Scheme.http();
+ break;
+ case "https":
+ scheme = ITypes.Scheme.https();
+ break;
+ default:
+ scheme = ITypes.Scheme.other(uri.Scheme);
+ break;
+ }
+
+ string authority;
+ if (uri.Authority.Length == 0)
+ {
+ // `wasi:http/outgoing-handler` requires a non-empty authority,
+ // so we set one here:
+ if (scheme.Tag == ITypes.Scheme.HTTPS)
+ {
+ authority = ":443";
+ }
+ else
+ {
+ authority = ":80";
+ }
+ }
+ else
+ {
+ authority = uri.Authority;
+ }
+
+ var headers = new List<(string, byte[])>();
+ foreach (var pair in request.Headers)
+ {
+ foreach (var value in pair.Value)
+ {
+ headers.Add((pair.Key, Encoding.UTF8.GetBytes(value)));
+ }
+ }
+ if (request.Content is not null)
+ {
+ foreach (var pair in request.Content.Headers)
+ {
+ foreach (var value in pair.Value)
+ {
+ headers.Add((pair.Key, Encoding.UTF8.GetBytes(value)));
+ }
+ }
+ }
+
+ var outgoingRequest = new ITypes.OutgoingRequest(ITypes.Fields.FromList(headers));
+ outgoingRequest.SetMethod(method);
+ outgoingRequest.SetScheme(scheme);
+ outgoingRequest.SetAuthority(authority);
+ outgoingRequest.SetPathWithQuery(uri.PathAndQuery);
+
+ var outgoingStream = new OutputStream(outgoingRequest.Body());
+
+ Func> sendContent = async () =>
+ {
+ await SendContentAsync(request.Content, outgoingStream).ConfigureAwait(false);
+ return null;
+ };
+
+ // Concurrently send the request and the content stream, allowing
+ // the server to start sending a response before it's received the
+ // entire request body.
+ var incomingResponse = (
+ await Task.WhenAll(
+ new Task[]
+ {
+ SendRequestAsync(outgoingRequest),
+ sendContent()
+ }
+ )
+ .ConfigureAwait(false)
+ )[0];
+
+ if (incomingResponse is null)
+ {
+ // Shouldn't be possible, since `SendRequestAsync` always
+ // returns a non-null value.
+ throw new Exception("unreachable code");
+ }
+
+ var response = new HttpResponseMessage((HttpStatusCode)incomingResponse.Status());
+ var responseHeaders = incomingResponse.Headers().Entries();
+ response.Content = new StreamContent(new InputStream(incomingResponse.Consume()));
+ foreach ((var key, var value) in responseHeaders)
+ {
+ var valueString = Encoding.UTF8.GetString(value);
+ if (
+ HeaderDescriptor.TryGet(key, out HeaderDescriptor descriptor)
+ && (descriptor.HeaderType & HttpHeaderType.Content) != 0
+ )
+ {
+ response.Content.Headers.Add(key, valueString);
+ }
+ else
+ {
+ response.Headers.Add(key, valueString);
+ }
+ }
+
+ return response;
+ }
+
+ private static async Task SendRequestAsync(
+ ITypes.OutgoingRequest request
+ )
+ {
+ ITypes.FutureIncomingResponse future;
+ try
+ {
+ future = OutgoingHandlerInterop.Handle(request, null);
+ }
+ catch (WasiHttpWorld.WitException e)
+ {
+ var message = ErrorCodeToString((ITypes.ErrorCode)e.Value);
+ throw new Exception($"Request Error: {message}");
+ }
+
+ while (true)
+ {
+ var response = future.Get();
+ if (response is not null)
+ {
+ var result = (
+ (Result, None>)response
+ ).AsOk;
+
+ if (result.IsOk)
+ {
+ return result.AsOk;
+ }
+ else
+ {
+ var message = ErrorCodeToString(result.AsErr);
+ throw new Exception($"Request Error: {message}");
+ }
+ }
+ else
+ {
+ await WasiEventLoop.RegisterWasiPollable(future.Subscribe()).ConfigureAwait(false);
+ }
+ }
+ }
+
+ private static string ErrorCodeToString(ITypes.ErrorCode code)
+ {
+ // TODO: include payload data in result where applicable
+ switch (code.Tag)
+ {
+ case ITypes.ErrorCode.DNS_TIMEOUT:
+ return "DNS_TIMEOUT";
+
+ case ITypes.ErrorCode.DNS_ERROR:
+ return "DNS_ERROR";
+
+ case ITypes.ErrorCode.DESTINATION_NOT_FOUND:
+ return "DESTINATION_NOT_FOUND";
+
+ case ITypes.ErrorCode.DESTINATION_UNAVAILABLE:
+ return "DESTINATION_UNAVAILABLE";
+
+ case ITypes.ErrorCode.DESTINATION_IP_PROHIBITED:
+ return "DESTINATION_IP_PROHIBITED";
+
+ case ITypes.ErrorCode.DESTINATION_IP_UNROUTABLE:
+ return "DESTINATION_IP_UNROUTABLE";
+
+ case ITypes.ErrorCode.CONNECTION_REFUSED:
+ return "CONNECTION_REFUSED";
+
+ case ITypes.ErrorCode.CONNECTION_TERMINATED:
+ return "CONNECTION_TERMINATED";
+
+ case ITypes.ErrorCode.CONNECTION_TIMEOUT:
+ return "CONNECTION_TIMEOUT";
+
+ case ITypes.ErrorCode.CONNECTION_READ_TIMEOUT:
+ return "CONNECTION_READ_TIMEOUT";
+
+ case ITypes.ErrorCode.CONNECTION_WRITE_TIMEOUT:
+ return "CONNECTION_WRITE_TIMEOUT";
+
+ case ITypes.ErrorCode.CONNECTION_LIMIT_REACHED:
+ return "CONNECTION_LIMIT_REACHED";
+
+ case ITypes.ErrorCode.TLS_PROTOCOL_ERROR:
+ return "TLS_PROTOCOL_ERROR";
+
+ case ITypes.ErrorCode.TLS_CERTIFICATE_ERROR:
+ return "TLS_CERTIFICATE_ERROR";
+
+ case ITypes.ErrorCode.TLS_ALERT_RECEIVED:
+ return "TLS_ALERT_RECEIVED";
+
+ case ITypes.ErrorCode.HTTP_REQUEST_DENIED:
+ return "HTTP_REQUEST_DENIED";
+
+ case ITypes.ErrorCode.HTTP_REQUEST_LENGTH_REQUIRED:
+ return "HTTP_REQUEST_LENGTH_REQUIRED";
+
+ case ITypes.ErrorCode.HTTP_REQUEST_BODY_SIZE:
+ return "HTTP_REQUEST_BODY_SIZE";
+
+ case ITypes.ErrorCode.HTTP_REQUEST_METHOD_INVALID:
+ return "HTTP_REQUEST_METHOD_INVALID";
+
+ case ITypes.ErrorCode.HTTP_REQUEST_URI_INVALID:
+ return "HTTP_REQUEST_URI_INVALID";
+
+ case ITypes.ErrorCode.HTTP_REQUEST_URI_TOO_LONG:
+ return "HTTP_REQUEST_URI_TOO_LONG";
+
+ case ITypes.ErrorCode.HTTP_REQUEST_HEADER_SECTION_SIZE:
+ return "HTTP_REQUEST_HEADER_SECTION_SIZE";
+
+ case ITypes.ErrorCode.HTTP_REQUEST_HEADER_SIZE:
+ return "HTTP_REQUEST_HEADER_SIZE";
+
+ case ITypes.ErrorCode.HTTP_REQUEST_TRAILER_SECTION_SIZE:
+ return "HTTP_REQUEST_TRAILER_SECTION_SIZE";
+
+ case ITypes.ErrorCode.HTTP_REQUEST_TRAILER_SIZE:
+ return "HTTP_REQUEST_TRAILER_SIZE";
+
+ case ITypes.ErrorCode.HTTP_RESPONSE_INCOMPLETE:
+ return "HTTP_RESPONSE_INCOMPLETE";
+
+ case ITypes.ErrorCode.HTTP_RESPONSE_HEADER_SECTION_SIZE:
+ return "HTTP_RESPONSE_HEADER_SECTION_SIZE";
+
+ case ITypes.ErrorCode.HTTP_RESPONSE_HEADER_SIZE:
+ return "HTTP_RESPONSE_HEADER_SIZE";
+
+ case ITypes.ErrorCode.HTTP_RESPONSE_BODY_SIZE:
+ return "HTTP_RESPONSE_BODY_SIZE";
+
+ case ITypes.ErrorCode.HTTP_RESPONSE_TRAILER_SECTION_SIZE:
+ return "HTTP_RESPONSE_TRAILER_SECTION_SIZE";
+
+ case ITypes.ErrorCode.HTTP_RESPONSE_TRAILER_SIZE:
+ return "HTTP_RESPONSE_TRAILER_SIZE";
+
+ case ITypes.ErrorCode.HTTP_RESPONSE_TRANSFER_CODING:
+ return "HTTP_RESPONSE_TRANSFER_CODING";
+
+ case ITypes.ErrorCode.HTTP_RESPONSE_CONTENT_CODING:
+ return "HTTP_RESPONSE_CONTENT_CODING";
+
+ case ITypes.ErrorCode.HTTP_RESPONSE_TIMEOUT:
+ return "HTTP_RESPONSE_TIMEOUT";
+
+ case ITypes.ErrorCode.HTTP_UPGRADE_FAILED:
+ return "HTTP_UPGRADE_FAILED";
+
+ case ITypes.ErrorCode.HTTP_PROTOCOL_ERROR:
+ return "HTTP_PROTOCOL_ERROR";
+
+ case ITypes.ErrorCode.LOOP_DETECTED:
+ return "LOOP_DETECTED";
+
+ case ITypes.ErrorCode.CONFIGURATION_ERROR:
+ return "CONFIGURATION_ERROR";
+
+ case ITypes.ErrorCode.INTERNAL_ERROR:
+ return "INTERNAL_ERROR";
+
+ default:
+ return $"{code.Tag}";
+ }
+ }
+
+ private static async Task SendContentAsync(HttpContent? content, Stream stream)
+ {
+ try
+ {
+ if (content is not null)
+ {
+ await content.CopyToAsync(stream).ConfigureAwait(false);
+ }
+ }
+ finally
+ {
+ stream.Dispose();
+ }
+ }
+
+ private static class WasiEventLoop
+ {
+ internal static Task RegisterWasiPollable(IPoll.Pollable pollable)
+ {
+ var handle = pollable.Handle;
+ pollable.Handle = 0;
+ return CallRegisterWasiPollable((Thread)null!, handle);
+
+ [UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "RegisterWasiPollable")]
+ static extern Task CallRegisterWasiPollable(Thread t, int handle);
+ }
+ }
+
+ private sealed class InputStream : Stream
+ {
+ private ITypes.IncomingBody body;
+ private IStreams.InputStream stream;
+ private int offset;
+ private byte[]? buffer;
+ private bool closed;
+
+ public InputStream(ITypes.IncomingBody body)
+ {
+ this.body = body;
+ this.stream = body.Stream();
+ }
+
+ ~InputStream()
+ {
+ Dispose(false);
+ }
+
+ public override bool CanRead => true;
+ public override bool CanWrite => false;
+ public override bool CanSeek => false;
+ public override long Length => throw new NotImplementedException();
+ public override long Position
+ {
+ get => throw new NotImplementedException();
+ set => throw new NotImplementedException();
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ stream.Dispose();
+ ITypes.IncomingBody.Finish(body);
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void Flush()
+ {
+ // ignore
+ }
+
+ public override void SetLength(long length)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int Read(byte[] buffer, int offset, int length)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void Write(byte[] buffer, int offset, int length)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override async Task ReadAsync(
+ byte[] bytes,
+ int offset,
+ int length,
+ CancellationToken cancellationToken
+ )
+ {
+ // TODO: handle `cancellationToken`
+ while (true)
+ {
+ if (closed)
+ {
+ return 0;
+ }
+ else if (this.buffer == null)
+ {
+ try
+ {
+ // TODO: should we add a special case to the bindings generator
+ // to allow passing a buffer to IStreams.InputStream.Read and
+ // avoid the extra copy?
+ var result = stream.Read(16 * 1024);
+ var buffer = result;
+ if (buffer.Length == 0)
+ {
+ await WasiEventLoop
+ .RegisterWasiPollable(stream.Subscribe())
+ .ConfigureAwait(false);
+ }
+ else
+ {
+ this.buffer = buffer;
+ this.offset = 0;
+ }
+ }
+ catch (WitException e)
+ {
+ if (((IStreams.StreamError)e.Value).Tag == IStreams.StreamError.CLOSED)
+ {
+ closed = true;
+ return 0;
+ }
+ else
+ {
+ throw e;
+ }
+ }
+ }
+ else
+ {
+ var min = Math.Min(this.buffer.Length - this.offset, length);
+ Array.Copy(this.buffer, this.offset, bytes, offset, min);
+ if (min < buffer.Length - this.offset)
+ {
+ this.offset += min;
+ }
+ else
+ {
+ this.buffer = null;
+ }
+ return min;
+ }
+ }
+ }
+
+ public override async ValueTask ReadAsync(
+ Memory buffer,
+ CancellationToken cancellationToken = default
+ )
+ {
+ // TODO: avoid copy when possible and use ArrayPool when not
+ var dst = new byte[buffer.Length];
+ // We disable "CA1835: Prefer the memory-based overloads of
+ // ReadAsync/WriteAsync methods in stream-based classes" for
+ // now, since `ReadyAsync(byte[], int, int, CancellationToken)`
+ // is where the implementation currently resides, but we should
+ // revisit this if/when `wit-bindgen` learns to generate
+ // memory-based bindings.
+#pragma warning disable CA1835
+ var result = await ReadAsync(dst, 0, buffer.Length, cancellationToken)
+ .ConfigureAwait(false);
+#pragma warning restore CA1835
+ new ReadOnlySpan(dst, 0, result).CopyTo(buffer.Span);
+ return result;
+ }
+ }
+
+ private sealed class OutputStream : Stream
+ {
+ private ITypes.OutgoingBody body;
+ private IStreams.OutputStream stream;
+
+ public OutputStream(ITypes.OutgoingBody body)
+ {
+ this.body = body;
+ this.stream = body.Write();
+ }
+
+ ~OutputStream()
+ {
+ Dispose(false);
+ }
+
+ public override bool CanRead => false;
+ public override bool CanWrite => true;
+ public override bool CanSeek => false;
+ public override long Length => throw new NotImplementedException();
+ public override long Position
+ {
+ get => throw new NotImplementedException();
+ set => throw new NotImplementedException();
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ stream.Dispose();
+ ITypes.OutgoingBody.Finish(body, null);
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void Flush()
+ {
+ // ignore
+ //
+ // Note that flushing a `wasi:io/streams/output-stream` is an
+ // asynchronous operation, so it's not clear how we would
+ // implement it here instead of taking care of it as part of
+ // `WriteAsync`.
+ }
+
+ public override void SetLength(long length)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int Read(byte[] buffer, int offset, int length)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void Write(byte[] buffer, int offset, int length)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override async Task WriteAsync(
+ byte[] bytes,
+ int offset,
+ int length,
+ CancellationToken cancellationToken
+ )
+ {
+ var limit = offset + length;
+ var flushing = false;
+ while (true)
+ {
+ var count = (int)stream.CheckWrite();
+ if (count == 0)
+ {
+ await WasiEventLoop.RegisterWasiPollable(stream.Subscribe()).ConfigureAwait(false);
+ }
+ else if (offset == limit)
+ {
+ if (flushing)
+ {
+ return;
+ }
+ else
+ {
+ stream.Flush();
+ flushing = true;
+ }
+ }
+ else
+ {
+ var min = Math.Min(count, limit - offset);
+ if (offset == 0 && min == bytes.Length)
+ {
+ stream.Write(bytes);
+ }
+ else
+ {
+ // TODO: is there a more efficient option than copying here?
+ // Do we need to change the binding generator to accept
+ // e.g. `Span`s?
+ var copy = new byte[min];
+ Array.Copy(bytes, offset, copy, 0, min);
+ stream.Write(copy);
+ }
+ offset += min;
+ }
+ }
+ }
+
+ public override ValueTask WriteAsync(
+ ReadOnlyMemory buffer,
+ CancellationToken cancellationToken = default
+ )
+ {
+ // TODO: avoid copy when possible and use ArrayPool when not
+ var copy = new byte[buffer.Length];
+ buffer.Span.CopyTo(copy);
+ return new ValueTask(WriteAsync(copy, 0, buffer.Length, cancellationToken));
+ }
+ }
+ }
+}
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs
new file mode 100644
index 0000000000000..cb17593768647
--- /dev/null
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs
@@ -0,0 +1,81 @@
+// Generated by `wit-bindgen` 0.27.0. DO NOT EDIT!
+//
+#nullable enable
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Collections;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
+
+namespace WasiHttpWorld.wit.imports.wasi.clocks.v0_2_0
+{
+ internal static class MonotonicClockInterop {
+
+ internal static class NowWasmInterop
+ {
+ [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "now"), WasmImportLinkage]
+ internal static extern long wasmImportNow();
+
+ }
+
+ internal static unsafe ulong Now()
+ {
+ var result = NowWasmInterop.wasmImportNow();
+ return unchecked((ulong)(result));
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class ResolutionWasmInterop
+ {
+ [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "resolution"), WasmImportLinkage]
+ internal static extern long wasmImportResolution();
+
+ }
+
+ internal static unsafe ulong Resolution()
+ {
+ var result = ResolutionWasmInterop.wasmImportResolution();
+ return unchecked((ulong)(result));
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SubscribeInstantWasmInterop
+ {
+ [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "subscribe-instant"), WasmImportLinkage]
+ internal static extern int wasmImportSubscribeInstant(long p0);
+
+ }
+
+ internal static unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable SubscribeInstant(ulong when)
+ {
+ var result = SubscribeInstantWasmInterop.wasmImportSubscribeInstant(unchecked((long)(when)));
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result));
+ return resource;
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SubscribeDurationWasmInterop
+ {
+ [DllImport("wasi:clocks/monotonic-clock@0.2.0", EntryPoint = "subscribe-duration"), WasmImportLinkage]
+ internal static extern int wasmImportSubscribeDuration(long p0);
+
+ }
+
+ internal static unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable SubscribeDuration(ulong when)
+ {
+ var result = SubscribeDurationWasmInterop.wasmImportSubscribeDuration(unchecked((long)(when)));
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result));
+ return resource;
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ }
+}
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.cs
new file mode 100644
index 0000000000000..ddcb79ed49d43
--- /dev/null
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.cs
@@ -0,0 +1,5958 @@
+// Generated by `wit-bindgen` 0.27.0. DO NOT EDIT!
+//
+#nullable enable
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Collections;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
+
+namespace WasiHttpWorld.wit.imports.wasi.http.v0_2_0;
+
+internal interface ITypes {
+
+ /**
+ * This type corresponds to HTTP standard Methods.
+ */
+
+ internal class Method {
+ internal readonly byte Tag;
+ private readonly object? value;
+
+ private Method(byte tag, object? value) {
+ this.Tag = tag;
+ this.value = value;
+ }
+
+ internal static Method get() {
+ return new Method(GET, null);
+ }
+
+ internal static Method head() {
+ return new Method(HEAD, null);
+ }
+
+ internal static Method post() {
+ return new Method(POST, null);
+ }
+
+ internal static Method put() {
+ return new Method(PUT, null);
+ }
+
+ internal static Method delete() {
+ return new Method(DELETE, null);
+ }
+
+ internal static Method connect() {
+ return new Method(CONNECT, null);
+ }
+
+ internal static Method options() {
+ return new Method(OPTIONS, null);
+ }
+
+ internal static Method trace() {
+ return new Method(TRACE, null);
+ }
+
+ internal static Method patch() {
+ return new Method(PATCH, null);
+ }
+
+ internal static Method other(string other) {
+ return new Method(OTHER, other);
+ }
+
+ internal string AsOther
+ {
+ get
+ {
+ if (Tag == OTHER)
+ return (string)value!;
+ else
+ throw new ArgumentException("expected OTHER, got " + Tag);
+ }
+ }
+
+ internal const byte GET = 0;
+ internal const byte HEAD = 1;
+ internal const byte POST = 2;
+ internal const byte PUT = 3;
+ internal const byte DELETE = 4;
+ internal const byte CONNECT = 5;
+ internal const byte OPTIONS = 6;
+ internal const byte TRACE = 7;
+ internal const byte PATCH = 8;
+ internal const byte OTHER = 9;
+ }
+
+ /**
+ * This type corresponds to HTTP standard Related Schemes.
+ */
+
+ internal class Scheme {
+ internal readonly byte Tag;
+ private readonly object? value;
+
+ private Scheme(byte tag, object? value) {
+ this.Tag = tag;
+ this.value = value;
+ }
+
+ internal static Scheme http() {
+ return new Scheme(HTTP, null);
+ }
+
+ internal static Scheme https() {
+ return new Scheme(HTTPS, null);
+ }
+
+ internal static Scheme other(string other) {
+ return new Scheme(OTHER, other);
+ }
+
+ internal string AsOther
+ {
+ get
+ {
+ if (Tag == OTHER)
+ return (string)value!;
+ else
+ throw new ArgumentException("expected OTHER, got " + Tag);
+ }
+ }
+
+ internal const byte HTTP = 0;
+ internal const byte HTTPS = 1;
+ internal const byte OTHER = 2;
+ }
+
+ /**
+ * Defines the case payload type for `DNS-error` above:
+ */
+
+ internal class DnsErrorPayload {
+ internal readonly string? rcode;
+ internal readonly ushort? infoCode;
+
+ internal DnsErrorPayload(string? rcode, ushort? infoCode) {
+ this.rcode = rcode;
+ this.infoCode = infoCode;
+ }
+ }
+
+ /**
+ * Defines the case payload type for `TLS-alert-received` above:
+ */
+
+ internal class TlsAlertReceivedPayload {
+ internal readonly byte? alertId;
+ internal readonly string? alertMessage;
+
+ internal TlsAlertReceivedPayload(byte? alertId, string? alertMessage) {
+ this.alertId = alertId;
+ this.alertMessage = alertMessage;
+ }
+ }
+
+ /**
+ * Defines the case payload type for `HTTP-response-{header,trailer}-size` above:
+ */
+
+ internal class FieldSizePayload {
+ internal readonly string? fieldName;
+ internal readonly uint? fieldSize;
+
+ internal FieldSizePayload(string? fieldName, uint? fieldSize) {
+ this.fieldName = fieldName;
+ this.fieldSize = fieldSize;
+ }
+ }
+
+ /**
+ * These cases are inspired by the IANA HTTP Proxy Error Types:
+ * https://www.iana.org/assignments/http-proxy-status/http-proxy-status.xhtml#table-http-proxy-error-types
+ */
+
+ internal class ErrorCode {
+ internal readonly byte Tag;
+ private readonly object? value;
+
+ private ErrorCode(byte tag, object? value) {
+ this.Tag = tag;
+ this.value = value;
+ }
+
+ internal static ErrorCode dnsTimeout() {
+ return new ErrorCode(DNS_TIMEOUT, null);
+ }
+
+ internal static ErrorCode dnsError(DnsErrorPayload dnsError) {
+ return new ErrorCode(DNS_ERROR, dnsError);
+ }
+
+ internal static ErrorCode destinationNotFound() {
+ return new ErrorCode(DESTINATION_NOT_FOUND, null);
+ }
+
+ internal static ErrorCode destinationUnavailable() {
+ return new ErrorCode(DESTINATION_UNAVAILABLE, null);
+ }
+
+ internal static ErrorCode destinationIpProhibited() {
+ return new ErrorCode(DESTINATION_IP_PROHIBITED, null);
+ }
+
+ internal static ErrorCode destinationIpUnroutable() {
+ return new ErrorCode(DESTINATION_IP_UNROUTABLE, null);
+ }
+
+ internal static ErrorCode connectionRefused() {
+ return new ErrorCode(CONNECTION_REFUSED, null);
+ }
+
+ internal static ErrorCode connectionTerminated() {
+ return new ErrorCode(CONNECTION_TERMINATED, null);
+ }
+
+ internal static ErrorCode connectionTimeout() {
+ return new ErrorCode(CONNECTION_TIMEOUT, null);
+ }
+
+ internal static ErrorCode connectionReadTimeout() {
+ return new ErrorCode(CONNECTION_READ_TIMEOUT, null);
+ }
+
+ internal static ErrorCode connectionWriteTimeout() {
+ return new ErrorCode(CONNECTION_WRITE_TIMEOUT, null);
+ }
+
+ internal static ErrorCode connectionLimitReached() {
+ return new ErrorCode(CONNECTION_LIMIT_REACHED, null);
+ }
+
+ internal static ErrorCode tlsProtocolError() {
+ return new ErrorCode(TLS_PROTOCOL_ERROR, null);
+ }
+
+ internal static ErrorCode tlsCertificateError() {
+ return new ErrorCode(TLS_CERTIFICATE_ERROR, null);
+ }
+
+ internal static ErrorCode tlsAlertReceived(TlsAlertReceivedPayload tlsAlertReceived) {
+ return new ErrorCode(TLS_ALERT_RECEIVED, tlsAlertReceived);
+ }
+
+ internal static ErrorCode httpRequestDenied() {
+ return new ErrorCode(HTTP_REQUEST_DENIED, null);
+ }
+
+ internal static ErrorCode httpRequestLengthRequired() {
+ return new ErrorCode(HTTP_REQUEST_LENGTH_REQUIRED, null);
+ }
+
+ internal static ErrorCode httpRequestBodySize(ulong? httpRequestBodySize) {
+ return new ErrorCode(HTTP_REQUEST_BODY_SIZE, httpRequestBodySize);
+ }
+
+ internal static ErrorCode httpRequestMethodInvalid() {
+ return new ErrorCode(HTTP_REQUEST_METHOD_INVALID, null);
+ }
+
+ internal static ErrorCode httpRequestUriInvalid() {
+ return new ErrorCode(HTTP_REQUEST_URI_INVALID, null);
+ }
+
+ internal static ErrorCode httpRequestUriTooLong() {
+ return new ErrorCode(HTTP_REQUEST_URI_TOO_LONG, null);
+ }
+
+ internal static ErrorCode httpRequestHeaderSectionSize(uint? httpRequestHeaderSectionSize) {
+ return new ErrorCode(HTTP_REQUEST_HEADER_SECTION_SIZE, httpRequestHeaderSectionSize);
+ }
+
+ internal static ErrorCode httpRequestHeaderSize(FieldSizePayload? httpRequestHeaderSize) {
+ return new ErrorCode(HTTP_REQUEST_HEADER_SIZE, httpRequestHeaderSize);
+ }
+
+ internal static ErrorCode httpRequestTrailerSectionSize(uint? httpRequestTrailerSectionSize) {
+ return new ErrorCode(HTTP_REQUEST_TRAILER_SECTION_SIZE, httpRequestTrailerSectionSize);
+ }
+
+ internal static ErrorCode httpRequestTrailerSize(FieldSizePayload httpRequestTrailerSize) {
+ return new ErrorCode(HTTP_REQUEST_TRAILER_SIZE, httpRequestTrailerSize);
+ }
+
+ internal static ErrorCode httpResponseIncomplete() {
+ return new ErrorCode(HTTP_RESPONSE_INCOMPLETE, null);
+ }
+
+ internal static ErrorCode httpResponseHeaderSectionSize(uint? httpResponseHeaderSectionSize) {
+ return new ErrorCode(HTTP_RESPONSE_HEADER_SECTION_SIZE, httpResponseHeaderSectionSize);
+ }
+
+ internal static ErrorCode httpResponseHeaderSize(FieldSizePayload httpResponseHeaderSize) {
+ return new ErrorCode(HTTP_RESPONSE_HEADER_SIZE, httpResponseHeaderSize);
+ }
+
+ internal static ErrorCode httpResponseBodySize(ulong? httpResponseBodySize) {
+ return new ErrorCode(HTTP_RESPONSE_BODY_SIZE, httpResponseBodySize);
+ }
+
+ internal static ErrorCode httpResponseTrailerSectionSize(uint? httpResponseTrailerSectionSize) {
+ return new ErrorCode(HTTP_RESPONSE_TRAILER_SECTION_SIZE, httpResponseTrailerSectionSize);
+ }
+
+ internal static ErrorCode httpResponseTrailerSize(FieldSizePayload httpResponseTrailerSize) {
+ return new ErrorCode(HTTP_RESPONSE_TRAILER_SIZE, httpResponseTrailerSize);
+ }
+
+ internal static ErrorCode httpResponseTransferCoding(string? httpResponseTransferCoding) {
+ return new ErrorCode(HTTP_RESPONSE_TRANSFER_CODING, httpResponseTransferCoding);
+ }
+
+ internal static ErrorCode httpResponseContentCoding(string? httpResponseContentCoding) {
+ return new ErrorCode(HTTP_RESPONSE_CONTENT_CODING, httpResponseContentCoding);
+ }
+
+ internal static ErrorCode httpResponseTimeout() {
+ return new ErrorCode(HTTP_RESPONSE_TIMEOUT, null);
+ }
+
+ internal static ErrorCode httpUpgradeFailed() {
+ return new ErrorCode(HTTP_UPGRADE_FAILED, null);
+ }
+
+ internal static ErrorCode httpProtocolError() {
+ return new ErrorCode(HTTP_PROTOCOL_ERROR, null);
+ }
+
+ internal static ErrorCode loopDetected() {
+ return new ErrorCode(LOOP_DETECTED, null);
+ }
+
+ internal static ErrorCode configurationError() {
+ return new ErrorCode(CONFIGURATION_ERROR, null);
+ }
+
+ internal static ErrorCode internalError(string? internalError) {
+ return new ErrorCode(INTERNAL_ERROR, internalError);
+ }
+
+ internal DnsErrorPayload AsDnsError
+ {
+ get
+ {
+ if (Tag == DNS_ERROR)
+ return (DnsErrorPayload)value!;
+ else
+ throw new ArgumentException("expected DNS_ERROR, got " + Tag);
+ }
+ }
+
+ internal TlsAlertReceivedPayload AsTlsAlertReceived
+ {
+ get
+ {
+ if (Tag == TLS_ALERT_RECEIVED)
+ return (TlsAlertReceivedPayload)value!;
+ else
+ throw new ArgumentException("expected TLS_ALERT_RECEIVED, got " + Tag);
+ }
+ }
+
+ internal ulong? AsHttpRequestBodySize
+ {
+ get
+ {
+ if (Tag == HTTP_REQUEST_BODY_SIZE)
+ return (ulong?)value!;
+ else
+ throw new ArgumentException("expected HTTP_REQUEST_BODY_SIZE, got " + Tag);
+ }
+ }
+
+ internal uint? AsHttpRequestHeaderSectionSize
+ {
+ get
+ {
+ if (Tag == HTTP_REQUEST_HEADER_SECTION_SIZE)
+ return (uint?)value!;
+ else
+ throw new ArgumentException("expected HTTP_REQUEST_HEADER_SECTION_SIZE, got " + Tag);
+ }
+ }
+
+ internal FieldSizePayload? AsHttpRequestHeaderSize
+ {
+ get
+ {
+ if (Tag == HTTP_REQUEST_HEADER_SIZE)
+ return (FieldSizePayload?)value!;
+ else
+ throw new ArgumentException("expected HTTP_REQUEST_HEADER_SIZE, got " + Tag);
+ }
+ }
+
+ internal uint? AsHttpRequestTrailerSectionSize
+ {
+ get
+ {
+ if (Tag == HTTP_REQUEST_TRAILER_SECTION_SIZE)
+ return (uint?)value!;
+ else
+ throw new ArgumentException("expected HTTP_REQUEST_TRAILER_SECTION_SIZE, got " + Tag);
+ }
+ }
+
+ internal FieldSizePayload AsHttpRequestTrailerSize
+ {
+ get
+ {
+ if (Tag == HTTP_REQUEST_TRAILER_SIZE)
+ return (FieldSizePayload)value!;
+ else
+ throw new ArgumentException("expected HTTP_REQUEST_TRAILER_SIZE, got " + Tag);
+ }
+ }
+
+ internal uint? AsHttpResponseHeaderSectionSize
+ {
+ get
+ {
+ if (Tag == HTTP_RESPONSE_HEADER_SECTION_SIZE)
+ return (uint?)value!;
+ else
+ throw new ArgumentException("expected HTTP_RESPONSE_HEADER_SECTION_SIZE, got " + Tag);
+ }
+ }
+
+ internal FieldSizePayload AsHttpResponseHeaderSize
+ {
+ get
+ {
+ if (Tag == HTTP_RESPONSE_HEADER_SIZE)
+ return (FieldSizePayload)value!;
+ else
+ throw new ArgumentException("expected HTTP_RESPONSE_HEADER_SIZE, got " + Tag);
+ }
+ }
+
+ internal ulong? AsHttpResponseBodySize
+ {
+ get
+ {
+ if (Tag == HTTP_RESPONSE_BODY_SIZE)
+ return (ulong?)value!;
+ else
+ throw new ArgumentException("expected HTTP_RESPONSE_BODY_SIZE, got " + Tag);
+ }
+ }
+
+ internal uint? AsHttpResponseTrailerSectionSize
+ {
+ get
+ {
+ if (Tag == HTTP_RESPONSE_TRAILER_SECTION_SIZE)
+ return (uint?)value!;
+ else
+ throw new ArgumentException("expected HTTP_RESPONSE_TRAILER_SECTION_SIZE, got " + Tag);
+ }
+ }
+
+ internal FieldSizePayload AsHttpResponseTrailerSize
+ {
+ get
+ {
+ if (Tag == HTTP_RESPONSE_TRAILER_SIZE)
+ return (FieldSizePayload)value!;
+ else
+ throw new ArgumentException("expected HTTP_RESPONSE_TRAILER_SIZE, got " + Tag);
+ }
+ }
+
+ internal string? AsHttpResponseTransferCoding
+ {
+ get
+ {
+ if (Tag == HTTP_RESPONSE_TRANSFER_CODING)
+ return (string?)value!;
+ else
+ throw new ArgumentException("expected HTTP_RESPONSE_TRANSFER_CODING, got " + Tag);
+ }
+ }
+
+ internal string? AsHttpResponseContentCoding
+ {
+ get
+ {
+ if (Tag == HTTP_RESPONSE_CONTENT_CODING)
+ return (string?)value!;
+ else
+ throw new ArgumentException("expected HTTP_RESPONSE_CONTENT_CODING, got " + Tag);
+ }
+ }
+
+ internal string? AsInternalError
+ {
+ get
+ {
+ if (Tag == INTERNAL_ERROR)
+ return (string?)value!;
+ else
+ throw new ArgumentException("expected INTERNAL_ERROR, got " + Tag);
+ }
+ }
+
+ internal const byte DNS_TIMEOUT = 0;
+ internal const byte DNS_ERROR = 1;
+ internal const byte DESTINATION_NOT_FOUND = 2;
+ internal const byte DESTINATION_UNAVAILABLE = 3;
+ internal const byte DESTINATION_IP_PROHIBITED = 4;
+ internal const byte DESTINATION_IP_UNROUTABLE = 5;
+ internal const byte CONNECTION_REFUSED = 6;
+ internal const byte CONNECTION_TERMINATED = 7;
+ internal const byte CONNECTION_TIMEOUT = 8;
+ internal const byte CONNECTION_READ_TIMEOUT = 9;
+ internal const byte CONNECTION_WRITE_TIMEOUT = 10;
+ internal const byte CONNECTION_LIMIT_REACHED = 11;
+ internal const byte TLS_PROTOCOL_ERROR = 12;
+ internal const byte TLS_CERTIFICATE_ERROR = 13;
+ internal const byte TLS_ALERT_RECEIVED = 14;
+ internal const byte HTTP_REQUEST_DENIED = 15;
+ internal const byte HTTP_REQUEST_LENGTH_REQUIRED = 16;
+ internal const byte HTTP_REQUEST_BODY_SIZE = 17;
+ internal const byte HTTP_REQUEST_METHOD_INVALID = 18;
+ internal const byte HTTP_REQUEST_URI_INVALID = 19;
+ internal const byte HTTP_REQUEST_URI_TOO_LONG = 20;
+ internal const byte HTTP_REQUEST_HEADER_SECTION_SIZE = 21;
+ internal const byte HTTP_REQUEST_HEADER_SIZE = 22;
+ internal const byte HTTP_REQUEST_TRAILER_SECTION_SIZE = 23;
+ internal const byte HTTP_REQUEST_TRAILER_SIZE = 24;
+ internal const byte HTTP_RESPONSE_INCOMPLETE = 25;
+ internal const byte HTTP_RESPONSE_HEADER_SECTION_SIZE = 26;
+ internal const byte HTTP_RESPONSE_HEADER_SIZE = 27;
+ internal const byte HTTP_RESPONSE_BODY_SIZE = 28;
+ internal const byte HTTP_RESPONSE_TRAILER_SECTION_SIZE = 29;
+ internal const byte HTTP_RESPONSE_TRAILER_SIZE = 30;
+ internal const byte HTTP_RESPONSE_TRANSFER_CODING = 31;
+ internal const byte HTTP_RESPONSE_CONTENT_CODING = 32;
+ internal const byte HTTP_RESPONSE_TIMEOUT = 33;
+ internal const byte HTTP_UPGRADE_FAILED = 34;
+ internal const byte HTTP_PROTOCOL_ERROR = 35;
+ internal const byte LOOP_DETECTED = 36;
+ internal const byte CONFIGURATION_ERROR = 37;
+ internal const byte INTERNAL_ERROR = 38;
+ }
+
+ /**
+ * This type enumerates the different kinds of errors that may occur when
+ * setting or appending to a `fields` resource.
+ */
+
+ internal class HeaderError {
+ internal readonly byte Tag;
+ private readonly object? value;
+
+ private HeaderError(byte tag, object? value) {
+ this.Tag = tag;
+ this.value = value;
+ }
+
+ internal static HeaderError invalidSyntax() {
+ return new HeaderError(INVALID_SYNTAX, null);
+ }
+
+ internal static HeaderError forbidden() {
+ return new HeaderError(FORBIDDEN, null);
+ }
+
+ internal static HeaderError immutable() {
+ return new HeaderError(IMMUTABLE, null);
+ }
+
+ internal const byte INVALID_SYNTAX = 0;
+ internal const byte FORBIDDEN = 1;
+ internal const byte IMMUTABLE = 2;
+ }
+
+ /**
+ * 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 be
+ * immutable. In an immutable fields, the `set`, `append`, and `delete`
+ * operations will fail with `header-error.immutable`.
+ */
+
+ internal class Fields: IDisposable {
+ internal int Handle { get; set; }
+
+ internal readonly record struct THandle(int Handle);
+
+ internal Fields(THandle handle) {
+ Handle = handle.Handle;
+ }
+
+ public void Dispose() {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]fields"), WasmImportLinkage]
+ private static extern void wasmImportResourceDrop(int p0);
+
+ protected virtual void Dispose(bool disposing) {
+ if (Handle != 0) {
+ wasmImportResourceDrop(Handle);
+ Handle = 0;
+ }
+ }
+
+ ~Fields() {
+ Dispose(false);
+ }
+
+ internal static class ConstructorWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[constructor]fields"), WasmImportLinkage]
+ internal static extern int wasmImportConstructor();
+
+ }
+
+ internal unsafe Fields()
+ {
+ var result = ConstructorWasmInterop.wasmImportConstructor();
+ this.Handle = result;
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class FromListWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[static]fields.from-list"), WasmImportLinkage]
+ internal static extern void wasmImportFromList(nint p0, int p1, nint p2);
+
+ }
+
+ internal static unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields FromList(List<(string, byte[])> entries)
+ {
+
+ byte[] buffer0 = new byte[16 * entries.Count];
+ var gcHandle = GCHandle.Alloc(buffer0, GCHandleType.Pinned);
+ var address = gcHandle.AddrOfPinnedObject();
+
+ for (int index = 0; index < entries.Count; ++index) {
+ (string, byte[]) element = entries[index];
+ int basePtr = (int)address + (index * 16);
+
+ var result = element.Item1;
+ IntPtr interopString = InteropString.FromString(result, out int lengthresult);
+ BitConverter.TryWriteBytes(new Span((void*)(basePtr + 4), 4), unchecked((int)lengthresult));
+ BitConverter.TryWriteBytes(new Span((void*)(basePtr + 0), 4), unchecked((int)interopString.ToInt32()));
+
+ void* buffer = stackalloc byte[(element.Item2).Length];
+ element.Item2.AsSpan().CopyTo(new Span(buffer, element.Item2.Length));
+ BitConverter.TryWriteBytes(new Span((void*)(basePtr + 12), 4), unchecked((int)(element.Item2).Length));
+ BitConverter.TryWriteBytes(new Span((void*)(basePtr + 8), 4), unchecked((int)(int)buffer));
+
+ }
+
+ var retArea = new uint[2];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ FromListWasmInterop.wasmImportFromList((int)address, entries.Count, ptr);
+
+ Result lifted11;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))));
+
+ lifted11 = Result.ok(resource);
+ break;
+ }
+ case 1: {
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted;
+
+ switch (new Span((void*)(ptr + 4), 1)[0]) {
+ case 0: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.invalidSyntax();
+ break;
+ }
+ case 1: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.forbidden();
+ break;
+ }
+ case 2: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.immutable();
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}");
+ }
+
+ lifted11 = Result.err(lifted);
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}");
+ }
+ gcHandle.Free();
+ if (lifted11.IsOk) {
+ var tmp = lifted11.AsOk;
+ return tmp;
+ } else {
+ throw new WitException(lifted11.AsErr!, 0);
+ }
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class GetWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.get"), WasmImportLinkage]
+ internal static extern void wasmImportGet(int p0, nint p1, int p2, nint p3);
+
+ }
+
+ internal unsafe List Get(string name)
+ {
+ var handle = this.Handle;
+
+ var result = name;
+ IntPtr interopString = InteropString.FromString(result, out int lengthresult);
+
+ var retArea = new uint[2];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ GetWasmInterop.wasmImportGet(handle, interopString.ToInt32(), lengthresult, ptr);
+
+ var array0 = new List(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)));
+ for (int index = 0; index < BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)); ++index) {
+ nint basePtr = BitConverter.ToInt32(new Span((void*)(ptr + 0), 4)) + (index * 8);
+
+ var array = new byte[BitConverter.ToInt32(new Span((void*)(basePtr + 4), 4))];
+ new Span((void*)(BitConverter.ToInt32(new Span((void*)(basePtr + 0), 4))), BitConverter.ToInt32(new Span((void*)(basePtr + 4), 4))).CopyTo(new Span(array));
+
+ array0.Add(array);
+ }
+ return array0;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class HasWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.has"), WasmImportLinkage]
+ internal static extern int wasmImportHas(int p0, nint p1, int p2);
+
+ }
+
+ internal unsafe bool Has(string name)
+ {
+ var handle = this.Handle;
+
+ var result = name;
+ IntPtr interopString = InteropString.FromString(result, out int lengthresult);
+ var result0 = HasWasmInterop.wasmImportHas(handle, interopString.ToInt32(), lengthresult);
+ return (result0 != 0);
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SetWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.set"), WasmImportLinkage]
+ internal static extern void wasmImportSet(int p0, nint p1, int p2, nint p3, int p4, nint p5);
+
+ }
+
+ internal unsafe void Set(string name, List value)
+ {
+ var handle = this.Handle;
+
+ var result = name;
+ IntPtr interopString = InteropString.FromString(result, out int lengthresult);
+
+ byte[] buffer0 = new byte[8 * value.Count];
+ var gcHandle = GCHandle.Alloc(buffer0, GCHandleType.Pinned);
+ var address = gcHandle.AddrOfPinnedObject();
+
+ for (int index = 0; index < value.Count; ++index) {
+ byte[] element = value[index];
+ int basePtr = (int)address + (index * 8);
+
+ void* buffer = stackalloc byte[(element).Length];
+ element.AsSpan().CopyTo(new Span(buffer, element.Length));
+ BitConverter.TryWriteBytes(new Span((void*)(basePtr + 4), 4), unchecked((int)(element).Length));
+ BitConverter.TryWriteBytes(new Span((void*)(basePtr + 0), 4), unchecked((int)(int)buffer));
+
+ }
+
+ var retArea = new byte[2];
+ fixed (byte* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ SetWasmInterop.wasmImportSet(handle, interopString.ToInt32(), lengthresult, (int)address, value.Count, ptr);
+
+ Result lifted11;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+
+ lifted11 = Result.ok(new global::WasiHttpWorld.None());
+ break;
+ }
+ case 1: {
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted;
+
+ switch (new Span((void*)(ptr + 1), 1)[0]) {
+ case 0: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.invalidSyntax();
+ break;
+ }
+ case 1: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.forbidden();
+ break;
+ }
+ case 2: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.immutable();
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 1), 1)[0]}");
+ }
+
+ lifted11 = Result.err(lifted);
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}");
+ }
+ gcHandle.Free();
+ if (lifted11.IsOk) {
+ var tmp = lifted11.AsOk;
+ return ;
+ } else {
+ throw new WitException(lifted11.AsErr!, 0);
+ }
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class DeleteWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.delete"), WasmImportLinkage]
+ internal static extern void wasmImportDelete(int p0, nint p1, int p2, nint p3);
+
+ }
+
+ internal unsafe void Delete(string name)
+ {
+ var handle = this.Handle;
+
+ var result = name;
+ IntPtr interopString = InteropString.FromString(result, out int lengthresult);
+
+ var retArea = new byte[2];
+ fixed (byte* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ DeleteWasmInterop.wasmImportDelete(handle, interopString.ToInt32(), lengthresult, ptr);
+
+ Result lifted8;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+
+ lifted8 = Result.ok(new global::WasiHttpWorld.None());
+ break;
+ }
+ case 1: {
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted;
+
+ switch (new Span((void*)(ptr + 1), 1)[0]) {
+ case 0: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.invalidSyntax();
+ break;
+ }
+ case 1: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.forbidden();
+ break;
+ }
+ case 2: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.immutable();
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 1), 1)[0]}");
+ }
+
+ lifted8 = Result.err(lifted);
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}");
+ }
+ if (lifted8.IsOk) {
+ var tmp = lifted8.AsOk;
+ return ;
+ } else {
+ throw new WitException(lifted8.AsErr!, 0);
+ }
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class AppendWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.append"), WasmImportLinkage]
+ internal static extern void wasmImportAppend(int p0, nint p1, int p2, nint p3, int p4, nint p5);
+
+ }
+
+ internal unsafe void Append(string name, byte[] value)
+ {
+ var handle = this.Handle;
+
+ var result = name;
+ IntPtr interopString = InteropString.FromString(result, out int lengthresult);
+
+ void* buffer = stackalloc byte[(value).Length];
+ value.AsSpan().CopyTo(new Span(buffer, value.Length));
+
+ var retArea = new byte[2];
+ fixed (byte* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ AppendWasmInterop.wasmImportAppend(handle, interopString.ToInt32(), lengthresult, (int)buffer, (value).Length, ptr);
+
+ Result lifted8;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+
+ lifted8 = Result.ok(new global::WasiHttpWorld.None());
+ break;
+ }
+ case 1: {
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError lifted;
+
+ switch (new Span((void*)(ptr + 1), 1)[0]) {
+ case 0: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.invalidSyntax();
+ break;
+ }
+ case 1: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.forbidden();
+ break;
+ }
+ case 2: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.HeaderError.immutable();
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 1), 1)[0]}");
+ }
+
+ lifted8 = Result.err(lifted);
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}");
+ }
+ if (lifted8.IsOk) {
+ var tmp = lifted8.AsOk;
+ return ;
+ } else {
+ throw new WitException(lifted8.AsErr!, 0);
+ }
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class EntriesWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.entries"), WasmImportLinkage]
+ internal static extern void wasmImportEntries(int p0, nint p1);
+
+ }
+
+ internal unsafe List<(string, byte[])> Entries()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[2];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ EntriesWasmInterop.wasmImportEntries(handle, ptr);
+
+ var array0 = new List<(string, byte[])>(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)));
+ for (int index = 0; index < BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)); ++index) {
+ nint basePtr = BitConverter.ToInt32(new Span((void*)(ptr + 0), 4)) + (index * 16);
+
+ var array = new byte[BitConverter.ToInt32(new Span((void*)(basePtr + 12), 4))];
+ new Span((void*)(BitConverter.ToInt32(new Span((void*)(basePtr + 8), 4))), BitConverter.ToInt32(new Span((void*)(basePtr + 12), 4))).CopyTo(new Span(array));
+
+ array0.Add((Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(basePtr + 0), 4)), BitConverter.ToInt32(new Span((void*)(basePtr + 4), 4))), array
+ ));
+ }
+ return array0;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class CloneWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]fields.clone"), WasmImportLinkage]
+ internal static extern int wasmImportClone(int p0);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Clone()
+ {
+ var handle = this.Handle;
+ var result = CloneWasmInterop.wasmImportClone(handle);
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result));
+ return resource;
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ }
+
+ /**
+ * Represents an incoming HTTP Request.
+ */
+
+ internal class IncomingRequest: IDisposable {
+ internal int Handle { get; set; }
+
+ internal readonly record struct THandle(int Handle);
+
+ internal IncomingRequest(THandle handle) {
+ Handle = handle.Handle;
+ }
+
+ public void Dispose() {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]incoming-request"), WasmImportLinkage]
+ private static extern void wasmImportResourceDrop(int p0);
+
+ protected virtual void Dispose(bool disposing) {
+ if (Handle != 0) {
+ wasmImportResourceDrop(Handle);
+ Handle = 0;
+ }
+ }
+
+ ~IncomingRequest() {
+ Dispose(false);
+ }
+
+ internal static class MethodWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.method"), WasmImportLinkage]
+ internal static extern void wasmImportMethod(int p0, nint p1);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method Method()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[3];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ MethodWasmInterop.wasmImportMethod(handle, ptr);
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.get();
+ break;
+ }
+ case 1: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.head();
+ break;
+ }
+ case 2: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.post();
+ break;
+ }
+ case 3: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.put();
+ break;
+ }
+ case 4: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.delete();
+ break;
+ }
+ case 5: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.connect();
+ break;
+ }
+ case 6: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.options();
+ break;
+ }
+ case 7: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.trace();
+ break;
+ }
+ case 8: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.patch();
+ break;
+ }
+ case 9: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.other(Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}");
+ }
+ return lifted;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class PathWithQueryWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.path-with-query"), WasmImportLinkage]
+ internal static extern void wasmImportPathWithQuery(int p0, nint p1);
+
+ }
+
+ internal unsafe string? PathWithQuery()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[3];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ PathWithQueryWasmInterop.wasmImportPathWithQuery(handle, ptr);
+
+ string? lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ lifted = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0]));
+ }
+ return lifted;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SchemeWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.scheme"), WasmImportLinkage]
+ internal static extern void wasmImportScheme(int p0, nint p1);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? Scheme()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[4];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ SchemeWasmInterop.wasmImportScheme(handle, ptr);
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? lifted8;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ lifted8 = null;
+ break;
+ }
+
+ case 1: {
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme lifted;
+
+ switch (new Span((void*)(ptr + 4), 1)[0]) {
+ case 0: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.http();
+ break;
+ }
+ case 1: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.https();
+ break;
+ }
+ case 2: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.other(Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 12), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}");
+ }
+
+ lifted8 = lifted;
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0]));
+ }
+ return lifted8;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class AuthorityWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.authority"), WasmImportLinkage]
+ internal static extern void wasmImportAuthority(int p0, nint p1);
+
+ }
+
+ internal unsafe string? Authority()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[3];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ AuthorityWasmInterop.wasmImportAuthority(handle, ptr);
+
+ string? lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ lifted = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0]));
+ }
+ return lifted;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class HeadersWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.headers"), WasmImportLinkage]
+ internal static extern int wasmImportHeaders(int p0);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Headers()
+ {
+ var handle = this.Handle;
+ var result = HeadersWasmInterop.wasmImportHeaders(handle);
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result));
+ return resource;
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class ConsumeWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-request.consume"), WasmImportLinkage]
+ internal static extern void wasmImportConsume(int p0, nint p1);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody Consume()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[2];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ ConsumeWasmInterop.wasmImportConsume(handle, ptr);
+
+ Result lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))));
+
+ lifted = Result.ok(resource);
+ break;
+ }
+ case 1: {
+
+ lifted = Result.err(new global::WasiHttpWorld.None());
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}");
+ }
+ if (lifted.IsOk) {
+ var tmp = lifted.AsOk;
+ return tmp;
+ } else {
+ throw new WitException(lifted.AsErr!, 0);
+ }
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ }
+
+ /**
+ * Represents an outgoing HTTP Request.
+ */
+
+ internal class OutgoingRequest: IDisposable {
+ internal int Handle { get; set; }
+
+ internal readonly record struct THandle(int Handle);
+
+ internal OutgoingRequest(THandle handle) {
+ Handle = handle.Handle;
+ }
+
+ public void Dispose() {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]outgoing-request"), WasmImportLinkage]
+ private static extern void wasmImportResourceDrop(int p0);
+
+ protected virtual void Dispose(bool disposing) {
+ if (Handle != 0) {
+ wasmImportResourceDrop(Handle);
+ Handle = 0;
+ }
+ }
+
+ ~OutgoingRequest() {
+ Dispose(false);
+ }
+
+ internal static class ConstructorWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[constructor]outgoing-request"), WasmImportLinkage]
+ internal static extern int wasmImportConstructor(int p0);
+
+ }
+
+ internal unsafe OutgoingRequest(global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields headers)
+ {
+ var handle = headers.Handle;
+ headers.Handle = 0;
+ var result = ConstructorWasmInterop.wasmImportConstructor(handle);
+ this.Handle = result;
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class BodyWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.body"), WasmImportLinkage]
+ internal static extern void wasmImportBody(int p0, nint p1);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody Body()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[2];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ BodyWasmInterop.wasmImportBody(handle, ptr);
+
+ Result lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingBody.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))));
+
+ lifted = Result.ok(resource);
+ break;
+ }
+ case 1: {
+
+ lifted = Result.err(new global::WasiHttpWorld.None());
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}");
+ }
+ if (lifted.IsOk) {
+ var tmp = lifted.AsOk;
+ return tmp;
+ } else {
+ throw new WitException(lifted.AsErr!, 0);
+ }
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class MethodWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.method"), WasmImportLinkage]
+ internal static extern void wasmImportMethod(int p0, nint p1);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method Method()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[3];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ MethodWasmInterop.wasmImportMethod(handle, ptr);
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.get();
+ break;
+ }
+ case 1: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.head();
+ break;
+ }
+ case 2: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.post();
+ break;
+ }
+ case 3: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.put();
+ break;
+ }
+ case 4: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.delete();
+ break;
+ }
+ case 5: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.connect();
+ break;
+ }
+ case 6: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.options();
+ break;
+ }
+ case 7: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.trace();
+ break;
+ }
+ case 8: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.patch();
+ break;
+ }
+ case 9: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method.other(Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}");
+ }
+ return lifted;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SetMethodWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.set-method"), WasmImportLinkage]
+ internal static extern int wasmImportSetMethod(int p0, int p1, nint p2, int p3);
+
+ }
+
+ internal unsafe void SetMethod(global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Method method)
+ {
+ var handle = this.Handle;
+
+ int lowered;
+ nint lowered27;
+ int lowered28;
+
+ switch (method.Tag) {
+ case 0: {
+
+ lowered = 0;
+ lowered27 = 0;
+ lowered28 = 0;
+
+ break;
+ }
+ case 1: {
+
+ lowered = 1;
+ lowered27 = 0;
+ lowered28 = 0;
+
+ break;
+ }
+ case 2: {
+
+ lowered = 2;
+ lowered27 = 0;
+ lowered28 = 0;
+
+ break;
+ }
+ case 3: {
+
+ lowered = 3;
+ lowered27 = 0;
+ lowered28 = 0;
+
+ break;
+ }
+ case 4: {
+
+ lowered = 4;
+ lowered27 = 0;
+ lowered28 = 0;
+
+ break;
+ }
+ case 5: {
+
+ lowered = 5;
+ lowered27 = 0;
+ lowered28 = 0;
+
+ break;
+ }
+ case 6: {
+
+ lowered = 6;
+ lowered27 = 0;
+ lowered28 = 0;
+
+ break;
+ }
+ case 7: {
+
+ lowered = 7;
+ lowered27 = 0;
+ lowered28 = 0;
+
+ break;
+ }
+ case 8: {
+
+ lowered = 8;
+ lowered27 = 0;
+ lowered28 = 0;
+
+ break;
+ }
+ case 9: {
+ string payload26 = method.AsOther;
+
+ var result = payload26;
+ IntPtr interopString = InteropString.FromString(result, out int lengthresult);
+
+ lowered = 9;
+ lowered27 = interopString.ToInt32();
+ lowered28 = lengthresult;
+
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {method}");
+ }
+ var result29 = SetMethodWasmInterop.wasmImportSetMethod(handle, lowered, lowered27, lowered28);
+
+ Result lifted;
+
+ switch (result29) {
+ case 0: {
+
+ lifted = Result.ok(new global::WasiHttpWorld.None());
+ break;
+ }
+ case 1: {
+
+ lifted = Result.err(new global::WasiHttpWorld.None());
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {result29}");
+ }
+ if (lifted.IsOk) {
+ var tmp = lifted.AsOk;
+ return ;
+ } else {
+ throw new WitException(lifted.AsErr!, 0);
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class PathWithQueryWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.path-with-query"), WasmImportLinkage]
+ internal static extern void wasmImportPathWithQuery(int p0, nint p1);
+
+ }
+
+ internal unsafe string? PathWithQuery()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[3];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ PathWithQueryWasmInterop.wasmImportPathWithQuery(handle, ptr);
+
+ string? lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ lifted = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0]));
+ }
+ return lifted;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SetPathWithQueryWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.set-path-with-query"), WasmImportLinkage]
+ internal static extern int wasmImportSetPathWithQuery(int p0, int p1, nint p2, int p3);
+
+ }
+
+ internal unsafe void SetPathWithQuery(string? pathWithQuery)
+ {
+ var handle = this.Handle;
+
+ int lowered;
+ nint lowered3;
+ int lowered4;
+
+ if (pathWithQuery != null) {
+ var payload2 = (string) pathWithQuery;
+
+ var result = payload2;
+ IntPtr interopString = InteropString.FromString(result, out int lengthresult);
+
+ lowered = 1;
+ lowered3 = interopString.ToInt32();
+ lowered4 = lengthresult;
+
+ } else {
+
+ lowered = 0;
+ lowered3 = 0;
+ lowered4 = 0;
+
+ }
+ var result5 = SetPathWithQueryWasmInterop.wasmImportSetPathWithQuery(handle, lowered, lowered3, lowered4);
+
+ Result lifted;
+
+ switch (result5) {
+ case 0: {
+
+ lifted = Result.ok(new global::WasiHttpWorld.None());
+ break;
+ }
+ case 1: {
+
+ lifted = Result.err(new global::WasiHttpWorld.None());
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {result5}");
+ }
+ if (lifted.IsOk) {
+ var tmp = lifted.AsOk;
+ return ;
+ } else {
+ throw new WitException(lifted.AsErr!, 0);
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SchemeWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.scheme"), WasmImportLinkage]
+ internal static extern void wasmImportScheme(int p0, nint p1);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? Scheme()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[4];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ SchemeWasmInterop.wasmImportScheme(handle, ptr);
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? lifted8;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ lifted8 = null;
+ break;
+ }
+
+ case 1: {
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme lifted;
+
+ switch (new Span((void*)(ptr + 4), 1)[0]) {
+ case 0: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.http();
+ break;
+ }
+ case 1: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.https();
+ break;
+ }
+ case 2: {
+
+ lifted = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme.other(Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 12), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 4), 1)[0]}");
+ }
+
+ lifted8 = lifted;
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0]));
+ }
+ return lifted8;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SetSchemeWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.set-scheme"), WasmImportLinkage]
+ internal static extern int wasmImportSetScheme(int p0, int p1, int p2, nint p3, int p4);
+
+ }
+
+ internal unsafe void SetScheme(global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme? scheme)
+ {
+ var handle = this.Handle;
+
+ int lowered14;
+ int lowered15;
+ nint lowered16;
+ int lowered17;
+
+ if (scheme != null) {
+ var payload2 = (global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Scheme) scheme;
+
+ int lowered;
+ nint lowered12;
+ int lowered13;
+
+ switch (payload2.Tag) {
+ case 0: {
+
+ lowered = 0;
+ lowered12 = 0;
+ lowered13 = 0;
+
+ break;
+ }
+ case 1: {
+
+ lowered = 1;
+ lowered12 = 0;
+ lowered13 = 0;
+
+ break;
+ }
+ case 2: {
+ string payload11 = payload2.AsOther;
+
+ var result = payload11;
+ IntPtr interopString = InteropString.FromString(result, out int lengthresult);
+
+ lowered = 2;
+ lowered12 = interopString.ToInt32();
+ lowered13 = lengthresult;
+
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {payload2}");
+ }
+
+ lowered14 = 1;
+ lowered15 = lowered;
+ lowered16 = lowered12;
+ lowered17 = lowered13;
+
+ } else {
+
+ lowered14 = 0;
+ lowered15 = 0;
+ lowered16 = 0;
+ lowered17 = 0;
+
+ }
+ var result18 = SetSchemeWasmInterop.wasmImportSetScheme(handle, lowered14, lowered15, lowered16, lowered17);
+
+ Result lifted;
+
+ switch (result18) {
+ case 0: {
+
+ lifted = Result.ok(new global::WasiHttpWorld.None());
+ break;
+ }
+ case 1: {
+
+ lifted = Result.err(new global::WasiHttpWorld.None());
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {result18}");
+ }
+ if (lifted.IsOk) {
+ var tmp = lifted.AsOk;
+ return ;
+ } else {
+ throw new WitException(lifted.AsErr!, 0);
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class AuthorityWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.authority"), WasmImportLinkage]
+ internal static extern void wasmImportAuthority(int p0, nint p1);
+
+ }
+
+ internal unsafe string? Authority()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[3];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ AuthorityWasmInterop.wasmImportAuthority(handle, ptr);
+
+ string? lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ lifted = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 4), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 8), 4)));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0]));
+ }
+ return lifted;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SetAuthorityWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.set-authority"), WasmImportLinkage]
+ internal static extern int wasmImportSetAuthority(int p0, int p1, nint p2, int p3);
+
+ }
+
+ internal unsafe void SetAuthority(string? authority)
+ {
+ var handle = this.Handle;
+
+ int lowered;
+ nint lowered3;
+ int lowered4;
+
+ if (authority != null) {
+ var payload2 = (string) authority;
+
+ var result = payload2;
+ IntPtr interopString = InteropString.FromString(result, out int lengthresult);
+
+ lowered = 1;
+ lowered3 = interopString.ToInt32();
+ lowered4 = lengthresult;
+
+ } else {
+
+ lowered = 0;
+ lowered3 = 0;
+ lowered4 = 0;
+
+ }
+ var result5 = SetAuthorityWasmInterop.wasmImportSetAuthority(handle, lowered, lowered3, lowered4);
+
+ Result lifted;
+
+ switch (result5) {
+ case 0: {
+
+ lifted = Result.ok(new global::WasiHttpWorld.None());
+ break;
+ }
+ case 1: {
+
+ lifted = Result.err(new global::WasiHttpWorld.None());
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {result5}");
+ }
+ if (lifted.IsOk) {
+ var tmp = lifted.AsOk;
+ return ;
+ } else {
+ throw new WitException(lifted.AsErr!, 0);
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class HeadersWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]outgoing-request.headers"), WasmImportLinkage]
+ internal static extern int wasmImportHeaders(int p0);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Headers()
+ {
+ var handle = this.Handle;
+ var result = HeadersWasmInterop.wasmImportHeaders(handle);
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result));
+ return resource;
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ }
+
+ /**
+ * 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`.
+ */
+
+ internal class RequestOptions: IDisposable {
+ internal int Handle { get; set; }
+
+ internal readonly record struct THandle(int Handle);
+
+ internal RequestOptions(THandle handle) {
+ Handle = handle.Handle;
+ }
+
+ public void Dispose() {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]request-options"), WasmImportLinkage]
+ private static extern void wasmImportResourceDrop(int p0);
+
+ protected virtual void Dispose(bool disposing) {
+ if (Handle != 0) {
+ wasmImportResourceDrop(Handle);
+ Handle = 0;
+ }
+ }
+
+ ~RequestOptions() {
+ Dispose(false);
+ }
+
+ internal static class ConstructorWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[constructor]request-options"), WasmImportLinkage]
+ internal static extern int wasmImportConstructor();
+
+ }
+
+ internal unsafe RequestOptions()
+ {
+ var result = ConstructorWasmInterop.wasmImportConstructor();
+ this.Handle = result;
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class ConnectTimeoutWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.connect-timeout"), WasmImportLinkage]
+ internal static extern void wasmImportConnectTimeout(int p0, nint p1);
+
+ }
+
+ internal unsafe ulong? ConnectTimeout()
+ {
+ var handle = this.Handle;
+
+ var retArea = new ulong[2];
+ fixed (ulong* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ ConnectTimeoutWasmInterop.wasmImportConnectTimeout(handle, ptr);
+
+ ulong? lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ lifted = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 8), 8))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0]));
+ }
+ return lifted;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SetConnectTimeoutWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.set-connect-timeout"), WasmImportLinkage]
+ internal static extern int wasmImportSetConnectTimeout(int p0, int p1, long p2);
+
+ }
+
+ internal unsafe void SetConnectTimeout(ulong? duration)
+ {
+ var handle = this.Handle;
+
+ int lowered;
+ long lowered3;
+
+ if (duration != null) {
+ var payload2 = (ulong) duration;
+
+ lowered = 1;
+ lowered3 = unchecked((long)(payload2));
+
+ } else {
+
+ lowered = 0;
+ lowered3 = 0L;
+
+ }
+ var result = SetConnectTimeoutWasmInterop.wasmImportSetConnectTimeout(handle, lowered, lowered3);
+
+ Result lifted;
+
+ switch (result) {
+ case 0: {
+
+ lifted = Result.ok(new global::WasiHttpWorld.None());
+ break;
+ }
+ case 1: {
+
+ lifted = Result.err(new global::WasiHttpWorld.None());
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {result}");
+ }
+ if (lifted.IsOk) {
+ var tmp = lifted.AsOk;
+ return ;
+ } else {
+ throw new WitException(lifted.AsErr!, 0);
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class FirstByteTimeoutWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.first-byte-timeout"), WasmImportLinkage]
+ internal static extern void wasmImportFirstByteTimeout(int p0, nint p1);
+
+ }
+
+ internal unsafe ulong? FirstByteTimeout()
+ {
+ var handle = this.Handle;
+
+ var retArea = new ulong[2];
+ fixed (ulong* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ FirstByteTimeoutWasmInterop.wasmImportFirstByteTimeout(handle, ptr);
+
+ ulong? lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ lifted = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 8), 8))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0]));
+ }
+ return lifted;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SetFirstByteTimeoutWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.set-first-byte-timeout"), WasmImportLinkage]
+ internal static extern int wasmImportSetFirstByteTimeout(int p0, int p1, long p2);
+
+ }
+
+ internal unsafe void SetFirstByteTimeout(ulong? duration)
+ {
+ var handle = this.Handle;
+
+ int lowered;
+ long lowered3;
+
+ if (duration != null) {
+ var payload2 = (ulong) duration;
+
+ lowered = 1;
+ lowered3 = unchecked((long)(payload2));
+
+ } else {
+
+ lowered = 0;
+ lowered3 = 0L;
+
+ }
+ var result = SetFirstByteTimeoutWasmInterop.wasmImportSetFirstByteTimeout(handle, lowered, lowered3);
+
+ Result lifted;
+
+ switch (result) {
+ case 0: {
+
+ lifted = Result.ok(new global::WasiHttpWorld.None());
+ break;
+ }
+ case 1: {
+
+ lifted = Result.err(new global::WasiHttpWorld.None());
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {result}");
+ }
+ if (lifted.IsOk) {
+ var tmp = lifted.AsOk;
+ return ;
+ } else {
+ throw new WitException(lifted.AsErr!, 0);
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class BetweenBytesTimeoutWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.between-bytes-timeout"), WasmImportLinkage]
+ internal static extern void wasmImportBetweenBytesTimeout(int p0, nint p1);
+
+ }
+
+ internal unsafe ulong? BetweenBytesTimeout()
+ {
+ var handle = this.Handle;
+
+ var retArea = new ulong[2];
+ fixed (ulong* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ BetweenBytesTimeoutWasmInterop.wasmImportBetweenBytesTimeout(handle, ptr);
+
+ ulong? lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ lifted = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 8), 8))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 0), 1)[0]));
+ }
+ return lifted;
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class SetBetweenBytesTimeoutWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]request-options.set-between-bytes-timeout"), WasmImportLinkage]
+ internal static extern int wasmImportSetBetweenBytesTimeout(int p0, int p1, long p2);
+
+ }
+
+ internal unsafe void SetBetweenBytesTimeout(ulong? duration)
+ {
+ var handle = this.Handle;
+
+ int lowered;
+ long lowered3;
+
+ if (duration != null) {
+ var payload2 = (ulong) duration;
+
+ lowered = 1;
+ lowered3 = unchecked((long)(payload2));
+
+ } else {
+
+ lowered = 0;
+ lowered3 = 0L;
+
+ }
+ var result = SetBetweenBytesTimeoutWasmInterop.wasmImportSetBetweenBytesTimeout(handle, lowered, lowered3);
+
+ Result lifted;
+
+ switch (result) {
+ case 0: {
+
+ lifted = Result.ok(new global::WasiHttpWorld.None());
+ break;
+ }
+ case 1: {
+
+ lifted = Result.err(new global::WasiHttpWorld.None());
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {result}");
+ }
+ if (lifted.IsOk) {
+ var tmp = lifted.AsOk;
+ return ;
+ } else {
+ throw new WitException(lifted.AsErr!, 0);
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ }
+
+ /**
+ * 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`.
+ */
+
+ internal class ResponseOutparam: IDisposable {
+ internal int Handle { get; set; }
+
+ internal readonly record struct THandle(int Handle);
+
+ internal ResponseOutparam(THandle handle) {
+ Handle = handle.Handle;
+ }
+
+ public void Dispose() {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]response-outparam"), WasmImportLinkage]
+ private static extern void wasmImportResourceDrop(int p0);
+
+ protected virtual void Dispose(bool disposing) {
+ if (Handle != 0) {
+ wasmImportResourceDrop(Handle);
+ Handle = 0;
+ }
+ }
+
+ ~ResponseOutparam() {
+ Dispose(false);
+ }
+
+ internal static class SetWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[static]response-outparam.set"), WasmImportLinkage]
+ internal static extern void wasmImportSet(int p0, int p1, int p2, int p3, long p4, nint p5, nint p6, int p7, int p8);
+
+ }
+
+ internal static unsafe void Set(global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ResponseOutparam param, Result response)
+ {
+ var handle = param.Handle;
+ param.Handle = 0;
+
+ int lowered332;
+ int lowered333;
+ int lowered334;
+ long lowered335;
+ nint lowered336;
+ nint lowered337;
+ int lowered338;
+ int lowered339;
+
+ switch (response.Tag) {
+ case 0: {
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.OutgoingResponse payload = response.AsOk;
+ var handle0 = payload.Handle;
+ payload.Handle = 0;
+
+ lowered332 = 0;
+ lowered333 = handle0;
+ lowered334 = 0;
+ lowered335 = 0L;
+ lowered336 = 0;
+ lowered337 = 0;
+ lowered338 = 0;
+ lowered339 = 0;
+
+ break;
+ }
+ case 1: {
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode payload3 = response.AsErr;
+
+ int lowered325;
+ int lowered326;
+ long lowered327;
+ nint lowered328;
+ nint lowered329;
+ int lowered330;
+ int lowered331;
+
+ switch (payload3.Tag) {
+ case 0: {
+
+ lowered325 = 0;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 1: {
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload payload9 = payload3.AsDnsError;
+
+ int lowered;
+ nint lowered16;
+ int lowered17;
+
+ if (payload9.rcode != null) {
+ var payload15 = (string) payload9.rcode;
+
+ var result = payload15;
+ IntPtr interopString = InteropString.FromString(result, out int lengthresult);
+
+ lowered = 1;
+ lowered16 = interopString.ToInt32();
+ lowered17 = lengthresult;
+
+ } else {
+
+ lowered = 0;
+ lowered16 = 0;
+ lowered17 = 0;
+
+ }
+
+ int lowered24;
+ int lowered25;
+
+ if (payload9.infoCode != null) {
+ var payload23 = (ushort) payload9.infoCode;
+
+ lowered24 = 1;
+ lowered25 = payload23;
+
+ } else {
+
+ lowered24 = 0;
+ lowered25 = 0;
+
+ }
+
+ lowered325 = 1;
+ lowered326 = lowered;
+ lowered327 = (long) (lowered16);
+ lowered328 = lowered17;
+ lowered329 = lowered24;
+ lowered330 = lowered25;
+ lowered331 = 0;
+
+ break;
+ }
+ case 2: {
+
+ lowered325 = 2;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 3: {
+
+ lowered325 = 3;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 4: {
+
+ lowered325 = 4;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 5: {
+
+ lowered325 = 5;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 6: {
+
+ lowered325 = 6;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 7: {
+
+ lowered325 = 7;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 8: {
+
+ lowered325 = 8;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 9: {
+
+ lowered325 = 9;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 10: {
+
+ lowered325 = 10;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 11: {
+
+ lowered325 = 11;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 12: {
+
+ lowered325 = 12;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 13: {
+
+ lowered325 = 13;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 14: {
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload payload64 = payload3.AsTlsAlertReceived;
+
+ int lowered71;
+ int lowered72;
+
+ if (payload64.alertId != null) {
+ var payload70 = (byte) payload64.alertId;
+
+ lowered71 = 1;
+ lowered72 = payload70;
+
+ } else {
+
+ lowered71 = 0;
+ lowered72 = 0;
+
+ }
+
+ int lowered81;
+ nint lowered82;
+ int lowered83;
+
+ if (payload64.alertMessage != null) {
+ var payload78 = (string) payload64.alertMessage;
+
+ var result80 = payload78;
+ IntPtr interopString79 = InteropString.FromString(result80, out int lengthresult80);
+
+ lowered81 = 1;
+ lowered82 = interopString79.ToInt32();
+ lowered83 = lengthresult80;
+
+ } else {
+
+ lowered81 = 0;
+ lowered82 = 0;
+ lowered83 = 0;
+
+ }
+
+ lowered325 = 14;
+ lowered326 = lowered71;
+ lowered327 = (long) (lowered72);
+ lowered328 = lowered81;
+ lowered329 = lowered82;
+ lowered330 = lowered83;
+ lowered331 = 0;
+
+ break;
+ }
+ case 15: {
+
+ lowered325 = 15;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 16: {
+
+ lowered325 = 16;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 17: {
+ ulong? payload92 = payload3.AsHttpRequestBodySize;
+
+ int lowered99;
+ long lowered100;
+
+ if (payload92 != null) {
+ var payload98 = (ulong) payload92;
+
+ lowered99 = 1;
+ lowered100 = unchecked((long)(payload98));
+
+ } else {
+
+ lowered99 = 0;
+ lowered100 = 0L;
+
+ }
+
+ lowered325 = 17;
+ lowered326 = lowered99;
+ lowered327 = lowered100;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 18: {
+
+ lowered325 = 18;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 19: {
+
+ lowered325 = 19;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 20: {
+
+ lowered325 = 20;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 21: {
+ uint? payload112 = payload3.AsHttpRequestHeaderSectionSize;
+
+ int lowered119;
+ int lowered120;
+
+ if (payload112 != null) {
+ var payload118 = (uint) payload112;
+
+ lowered119 = 1;
+ lowered120 = unchecked((int)(payload118));
+
+ } else {
+
+ lowered119 = 0;
+ lowered120 = 0;
+
+ }
+
+ lowered325 = 21;
+ lowered326 = lowered119;
+ lowered327 = (long) (lowered120);
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 22: {
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload? payload123 = payload3.AsHttpRequestHeaderSize;
+
+ int lowered149;
+ int lowered150;
+ nint lowered151;
+ int lowered152;
+ int lowered153;
+ int lowered154;
+
+ if (payload123 != null) {
+ var payload129 = (global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload) payload123;
+
+ int lowered138;
+ nint lowered139;
+ int lowered140;
+
+ if (payload129.fieldName != null) {
+ var payload135 = (string) payload129.fieldName;
+
+ var result137 = payload135;
+ IntPtr interopString136 = InteropString.FromString(result137, out int lengthresult137);
+
+ lowered138 = 1;
+ lowered139 = interopString136.ToInt32();
+ lowered140 = lengthresult137;
+
+ } else {
+
+ lowered138 = 0;
+ lowered139 = 0;
+ lowered140 = 0;
+
+ }
+
+ int lowered147;
+ int lowered148;
+
+ if (payload129.fieldSize != null) {
+ var payload146 = (uint) payload129.fieldSize;
+
+ lowered147 = 1;
+ lowered148 = unchecked((int)(payload146));
+
+ } else {
+
+ lowered147 = 0;
+ lowered148 = 0;
+
+ }
+
+ lowered149 = 1;
+ lowered150 = lowered138;
+ lowered151 = lowered139;
+ lowered152 = lowered140;
+ lowered153 = lowered147;
+ lowered154 = lowered148;
+
+ } else {
+
+ lowered149 = 0;
+ lowered150 = 0;
+ lowered151 = 0;
+ lowered152 = 0;
+ lowered153 = 0;
+ lowered154 = 0;
+
+ }
+
+ lowered325 = 22;
+ lowered326 = lowered149;
+ lowered327 = (long) (lowered150);
+ lowered328 = lowered151;
+ lowered329 = lowered152;
+ lowered330 = lowered153;
+ lowered331 = lowered154;
+
+ break;
+ }
+ case 23: {
+ uint? payload157 = payload3.AsHttpRequestTrailerSectionSize;
+
+ int lowered164;
+ int lowered165;
+
+ if (payload157 != null) {
+ var payload163 = (uint) payload157;
+
+ lowered164 = 1;
+ lowered165 = unchecked((int)(payload163));
+
+ } else {
+
+ lowered164 = 0;
+ lowered165 = 0;
+
+ }
+
+ lowered325 = 23;
+ lowered326 = lowered164;
+ lowered327 = (long) (lowered165);
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 24: {
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload payload168 = payload3.AsHttpRequestTrailerSize;
+
+ int lowered177;
+ nint lowered178;
+ int lowered179;
+
+ if (payload168.fieldName != null) {
+ var payload174 = (string) payload168.fieldName;
+
+ var result176 = payload174;
+ IntPtr interopString175 = InteropString.FromString(result176, out int lengthresult176);
+
+ lowered177 = 1;
+ lowered178 = interopString175.ToInt32();
+ lowered179 = lengthresult176;
+
+ } else {
+
+ lowered177 = 0;
+ lowered178 = 0;
+ lowered179 = 0;
+
+ }
+
+ int lowered186;
+ int lowered187;
+
+ if (payload168.fieldSize != null) {
+ var payload185 = (uint) payload168.fieldSize;
+
+ lowered186 = 1;
+ lowered187 = unchecked((int)(payload185));
+
+ } else {
+
+ lowered186 = 0;
+ lowered187 = 0;
+
+ }
+
+ lowered325 = 24;
+ lowered326 = lowered177;
+ lowered327 = (long) (lowered178);
+ lowered328 = lowered179;
+ lowered329 = lowered186;
+ lowered330 = lowered187;
+ lowered331 = 0;
+
+ break;
+ }
+ case 25: {
+
+ lowered325 = 25;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 26: {
+ uint? payload193 = payload3.AsHttpResponseHeaderSectionSize;
+
+ int lowered200;
+ int lowered201;
+
+ if (payload193 != null) {
+ var payload199 = (uint) payload193;
+
+ lowered200 = 1;
+ lowered201 = unchecked((int)(payload199));
+
+ } else {
+
+ lowered200 = 0;
+ lowered201 = 0;
+
+ }
+
+ lowered325 = 26;
+ lowered326 = lowered200;
+ lowered327 = (long) (lowered201);
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 27: {
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload payload204 = payload3.AsHttpResponseHeaderSize;
+
+ int lowered213;
+ nint lowered214;
+ int lowered215;
+
+ if (payload204.fieldName != null) {
+ var payload210 = (string) payload204.fieldName;
+
+ var result212 = payload210;
+ IntPtr interopString211 = InteropString.FromString(result212, out int lengthresult212);
+
+ lowered213 = 1;
+ lowered214 = interopString211.ToInt32();
+ lowered215 = lengthresult212;
+
+ } else {
+
+ lowered213 = 0;
+ lowered214 = 0;
+ lowered215 = 0;
+
+ }
+
+ int lowered222;
+ int lowered223;
+
+ if (payload204.fieldSize != null) {
+ var payload221 = (uint) payload204.fieldSize;
+
+ lowered222 = 1;
+ lowered223 = unchecked((int)(payload221));
+
+ } else {
+
+ lowered222 = 0;
+ lowered223 = 0;
+
+ }
+
+ lowered325 = 27;
+ lowered326 = lowered213;
+ lowered327 = (long) (lowered214);
+ lowered328 = lowered215;
+ lowered329 = lowered222;
+ lowered330 = lowered223;
+ lowered331 = 0;
+
+ break;
+ }
+ case 28: {
+ ulong? payload226 = payload3.AsHttpResponseBodySize;
+
+ int lowered233;
+ long lowered234;
+
+ if (payload226 != null) {
+ var payload232 = (ulong) payload226;
+
+ lowered233 = 1;
+ lowered234 = unchecked((long)(payload232));
+
+ } else {
+
+ lowered233 = 0;
+ lowered234 = 0L;
+
+ }
+
+ lowered325 = 28;
+ lowered326 = lowered233;
+ lowered327 = lowered234;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 29: {
+ uint? payload237 = payload3.AsHttpResponseTrailerSectionSize;
+
+ int lowered244;
+ int lowered245;
+
+ if (payload237 != null) {
+ var payload243 = (uint) payload237;
+
+ lowered244 = 1;
+ lowered245 = unchecked((int)(payload243));
+
+ } else {
+
+ lowered244 = 0;
+ lowered245 = 0;
+
+ }
+
+ lowered325 = 29;
+ lowered326 = lowered244;
+ lowered327 = (long) (lowered245);
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 30: {
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload payload248 = payload3.AsHttpResponseTrailerSize;
+
+ int lowered257;
+ nint lowered258;
+ int lowered259;
+
+ if (payload248.fieldName != null) {
+ var payload254 = (string) payload248.fieldName;
+
+ var result256 = payload254;
+ IntPtr interopString255 = InteropString.FromString(result256, out int lengthresult256);
+
+ lowered257 = 1;
+ lowered258 = interopString255.ToInt32();
+ lowered259 = lengthresult256;
+
+ } else {
+
+ lowered257 = 0;
+ lowered258 = 0;
+ lowered259 = 0;
+
+ }
+
+ int lowered266;
+ int lowered267;
+
+ if (payload248.fieldSize != null) {
+ var payload265 = (uint) payload248.fieldSize;
+
+ lowered266 = 1;
+ lowered267 = unchecked((int)(payload265));
+
+ } else {
+
+ lowered266 = 0;
+ lowered267 = 0;
+
+ }
+
+ lowered325 = 30;
+ lowered326 = lowered257;
+ lowered327 = (long) (lowered258);
+ lowered328 = lowered259;
+ lowered329 = lowered266;
+ lowered330 = lowered267;
+ lowered331 = 0;
+
+ break;
+ }
+ case 31: {
+ string? payload270 = payload3.AsHttpResponseTransferCoding;
+
+ int lowered279;
+ nint lowered280;
+ int lowered281;
+
+ if (payload270 != null) {
+ var payload276 = (string) payload270;
+
+ var result278 = payload276;
+ IntPtr interopString277 = InteropString.FromString(result278, out int lengthresult278);
+
+ lowered279 = 1;
+ lowered280 = interopString277.ToInt32();
+ lowered281 = lengthresult278;
+
+ } else {
+
+ lowered279 = 0;
+ lowered280 = 0;
+ lowered281 = 0;
+
+ }
+
+ lowered325 = 31;
+ lowered326 = lowered279;
+ lowered327 = (long) (lowered280);
+ lowered328 = lowered281;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 32: {
+ string? payload284 = payload3.AsHttpResponseContentCoding;
+
+ int lowered293;
+ nint lowered294;
+ int lowered295;
+
+ if (payload284 != null) {
+ var payload290 = (string) payload284;
+
+ var result292 = payload290;
+ IntPtr interopString291 = InteropString.FromString(result292, out int lengthresult292);
+
+ lowered293 = 1;
+ lowered294 = interopString291.ToInt32();
+ lowered295 = lengthresult292;
+
+ } else {
+
+ lowered293 = 0;
+ lowered294 = 0;
+ lowered295 = 0;
+
+ }
+
+ lowered325 = 32;
+ lowered326 = lowered293;
+ lowered327 = (long) (lowered294);
+ lowered328 = lowered295;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 33: {
+
+ lowered325 = 33;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 34: {
+
+ lowered325 = 34;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 35: {
+
+ lowered325 = 35;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 36: {
+
+ lowered325 = 36;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 37: {
+
+ lowered325 = 37;
+ lowered326 = 0;
+ lowered327 = 0L;
+ lowered328 = 0;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+ case 38: {
+ string? payload313 = payload3.AsInternalError;
+
+ int lowered322;
+ nint lowered323;
+ int lowered324;
+
+ if (payload313 != null) {
+ var payload319 = (string) payload313;
+
+ var result321 = payload319;
+ IntPtr interopString320 = InteropString.FromString(result321, out int lengthresult321);
+
+ lowered322 = 1;
+ lowered323 = interopString320.ToInt32();
+ lowered324 = lengthresult321;
+
+ } else {
+
+ lowered322 = 0;
+ lowered323 = 0;
+ lowered324 = 0;
+
+ }
+
+ lowered325 = 38;
+ lowered326 = lowered322;
+ lowered327 = (long) (lowered323);
+ lowered328 = lowered324;
+ lowered329 = 0;
+ lowered330 = 0;
+ lowered331 = 0;
+
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {payload3}");
+ }
+
+ lowered332 = 1;
+ lowered333 = lowered325;
+ lowered334 = lowered326;
+ lowered335 = lowered327;
+ lowered336 = lowered328;
+ lowered337 = lowered329;
+ lowered338 = lowered330;
+ lowered339 = lowered331;
+
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {response}");
+ }
+ SetWasmInterop.wasmImportSet(handle, lowered332, lowered333, lowered334, lowered335, lowered336, lowered337, lowered338, lowered339);
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ }
+
+ /**
+ * Represents an incoming HTTP Response.
+ */
+
+ internal class IncomingResponse: IDisposable {
+ internal int Handle { get; set; }
+
+ internal readonly record struct THandle(int Handle);
+
+ internal IncomingResponse(THandle handle) {
+ Handle = handle.Handle;
+ }
+
+ public void Dispose() {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]incoming-response"), WasmImportLinkage]
+ private static extern void wasmImportResourceDrop(int p0);
+
+ protected virtual void Dispose(bool disposing) {
+ if (Handle != 0) {
+ wasmImportResourceDrop(Handle);
+ Handle = 0;
+ }
+ }
+
+ ~IncomingResponse() {
+ Dispose(false);
+ }
+
+ internal static class StatusWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-response.status"), WasmImportLinkage]
+ internal static extern int wasmImportStatus(int p0);
+
+ }
+
+ internal unsafe ushort Status()
+ {
+ var handle = this.Handle;
+ var result = StatusWasmInterop.wasmImportStatus(handle);
+ return ((ushort)result);
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class HeadersWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-response.headers"), WasmImportLinkage]
+ internal static extern int wasmImportHeaders(int p0);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields Headers()
+ {
+ var handle = this.Handle;
+ var result = HeadersWasmInterop.wasmImportHeaders(handle);
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(result));
+ return resource;
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class ConsumeWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-response.consume"), WasmImportLinkage]
+ internal static extern void wasmImportConsume(int p0, nint p1);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody Consume()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[2];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ ConsumeWasmInterop.wasmImportConsume(handle, ptr);
+
+ Result lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))));
+
+ lifted = Result.ok(resource);
+ break;
+ }
+ case 1: {
+
+ lifted = Result.err(new global::WasiHttpWorld.None());
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}");
+ }
+ if (lifted.IsOk) {
+ var tmp = lifted.AsOk;
+ return tmp;
+ } else {
+ throw new WitException(lifted.AsErr!, 0);
+ }
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ }
+
+ /**
+ * 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.
+ */
+
+ internal class IncomingBody: IDisposable {
+ internal int Handle { get; set; }
+
+ internal readonly record struct THandle(int Handle);
+
+ internal IncomingBody(THandle handle) {
+ Handle = handle.Handle;
+ }
+
+ public void Dispose() {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]incoming-body"), WasmImportLinkage]
+ private static extern void wasmImportResourceDrop(int p0);
+
+ protected virtual void Dispose(bool disposing) {
+ if (Handle != 0) {
+ wasmImportResourceDrop(Handle);
+ Handle = 0;
+ }
+ }
+
+ ~IncomingBody() {
+ Dispose(false);
+ }
+
+ internal static class StreamWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]incoming-body.stream"), WasmImportLinkage]
+ internal static extern void wasmImportStream(int p0, nint p1);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream Stream()
+ {
+ var handle = this.Handle;
+
+ var retArea = new uint[2];
+ fixed (uint* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ StreamWasmInterop.wasmImportStream(handle, ptr);
+
+ Result lifted;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.InputStream.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 4), 4))));
+
+ lifted = Result.ok(resource);
+ break;
+ }
+ case 1: {
+
+ lifted = Result.err(new global::WasiHttpWorld.None());
+ break;
+ }
+
+ default: throw new ArgumentException($"invalid discriminant: {new Span((void*)(ptr + 0), 1)[0]}");
+ }
+ if (lifted.IsOk) {
+ var tmp = lifted.AsOk;
+ return tmp;
+ } else {
+ throw new WitException(lifted.AsErr!, 0);
+ }
+ }
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class FinishWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[static]incoming-body.finish"), WasmImportLinkage]
+ internal static extern int wasmImportFinish(int p0);
+
+ }
+
+ internal static unsafe global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureTrailers Finish(global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.IncomingBody @this)
+ {
+ var handle = @this.Handle;
+ @this.Handle = 0;
+ var result = FinishWasmInterop.wasmImportFinish(handle);
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureTrailers(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FutureTrailers.THandle(result));
+ return resource;
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ }
+
+ /**
+ * Represents a future which may eventaully 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.
+ */
+
+ internal class FutureTrailers: IDisposable {
+ internal int Handle { get; set; }
+
+ internal readonly record struct THandle(int Handle);
+
+ internal FutureTrailers(THandle handle) {
+ Handle = handle.Handle;
+ }
+
+ public void Dispose() {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[resource-drop]future-trailers"), WasmImportLinkage]
+ private static extern void wasmImportResourceDrop(int p0);
+
+ protected virtual void Dispose(bool disposing) {
+ if (Handle != 0) {
+ wasmImportResourceDrop(Handle);
+ Handle = 0;
+ }
+ }
+
+ ~FutureTrailers() {
+ Dispose(false);
+ }
+
+ internal static class SubscribeWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]future-trailers.subscribe"), WasmImportLinkage]
+ internal static extern int wasmImportSubscribe(int p0);
+
+ }
+
+ internal unsafe global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable Subscribe()
+ {
+ var handle = this.Handle;
+ var result = SubscribeWasmInterop.wasmImportSubscribe(handle);
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable(new global::WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.Pollable.THandle(result));
+ return resource;
+
+ //TODO: free alloc handle (interopString) if exists
+ }
+
+ internal static class GetWasmInterop
+ {
+ [DllImport("wasi:http/types@0.2.0", EntryPoint = "[method]future-trailers.get"), WasmImportLinkage]
+ internal static extern void wasmImportGet(int p0, nint p1);
+
+ }
+
+ internal unsafe Result, None>? Get()
+ {
+ var handle = this.Handle;
+
+ var retArea = new ulong[7];
+ fixed (ulong* retAreaByte0 = &retArea[0])
+ {
+ var ptr = (nint)retAreaByte0;
+ GetWasmInterop.wasmImportGet(handle, ptr);
+
+ Result, None>? lifted205;
+
+ switch (new Span((void*)(ptr + 0), 1)[0]) {
+ case 0: {
+ lifted205 = null;
+ break;
+ }
+
+ case 1: {
+
+ Result, None> lifted204;
+
+ switch (new Span((void*)(ptr + 8), 1)[0]) {
+ case 0: {
+
+ Result lifted201;
+
+ switch (new Span((void*)(ptr + 16), 1)[0]) {
+ case 0: {
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields? lifted;
+
+ switch (new Span((void*)(ptr + 24), 1)[0]) {
+ case 0: {
+ lifted = null;
+ break;
+ }
+
+ case 1: {
+ var resource = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.Fields.THandle(BitConverter.ToInt32(new Span((void*)(ptr + 28), 4))));
+
+ lifted = resource;
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 24), 1)[0]));
+ }
+
+ lifted201 = Result.ok(lifted);
+ break;
+ }
+ case 1: {
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode lifted200;
+
+ switch (new Span((void*)(ptr + 24), 1)[0]) {
+ case 0: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.dnsTimeout();
+ break;
+ }
+ case 1: {
+
+ string? lifted20;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted20 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted20 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4)));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ ushort? lifted25;
+
+ switch (new Span((void*)(ptr + 44), 1)[0]) {
+ case 0: {
+ lifted25 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted25 = ((ushort)BitConverter.ToUInt16(new Span((void*)(ptr + 46), 2)));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.dnsError(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.DnsErrorPayload (
+ lifted20, lifted25));
+ break;
+ }
+ case 2: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationNotFound();
+ break;
+ }
+ case 3: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationUnavailable();
+ break;
+ }
+ case 4: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpProhibited();
+ break;
+ }
+ case 5: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.destinationIpUnroutable();
+ break;
+ }
+ case 6: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionRefused();
+ break;
+ }
+ case 7: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTerminated();
+ break;
+ }
+ case 8: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionTimeout();
+ break;
+ }
+ case 9: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionReadTimeout();
+ break;
+ }
+ case 10: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionWriteTimeout();
+ break;
+ }
+ case 11: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.connectionLimitReached();
+ break;
+ }
+ case 12: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsProtocolError();
+ break;
+ }
+ case 13: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsCertificateError();
+ break;
+ }
+ case 14: {
+
+ byte? lifted56;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted56 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted56 = ((byte)new Span((void*)(ptr + 33), 1)[0]);
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ string? lifted61;
+
+ switch (new Span((void*)(ptr + 36), 1)[0]) {
+ case 0: {
+ lifted61 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted61 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 40), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 44), 4)));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 36), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.tlsAlertReceived(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.TlsAlertReceivedPayload (
+ lifted56, lifted61));
+ break;
+ }
+ case 15: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestDenied();
+ break;
+ }
+ case 16: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestLengthRequired();
+ break;
+ }
+ case 17: {
+
+ ulong? lifted72;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted72 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted72 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 40), 8))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestBodySize(lifted72);
+ break;
+ }
+ case 18: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestMethodInvalid();
+ break;
+ }
+ case 19: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestUriInvalid();
+ break;
+ }
+ case 20: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestUriTooLong();
+ break;
+ }
+ case 21: {
+
+ uint? lifted85;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted85 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted85 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestHeaderSectionSize(lifted85);
+ break;
+ }
+ case 22: {
+
+ global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload? lifted102;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted102 = null;
+ break;
+ }
+
+ case 1: {
+
+ string? lifted96;
+
+ switch (new Span((void*)(ptr + 36), 1)[0]) {
+ case 0: {
+ lifted96 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted96 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 40), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 44), 4)));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 36), 1)[0]));
+ }
+
+ uint? lifted101;
+
+ switch (new Span((void*)(ptr + 48), 1)[0]) {
+ case 0: {
+ lifted101 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted101 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 52), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 48), 1)[0]));
+ }
+
+ lifted102 = new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload (
+ lifted96, lifted101);
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestHeaderSize(lifted102);
+ break;
+ }
+ case 23: {
+
+ uint? lifted109;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted109 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted109 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestTrailerSectionSize(lifted109);
+ break;
+ }
+ case 24: {
+
+ string? lifted116;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted116 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted116 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4)));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ uint? lifted121;
+
+ switch (new Span((void*)(ptr + 44), 1)[0]) {
+ case 0: {
+ lifted121 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted121 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 48), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpRequestTrailerSize(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload (
+ lifted116, lifted121));
+ break;
+ }
+ case 25: {
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseIncomplete();
+ break;
+ }
+ case 26: {
+
+ uint? lifted130;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted130 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted130 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseHeaderSectionSize(lifted130);
+ break;
+ }
+ case 27: {
+
+ string? lifted137;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted137 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted137 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4)));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ uint? lifted142;
+
+ switch (new Span((void*)(ptr + 44), 1)[0]) {
+ case 0: {
+ lifted142 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted142 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 48), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseHeaderSize(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload (
+ lifted137, lifted142));
+ break;
+ }
+ case 28: {
+
+ ulong? lifted149;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted149 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted149 = unchecked((ulong)(BitConverter.ToInt64(new Span((void*)(ptr + 40), 8))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseBodySize(lifted149);
+ break;
+ }
+ case 29: {
+
+ uint? lifted156;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted156 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted156 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 36), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTrailerSectionSize(lifted156);
+ break;
+ }
+ case 30: {
+
+ string? lifted163;
+
+ switch (new Span((void*)(ptr + 32), 1)[0]) {
+ case 0: {
+ lifted163 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted163 = Encoding.UTF8.GetString((byte*)BitConverter.ToInt32(new Span((void*)(ptr + 36), 4)), BitConverter.ToInt32(new Span((void*)(ptr + 40), 4)));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 32), 1)[0]));
+ }
+
+ uint? lifted168;
+
+ switch (new Span((void*)(ptr + 44), 1)[0]) {
+ case 0: {
+ lifted168 = null;
+ break;
+ }
+
+ case 1: {
+
+ lifted168 = unchecked((uint)(BitConverter.ToInt32(new Span((void*)(ptr + 48), 4))));
+ break;
+ }
+
+ default: throw new ArgumentException("invalid discriminant: " + (new Span((void*)(ptr + 44), 1)[0]));
+ }
+
+ lifted200 = global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.ErrorCode.httpResponseTrailerSize(new global::WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.FieldSizePayload (
+ lifted163, lifted168));
+ break;
+ }
+ case 31: {
+
+ string? lifted175;
+
+ switch (new Span