diff --git a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs
index 8681d16fd9fb4b..7834118011a58b 100644
--- a/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs
+++ b/src/libraries/Common/tests/TestUtilities/System/PlatformDetection.Unix.cs
@@ -106,7 +106,7 @@ public static bool OpenSslPresentOnSystem
{
get
{
- if (IsWindows || IsAndroid || UsesMobileAppleCrypto || IsBrowser)
+ if (IsWindows || IsAndroid || UsesMobileAppleCrypto || IsBrowser || IsWasi)
{
return false;
}
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
index db7224a70342d8..f527ad573b8f5d 100644
--- 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
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
using System;
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
index 160183dcd57673..8aeab0a359ef5a 100644
--- 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
@@ -60,7 +60,7 @@ public async Task SendRequestAsync(HttpRequestMessage reque
// we will leave scope of this method
// we need to pass the ownership of the request and this wrapper to the response (via response content stream)
// unless we know that we are not streaming anymore
- incomingStream = new WasiInputStream(this, incomingResponse.Consume());// passing self ownership, passing body ownership
+ incomingStream = new WasiInputStream(this, incomingResponse.Consume(), response);// passing self ownership, passing body ownership
response.Content = new StreamContent(incomingStream); // passing incomingStream ownership to SendAsync() caller
WasiHttpInterop.ConvertResponseHeaders(incomingResponse, response);
@@ -68,10 +68,12 @@ public async Task SendRequestAsync(HttpRequestMessage reque
}
catch (WitException e)
{
+ Dispose();
throw new HttpRequestException(WasiHttpInterop.ErrorCodeToString((ErrorCode)e.Value), e);
}
catch (Exception)
{
+ Dispose();
throw;
}
}
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpInterop.cs
index d9dcee595cb243..47d5a70928ad6b 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpInterop.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpInterop.cs
@@ -178,6 +178,16 @@ public static void ConvertResponseHeaders(IncomingResponse incomingResponse, Htt
}
}
+ public static HttpResponseHeaders ConvertTrailingResponseHeaders(Fields headers)
+ {
+ var result = new HttpResponseHeaders();
+ foreach ((var key, var value) in headers.Entries())
+ {
+ result.Add(key, Encoding.UTF8.GetString(value));
+ }
+ return result;
+ }
+
private static bool IsContentHeader(string headerName)
{
return HeaderDescriptor.TryGet(headerName, out HeaderDescriptor descriptor) && (descriptor.HeaderType & HttpHeaderType.Content) != 0;
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.clocks.v0_2_1.MonotonicClockInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.clocks.v0_2_1.MonotonicClockInterop.cs
index 4eef64ee389e5a..0f08e9800b770a 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.clocks.v0_2_1.MonotonicClockInterop.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.clocks.v0_2_1.MonotonicClockInterop.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.ITypes.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.ITypes.cs
index b65506f194c44f..1a9027b1517c4c 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.ITypes.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.ITypes.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
@@ -605,23 +605,18 @@ internal Fields(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[resource-drop]fields"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~Fields() {
- Dispose(false);
- }
-
internal static class ConstructorWasmInterop
{
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[constructor]fields"), WasmImportLinkage]
@@ -1071,23 +1066,18 @@ internal IncomingRequest(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[resource-drop]incoming-request"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~IncomingRequest() {
- Dispose(false);
- }
-
internal static class MethodWasmInterop
{
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[method]incoming-request.method"), WasmImportLinkage]
@@ -1385,23 +1375,18 @@ internal OutgoingRequest(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[resource-drop]outgoing-request"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~OutgoingRequest() {
- Dispose(false);
- }
-
internal static class ConstructorWasmInterop
{
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[constructor]outgoing-request"), WasmImportLinkage]
@@ -2069,23 +2054,18 @@ internal RequestOptions(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[resource-drop]request-options"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~RequestOptions() {
- Dispose(false);
- }
-
internal static class ConstructorWasmInterop
{
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[constructor]request-options"), WasmImportLinkage]
@@ -2401,23 +2381,18 @@ internal ResponseOutparam(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[resource-drop]response-outparam"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~ResponseOutparam() {
- Dispose(false);
- }
-
internal static class SetWasmInterop
{
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[static]response-outparam.set"), WasmImportLinkage]
@@ -3409,23 +3384,18 @@ internal IncomingResponse(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[resource-drop]incoming-response"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~IncomingResponse() {
- Dispose(false);
- }
-
internal static class StatusWasmInterop
{
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[method]incoming-response.status"), WasmImportLinkage]
@@ -3528,23 +3498,18 @@ internal IncomingBody(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[resource-drop]incoming-body"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~IncomingBody() {
- Dispose(false);
- }
-
internal static class StreamWasmInterop
{
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[method]incoming-body.stream"), WasmImportLinkage]
@@ -3629,23 +3594,18 @@ internal FutureTrailers(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[resource-drop]future-trailers"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~FutureTrailers() {
- Dispose(false);
- }
-
internal static class SubscribeWasmInterop
{
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[method]future-trailers.subscribe"), WasmImportLinkage]
@@ -4353,23 +4313,18 @@ internal OutgoingResponse(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[resource-drop]outgoing-response"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~OutgoingResponse() {
- Dispose(false);
- }
-
internal static class ConstructorWasmInterop
{
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[constructor]outgoing-response"), WasmImportLinkage]
@@ -4535,23 +4490,18 @@ internal OutgoingBody(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[resource-drop]outgoing-body"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~OutgoingBody() {
- Dispose(false);
- }
-
internal static class WriteWasmInterop
{
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[method]outgoing-body.write"), WasmImportLinkage]
@@ -5263,23 +5213,18 @@ internal FutureIncomingResponse(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[resource-drop]future-incoming-response"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~FutureIncomingResponse() {
- Dispose(false);
- }
-
internal static class SubscribeWasmInterop
{
[DllImport("wasi:http/types@0.2.1", EntryPoint = "[method]future-incoming-response.subscribe"), WasmImportLinkage]
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.OutgoingHandlerInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.OutgoingHandlerInterop.cs
index 77435d5b2c7f28..e958a1dfbb2e76 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.OutgoingHandlerInterop.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.OutgoingHandlerInterop.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.TypesInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.TypesInterop.cs
index 8a5802302e148e..bb90a5fba77089 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.TypesInterop.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.http.v0_2_1.TypesInterop.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.ErrorInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.ErrorInterop.cs
index a395aa89033fb0..34c9b9ec0517b1 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.ErrorInterop.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.ErrorInterop.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IError.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IError.cs
index be423962894b5b..e11cf463d7d12b 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IError.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IError.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
@@ -46,23 +46,18 @@ internal Error(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:io/error@0.2.1", EntryPoint = "[resource-drop]error"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~Error() {
- Dispose(false);
- }
-
internal static class ToDebugStringWasmInterop
{
[DllImport("wasi:io/error@0.2.1", EntryPoint = "[method]error.to-debug-string"), WasmImportLinkage]
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IPoll.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IPoll.cs
index b9116711bf03d0..8ec3e7902be2dc 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IPoll.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IPoll.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
@@ -30,23 +30,18 @@ internal Pollable(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:io/poll@0.2.1", EntryPoint = "[resource-drop]pollable"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~Pollable() {
- Dispose(false);
- }
-
internal static class ReadyWasmInterop
{
[DllImport("wasi:io/poll@0.2.1", EntryPoint = "[method]pollable.ready"), WasmImportLinkage]
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IStreams.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IStreams.cs
index 737858ba97f5c1..cb3bf57e93e29b 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IStreams.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.IStreams.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
@@ -73,23 +73,18 @@ internal InputStream(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:io/streams@0.2.1", EntryPoint = "[resource-drop]input-stream"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~InputStream() {
- Dispose(false);
- }
-
internal static class ReadWasmInterop
{
[DllImport("wasi:io/streams@0.2.1", EntryPoint = "[method]input-stream.read"), WasmImportLinkage]
@@ -389,23 +384,18 @@ internal OutputStream(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:io/streams@0.2.1", EntryPoint = "[resource-drop]output-stream"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~OutputStream() {
- Dispose(false);
- }
-
internal static class CheckWriteWasmInterop
{
[DllImport("wasi:io/streams@0.2.1", EntryPoint = "[method]output-stream.check-write"), WasmImportLinkage]
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.PollInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.PollInterop.cs
index 01157399463dd5..dd18170080c644 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.PollInterop.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.PollInterop.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.StreamsInterop.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.StreamsInterop.cs
index 1e2ade74bb38cc..b53cff1046e1b1 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.StreamsInterop.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiHttpWorld.wit.imports.wasi.io.v0_2_1.StreamsInterop.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs
index 95c5577e3b28fb..32aded17ca861b 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/WasiInputStream.cs
@@ -15,6 +15,7 @@ namespace System.Net.Http
// on top of https://github.com/WebAssembly/wasi-io/blob/main/wit/streams.wit
internal sealed class WasiInputStream : Stream
{
+ private HttpResponseMessage response;
private WasiRequestWrapper wrapper; // owned by this instance
private IncomingBody body; // owned by this instance
private InputStream stream; // owned by this instance
@@ -28,11 +29,16 @@ internal sealed class WasiInputStream : Stream
public override bool CanWrite => false;
public override bool CanSeek => false;
- public WasiInputStream(WasiRequestWrapper wrapper, IncomingBody body)
+ public WasiInputStream(
+ WasiRequestWrapper wrapper,
+ IncomingBody body,
+ HttpResponseMessage response
+ )
{
this.wrapper = wrapper;
this.body = body;
this.stream = body.Stream();
+ this.response = response;
}
~WasiInputStream()
@@ -97,7 +103,9 @@ CancellationToken cancellationToken
if (buffer.Length == 0)
{
cancellationToken.ThrowIfCancellationRequested();
- await WasiHttpInterop.RegisterWasiPollable(stream.Subscribe(), cancellationToken).ConfigureAwait(false);
+ await WasiHttpInterop
+ .RegisterWasiPollable(stream.Subscribe(), cancellationToken)
+ .ConfigureAwait(false);
ObjectDisposedException.ThrowIf(isClosed, this);
}
else
@@ -111,6 +119,7 @@ CancellationToken cancellationToken
if (((StreamError)e.Value).Tag == StreamError.CLOSED)
{
otherSideClosed = true;
+ await ReadTrailingHeaders(cancellationToken).ConfigureAwait(false);
return 0;
}
else
@@ -158,6 +167,53 @@ public override async ValueTask ReadAsync(
return result;
}
+ private async Task ReadTrailingHeaders(CancellationToken cancellationToken)
+ {
+ isClosed = true;
+ stream.Dispose();
+ using var futureTrailers = IncomingBody.Finish(body);
+ while (true)
+ {
+ var trailers = futureTrailers.Get();
+ if (trailers is null)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+ await WasiHttpInterop
+ .RegisterWasiPollable(futureTrailers.Subscribe(), cancellationToken)
+ .ConfigureAwait(false);
+ }
+ else
+ {
+ var inner = ((Result, None>)trailers!).AsOk;
+ if (inner.IsOk)
+ {
+ using var headers = inner.AsOk;
+ if (headers is not null)
+ {
+ response.StoreReceivedTrailingHeaders(
+ WasiHttpInterop.ConvertTrailingResponseHeaders(headers)
+ );
+ }
+
+ break;
+ }
+ else if (inner.AsErr.Tag == ErrorCode.CONNECTION_TERMINATED)
+ {
+ // TODO after we upgrade to wasmtime version 25
+ // https://github.com/bytecodealliance/wasmtime/pull/9208
+ // we can remove this, it will return None
+ break;
+ }
+ else
+ {
+ throw new HttpRequestException(
+ WasiHttpInterop.ErrorCodeToString(inner.AsErr)
+ );
+ }
+ }
+ }
+ }
+
#region PlatformNotSupported
public override void Flush()
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.ps1 b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.ps1
index b57834c224208f..b20d69c25ed0bc 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.ps1
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.ps1
@@ -10,7 +10,7 @@ $dir = Split-Path $scriptpath
Push-Location $dir
-cargo install --locked --no-default-features --features csharp --version 0.30.0 wit-bindgen-cli
+cargo install --locked --no-default-features --features csharp --version 0.32.0 wit-bindgen-cli
Invoke-WebRequest -Uri https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.1.tar.gz -OutFile v0.2.1.tar.gz
tar xzf v0.2.1.tar.gz
cp world.wit wasi-http-0.2.1/wit/world.wit
diff --git a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.sh b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.sh
index f79fdbc61bd83f..4f04784676dae6 100644
--- a/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.sh
+++ b/src/libraries/System.Net.Http/src/System/Net/Http/WasiHttpHandler/generate-wasi-http-bindings.sh
@@ -11,7 +11,7 @@ set -ex
# [cargo](https://rustup.rs/)
# [curl](https://curl.se/download.html)
-cargo install --locked --no-default-features --features csharp --version 0.30.0 wit-bindgen-cli
+cargo install --locked --no-default-features --features csharp --version 0.32.0 wit-bindgen-cli
curl -OL https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.1.tar.gz
tar xzf v0.2.1.tar.gz
cp world.wit wasi-http-0.2.1/wit/world.wit
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPoll.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPoll.cs
index f528a5798dbfbf..888adcfe3a3fb5 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPoll.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPoll.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
using System;
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.clocks.v0_2_1.MonotonicClockInterop.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.clocks.v0_2_1.MonotonicClockInterop.cs
index b3c646e7e4bb8a..ed897c94200a96 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.clocks.v0_2_1.MonotonicClockInterop.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.clocks.v0_2_1.MonotonicClockInterop.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_1.IPoll.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_1.IPoll.cs
index fd8a827304a91d..6ab1aef5141478 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_1.IPoll.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_1.IPoll.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
@@ -30,23 +30,18 @@ internal Pollable(THandle handle) {
public void Dispose() {
Dispose(true);
- GC.SuppressFinalize(this);
}
[DllImport("wasi:io/poll@0.2.1", EntryPoint = "[resource-drop]pollable"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {
- if (Handle != 0) {
+ if (disposing && Handle != 0) {
wasmImportResourceDrop(Handle);
Handle = 0;
}
}
- ~Pollable() {
- Dispose(false);
- }
-
internal static class ReadyWasmInterop
{
[DllImport("wasi:io/poll@0.2.1", EntryPoint = "[method]pollable.ready"), WasmImportLinkage]
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_1.PollInterop.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_1.PollInterop.cs
index c403ef10d1ff28..424a42eb82c651 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_1.PollInterop.cs
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/WasiPollWorld.wit.imports.wasi.io.v0_2_1.PollInterop.cs
@@ -1,4 +1,4 @@
-// Generated by `wit-bindgen` 0.30.0. DO NOT EDIT!
+// Generated by `wit-bindgen` 0.32.0. DO NOT EDIT!
//
#nullable enable
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.ps1 b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.ps1
index 0a7cd7bebb7228..ba5675fa1f2350 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.ps1
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.ps1
@@ -10,7 +10,7 @@ $dir = Split-Path $scriptpath
Push-Location $dir
-cargo install --locked --no-default-features --features csharp --version 0.30.0 wit-bindgen-cli
+cargo install --locked --no-default-features --features csharp --version 0.32.0 wit-bindgen-cli
Invoke-WebRequest -Uri https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.1.tar.gz -OutFile v0.2.1.tar.gz
tar xzf v0.2.1.tar.gz
cp world.wit wasi-http-0.2.1/wit/world.wit
diff --git a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.sh b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.sh
index bd32a739d88711..a722eb81fb3f8b 100644
--- a/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.sh
+++ b/src/libraries/System.Private.CoreLib/src/System/Threading/Wasi/generate-wasi-poll-bindings.sh
@@ -11,7 +11,7 @@ set -ex
# [cargo](https://rustup.rs/)
# [curl](https://curl.se/download.html)
-cargo install --locked --no-default-features --features csharp --version 0.30.0 wit-bindgen-cli
+cargo install --locked --no-default-features --features csharp --version 0.32.0 wit-bindgen-cli
curl -OL https://github.com/WebAssembly/wasi-http/archive/refs/tags/v0.2.1.tar.gz
tar xzf v0.2.1.tar.gz
cp world.wit wasi-http-0.2.1/wit/world.wit
diff --git a/src/mono/sample/wasi/http-p2/Program.cs b/src/mono/sample/wasi/http-p2/Program.cs
index 9bf6140161db5b..f73dc682c75915 100644
--- a/src/mono/sample/wasi/http-p2/Program.cs
+++ b/src/mono/sample/wasi/http-p2/Program.cs
@@ -6,7 +6,9 @@
using System.Net.Http;
using System.Threading.Tasks;
using System.Threading;
+using System.Collections.Generic;
using System.Runtime.CompilerServices;
+using System.Net;
// keep in sync with src\mono\wasi\testassets\Http.cs
public static class WasiMainWrapper
@@ -70,6 +72,23 @@ public static async Task MainAsync(string[] args)
Console.WriteLine();
Console.WriteLine(json);
+ // test trailers
+ using (HttpClient httpClient = new HttpClient())
+ {
+ httpClient.DefaultRequestVersion = HttpVersion.Version20;
+ httpClient.DefaultRequestHeaders.Add("TE", "trailers");
+
+ HttpResponseMessage response = await httpClient.GetAsync("http://localhost:5001/weatherforecast");
+
+ var s = await response.Content.ReadAsStringAsync(); //right!
+ Console.WriteLine("A "+s);
+
+ foreach(var (k,v) in response.TrailingHeaders)
+ {
+ Console.WriteLine("B "+k);
+ }
+ }
+
GC.Collect();
return 0;
}