FetchHTTPClient for WASM#154
Merged
Merged
Conversation
Collaborator
Author
large_response_body.movpost.mov |
xbhatnag
commented
May 1, 2026
| return false; | ||
| } | ||
| for i in span.indices { | ||
| bytes.append(span[i]) |
Collaborator
Author
There was a problem hiding this comment.
Online searches suggest I can just do bytes.append(contentsOf: span) but the compiler was not having it, because Span does not implement Sequence?
Still, there's gotta be a better way than adding byte by byte!
xbhatnag
commented
May 1, 2026
guoye-zhang
reviewed
May 1, 2026
guoye-zhang
reviewed
May 2, 2026
guoye-zhang
reviewed
May 2, 2026
guoye-zhang
approved these changes
May 6, 2026
xbhatnag
commented
May 7, 2026
|
|
||
| import PackageDescription | ||
|
|
||
| let enableWASM = Context.environment["SWIFT_ENABLE_WASM_TARGETS"] != nil |
Collaborator
Author
There was a problem hiding this comment.
This environment variable now conditionally adds the WASM targets in for compilation and is disabled by default.
guoye-zhang
reviewed
May 7, 2026
Collaborator
Author
|
I hacked up our Client Conformance Tests to work in WASM with the Test Server hosted out of process. Then I ran the test on Safari + Mac. These tests failed as expected:
These were the unexpected failures that need addressing:
Everything else passed 🎉 |
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.
Motivation
This PR proposes
FetchHTTPClient: a HTTP Client implementation for Swift WASM built on top of Javascript'sfetch()API.Modifications
FetchHTTPClientimplementation ofHTTPClientExamples/WASMClientthat usesFetchHTTPClientto make arbitrary network requests (within the confines of what the browser will allow).Examples/WASMClient/README.mdto explain how to build and run the example program.Note: WASM targets only build when the
HTTP_API_ENABLE_WASMenvironment variable is set on the host system.Feature set
✅ Request and response headers
⚠️ Request bodies (request body is collected upfront prior to the request because some browsers don't support streaming request bodies)
⚠️ URL parsing (
✅ Streamed response bodies
swift-http-typesdoesn't allow scheme-less URLs, which are valid in Javascript, for example:fetch("/index.html"))❌ Request options (there are many options that exist in JS
RequestInitthat still need to be exposed)❌ Trailers (browsers just don't support them)
❌ Swift Task Cancellation (broken because the cancel doesn't propagate to JS
fetch())