Repository navigation
[wasi] Fix WasiHttpHandler request failures, disposal and header handling - #136261
Merged
Merged
Conversation
Throw InvalidOperationException/NotSupportedException for missing, relative or unsupported request URIs, translate wasi:io stream errors on the response body into HttpIOException(ResponseEnded), and report CanRead=false after the response stream is disposed. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Observe the request-content send task while waiting for the response, so a failure in the content (or its cancellation) fails the request with the original exception instead of hanging until HttpClient.Timeout. Also: - abort, rather than finish, the outgoing body when the request wrapper is disposed before the content completes; - release pending wasi:io pollables before dropping request/response streams, avoiding the 'resource has children' trap; - translate TransferEncodingChunked into a body without Content-Length, since wasi:http forbids the Transfer-Encoding header, and send Content-Length for content of known length. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: Successfully started running 4 pipeline(s). 12 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
Contributor
|
Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara |
pavelsavara
self-requested a review
October 22, 2026 09:50
lewing
marked this pull request as ready for review
October 24, 2026 02:56
Member
Author
|
I have a full test standup for this that needs to stack on the socketshttphandler/websocket pr that demonstrated the need for this. |
Member
Author
|
#136684 has the test support for WasiHttpHandler |
pavelsavara
approved these changes
Oct 30, 2026
lewing
added a commit
that referenced
this pull request
Nov 13, 2026
Since #136234 (and with the handler fixes from #136261), `System.Net.Http.Functional.Tests` sets `UseNativeHttpHandler=false` on WASI, so it covers SocketsHttpHandler. The switch is process-wide and trimmed, so one assembly can't also test the `wasi:http` handler (`WasiHttpHandler`). This adds a WASI-only test project, `System.Net.Http.WasiHttpHandler.Functional.Tests`, that leaves the switch at its WASI default (true). ### Test project The project adds `WasiHttpHandler_*` classes for these shared test bases: - HttpClientHandlerTest - Asynchrony - Cancellation - IdnaProtocolTests - PostScenarioTest - ResponseStreamTest It also includes `HttpClientHandler_RemoteServerTest`. PostScenarioTest and RemoteServerTest are OuterLoop on WASI. The existing `tests.proj` glob picks the project up, which adds one Helix work item. ### Skips - **Capability gates:** - The AutoRedirect, Decompression, Proxy and DefaultProxyCredentials classes use `ConditionalClass` on `SupportsRedirectConfiguration`, `SupportsAutomaticDecompression` and `SupportsProxy`. Those probes now live in the shared `HttpClientHandlerTestBase`. - In-body checks cover the same capabilities. - **`IsWasiHttpHandler`** (alongside `IsWinHttpHandler`) adds early returns for handler gaps with no public capability flag: - Credentials and PreAuthenticate - CookieContainer - MaxConnectionsPerServer - redirect following - synchronous stream I/O - **Host behaviour:** wasmtime's `wasi:http` behaviour is also gated: - It forbids hop-by-hop request headers and control characters. - It strips hop-by-hop response headers and rejects obs-fold. - It doesn't expose the reason phrase or let the client choose the HTTP version. - **Outerloop helpers:** - MD5 checks are gated on `PlatformDetection.IsMD5Supported`, using the echo server's existing `Content-MD5-Skip` path. - The HTTPS/HTTP2 local echo endpoints are dropped on WASI, which doesn't trust their dev certificate. HttpProtocolTests isn't included: it checks status-line parsing that the `wasi:http` host performs, and Browser excludes it too. ### Validation CoreCLR WASI, Release, wasmtime 49.0.1, on main `a932cb67bf6`: | Suite | Run | Passed | Failed | Skipped | |---|---|---|---|---| | `System.Net.Http.WasiHttpHandler.Functional.Tests` | 195 | 184 | 0 | 11 | | `System.Net.Http.Functional.Tests` (shared test changes) | 1994 | 1810 | 0 | 184 | Outerloop was validated before the rebase onto current main: 311 of 325 tests passed, with 0 failures, with every class except the two `SupportsProxy`-gated proxy classes. Running the full outerloop scope still runs those proxy classes. WasmTestRunner lets `-trait category=OuterLoop` override `-notrait category=failing`, so `ConditionalClass`-gated classes run anyway. That's a separate runner issue affecting all WASI/browser projects. The WASI outerloop CI leg currently runs innerloop scope only. > [!NOTE] > This PR description and the changes were generated with GitHub Copilot. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes several WasiHttpHandler (the
wasi:httphandler used byHttpClientHandleron WASI) behaviors that made failures hang or surface the wrong exception.Request content failures hang until timeout.
SendContentwas started fire-and-forget, so if serializing the request content threw or was canceled, nothing observed it and the request waited for a response untilHttpClient.Timeout(100s). The handler now watches the send task while polling for the response and fails the request with the content's exception.Dispose hides the real exception.
Stream.Dispose()called theWasiOutputStream.Close()override, which finished the outgoing body. After a content failure, that threw aWitExceptionfromOutgoingBody.Finish, which replaced the original exception. Completing the body is now an explicitFinish(), and disposing an unfinished stream aborts the body.Pending-pollable disposal trap. Dropping a request or response stream while a read or write pollable (a child resource) was still registered trapped wasmtime with
resource has childrenand killed the process. The streams now cancel their pending wait before dropping the stream.Chunked / Content-Length.
wasi:httpforbids theTransfer-Encodingheader, soTransferEncodingChunked = truefailed header validation. It now omits the header (andContent-Length) and lets the host chunk the body, and chunked encoding without content throwsInvalidOperationExceptionlike SocketsHttpHandler. For content with a known length,Content-Lengthis now computed and sent.Exception types aligned with SocketsHttpHandler.
InvalidOperationException, and non-http(s) schemes throwNotSupportedException; both used to throwArgumentException.wasi:iostream errors while reading the response body now throwHttpIOException(HttpRequestError.ResponseEnded)instead of a rawWitException.CanReadisfalseafter the response stream is disposed.Validation
CoreCLR WASI, Release, wasmtime 49.0.1. Each run was done against a baseline build of the same
maincommit without these changes.System.Net.Http.Functional.TestsinnerloopHttpClientHandler_RemoteServerTest,SocketsHttpHandler_PostScenarioTest,SocketsHttpHandler_ResponseStreamTestSendAsync_SendSameRequestMultipleTimesDirectlyOnHandler_Successnow passes (2 cases) becauseContent-Lengthis sent.main, the sharedHttpClientHandlerTestbodies don't run against this handler on WASI. They're exercised by a follow-up WASI-only WasiHttpHandler test project, where the request-content-failure, cancellation and response-stream tests pass with these changes.Note
This PR description and the changes were generated with GitHub Copilot.