Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara committed Jul 1, 2024
1 parent ca5b8e1 commit 8808137
Show file tree
Hide file tree
Showing 27 changed files with 9,680 additions and 19 deletions.
17 changes: 16 additions & 1 deletion src/libraries/System.Net.Http/src/System.Net.Http.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,22 @@
Link="Common\System\Net\Http\HttpHandlerDefaults.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetPlatformIdentifier)' == 'wasi'">
<Reference Include="System.Threading.Thread" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttpHandler.cs" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttp.cs" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttpWorld.wit.imports.wasi.clocks.v0_2_0.MonotonicClockInterop.cs" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttpWorld.wit.imports.wasi.http.v0_2_0.ITypes.cs" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttpWorld.wit.imports.wasi.http.v0_2_0.OutgoingHandlerInterop.cs" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttpWorld.wit.imports.wasi.http.v0_2_0.TypesInterop.cs" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttpWorld.wit.imports.wasi.io.v0_2_0.ErrorInterop.cs" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IError.cs" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IPoll.cs" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttpWorld.wit.imports.wasi.io.v0_2_0.IStreams.cs" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttpWorld.wit.imports.wasi.io.v0_2_0.PollInterop.cs" />
<Compile Include="System\Net\Http\WasiHttpHandler\WasiHttpWorld.wit.imports.wasi.io.v0_2_0.StreamsInterop.cs" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.Win32.Primitives" />
<Reference Include="System.Collections.NonGeneric" />
Expand Down Expand Up @@ -505,5 +521,4 @@
<ItemGroup>
<None Include="Resources\SR.resx" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 MetricsHandler? _metricsHandler;

Expand Down Expand Up @@ -90,7 +94,7 @@ protected override void Dispose(bool disposing)
[CLSCompliant(false)]
public IMeterFactory? MeterFactory
{
#if TARGET_BROWSER
#if TARGET_BROWSER || TARGET_WASI
get => _meterFactory;
set
{
Expand Down Expand Up @@ -258,14 +262,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
Expand Down Expand Up @@ -296,7 +300,7 @@ public X509CertificateCollection ClientCertificates
[UnsupportedOSPlatform("browser")]
public Func<HttpRequestMessage, X509Certificate2?, X509Chain?, SslPolicyErrors, bool>? ServerCertificateCustomValidationCallback
{
#if TARGET_BROWSER
#if TARGET_BROWSER || TARGET_WASI
get => throw new PlatformNotSupportedException();
set => throw new PlatformNotSupportedException();
#else
Expand Down Expand Up @@ -345,7 +349,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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// Generated by `wit-bindgen` 0.26.0. DO NOT EDIT!
// <auto-generated />
#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<Ok, Err>
{
internal readonly byte Tag;
private readonly object value;

private Result(byte tag, object value)
{
Tag = tag;
this.value = value;
}

internal static Result<Ok, Err> ok(Ok ok)
{
return new Result<Ok, Err>(OK, ok!);
}

internal static Result<Ok, Err> err(Err err)
{
return new Result<Ok, Err>(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<T> {
private static Option<T> none = new ();

private Option()
{
HasValue = false;
}

internal Option(T v)
{
HasValue = true;
Value = v;
}

internal static Option<T> 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
{
}
}

}
Loading

0 comments on commit 8808137

Please sign in to comment.