Skip to content

Commit 4f5c7b2

Browse files
committed
http sample
1 parent e9cc7a0 commit 4f5c7b2

File tree

3 files changed

+71
-3
lines changed

3 files changed

+71
-3
lines changed

src/mono/sample/wasi/Directory.Build.targets

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
-->
1717
<Exec WorkingDirectory="bin/wasi-wasm/AppBundle"
1818
Condition="'$(WasmBuildNative)' != 'true'"
19-
Command="$(WasmtimeDir)wasmtime$(_ExeExt) $(MONO_LOG_LEVEL) --dir . dotnet.wasm $(_SampleProjectName)" IgnoreExitCode="true" />
19+
Command="$(WasmtimeDir)wasmtime$(_ExeExt) $(MONO_LOG_LEVEL) -S http --dir . dotnet.wasm $(_SampleProjectName)" IgnoreExitCode="true" />
2020
<Exec WorkingDirectory="bin/wasi-wasm/AppBundle"
2121
Condition="'$(WasmBuildNative)' == 'true' and '$(WasmSingleFileBundle)' != 'true'"
22-
Command="$(WasmtimeDir)wasmtime$(_ExeExt) $(MONO_LOG_LEVEL) --dir . dotnet.wasm" IgnoreExitCode="true" />
22+
Command="$(WasmtimeDir)wasmtime$(_ExeExt) $(MONO_LOG_LEVEL) -S http --dir . dotnet.wasm" IgnoreExitCode="true" />
2323
<Exec WorkingDirectory="bin/wasi-wasm/AppBundle"
2424
Condition="'$(WasmSingleFileBundle)' == 'true'"
25-
Command="$(WasmtimeDir)wasmtime$(_ExeExt) $(MONO_LOG_LEVEL) $([System.IO.Path]::ChangeExtension($(_SampleAssembly), '.wasm'))" IgnoreExitCode="true" />
25+
Command="$(WasmtimeDir)wasmtime$(_ExeExt) $(MONO_LOG_LEVEL) -S http $([System.IO.Path]::ChangeExtension($(_SampleAssembly), '.wasm'))" IgnoreExitCode="true" />
2626
</Target>
2727

2828
<Import Project="$(RepositoryEngineeringDir)testing\wasi-provisioning.targets" />
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Net.Http.Headers;
6+
using System.Net.Http;
7+
using System.Threading.Tasks;
8+
using System.Threading;
9+
using System.Runtime.CompilerServices;
10+
11+
public class Test
12+
{
13+
public static int Main(string[] args)
14+
{
15+
var task = Work();
16+
while (!task.IsCompleted)
17+
{
18+
WasiEventLoop.DispatchWasiEventLoop();
19+
}
20+
var exception = task.Exception;
21+
if (exception is not null)
22+
{
23+
throw exception;
24+
}
25+
26+
return 0;
27+
}
28+
29+
public static async Task Work()
30+
{
31+
using HttpClient client = new();
32+
client.Timeout = Timeout.InfiniteTimeSpan;
33+
client.DefaultRequestHeaders.Accept.Clear();
34+
client.DefaultRequestHeaders.Accept.Add(
35+
new MediaTypeWithQualityHeaderValue("application/vnd.github.v3+json"));
36+
client.DefaultRequestHeaders.Add("User-Agent", ".NET Foundation Repository Reporter");
37+
38+
var query="https://api.github.com/orgs/dotnet/repos?per_page=1";
39+
var json = await client.GetStringAsync(query);
40+
41+
Console.WriteLine();
42+
Console.WriteLine("GET "+query);
43+
Console.WriteLine();
44+
Console.WriteLine(json);
45+
}
46+
47+
private static class WasiEventLoop
48+
{
49+
internal static void DispatchWasiEventLoop()
50+
{
51+
CallDispatchWasiEventLoop((Thread)null!);
52+
53+
[UnsafeAccessor(UnsafeAccessorKind.StaticMethod, Name = "DispatchWasiEventLoop")]
54+
static extern void CallDispatchWasiEventLoop(Thread t);
55+
}
56+
}
57+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
4+
<!--
5+
<WasmSingleFileBundle>true</WasmSingleFileBundle>
6+
<InvariantGlobalization>true</InvariantGlobalization>
7+
-->
8+
</PropertyGroup>
9+
10+
<Target Name="RunSample" DependsOnTargets="RunSampleWithWasmtime" />
11+
</Project>

0 commit comments

Comments
 (0)