Skip to content

Move iOS to swift-nio-http3 and add HTTP/3 datagram sessions - #9

Draft
gartnera wants to merge 1 commit into
mainfrom
claude/quirky-feynman-7rnekj
Draft

gartnera wants to merge 1 commit into
mainfrom
claude/quirky-feynman-7rnekj

Conversation

@gartnera

Copy link
Copy Markdown
Member

Draft for tracking. Not ready to merge: iOS loses its HTTP/2 fallback (see "Open questions").

What

  • iOS bridge on swift-nio-http3. The bridge (HTTP3Bridge.swift) now runs on swift-nio-http3 and swift-nio-quic instead of URLSession, which has no HTTP datagram API. It keeps the same method and event channel protocol and still reports failures in NSURLErrorDomain codes.
  • Datagram sessions (iOS). NativeHttpClient.openDatagramSession(url, protocol:, headers:) opens an Extended CONNECT stream (RFC 9220) that carries HTTP datagrams (RFC 9297), and returns a DatagramSession with datagrams, send, close, cancel and done. On Android it throws UnsupportedError, because Cronet has no datagram API.
  • Config. quicIdleTimeout now applies on iOS too, and a new iOS-only connectTimeout defaults to 10 s.
  • Test server. Adds /datagrams/echo and sets EnableDatagrams on its http3.Server.
  • CI. The Swift core builds without Apple SDKs, so its tests now run on Linux in swift:6.4.2-noble.
  • Removed. The Connect end-stream detector and the URLSession header fixups, which only URLSession needed.

Behavior changes on iOS

  • iOS 27 minimum, and apps need Xcode 27. Every swift-nio-http3 API requires iOS 27 (@available(anyAppleOS 27, *)).
  • HTTP/3 only. If UDP is blocked, every call fails as notSent. http3Origins is ignored on iOS.
  • No untrusted failures. The QUIC stack closes any failed TLS handshake with CRYPTO_ERROR 0x100 and no detail, so a rejected certificate reports as -1200 and is classified notSent.
  • No write backpressure. swift-nio-quic completes a stream write as soon as it has buffered it.
  • Pinned dependency. swift-nio-http3 has no release yet, so it's pinned to commit 58ba11b.
  • STOP_SENDING workaround. Without swift-nio-quic's halfCloseOnStopSending option, a server's STOP_SENDING closes the whole stream, response included, and swift-nio-http3 hits an assertion in HTTP3StreamStateMachine.inputClosed. The bridge sets the option on every request stream. Upstream PR apple/swift-nio-http3#104 (open) addresses the same problem.

Verification

  • Swift core tests on Linux: 16 tests passed 8 runs out of 8 with Swift 6.4.2, against the Go test server (quic-go).
  • Not verified:
    • The iOS simulator integration job, which needs a runner with Xcode 27 and an iOS 27 simulator.
    • The plugin build under Flutter on iOS.
    • Any device run.

Open questions

  • HTTP/2 fallback. No higher-level NIO client falls back from HTTP/3 to HTTP/2. AsyncHTTPClient supports HTTP/1.1 and HTTP/2 only (no HTTP/3 or QUIC in its sources as of commit d2dfb39, 2026-10-30), and swift-nio-http3 has no fallback logic. The options are:
    • Hybrid: keep URLSession for RPCs, which also keeps iOS 15+, and use NIO only for datagram sessions.
    • Own fallback: add a fallback to AsyncHTTPClient over HTTP/2 inside the bridge, reported through onResponse rather than silent.
  • Haystack. haystack's NativeCloudHttp relies on the platform's HTTP/2 fallback, and its server needs EnableDatagrams in web/go/internal/rpc/tls_server.go before datagram sessions can open.

Generated by Claude Code

The iOS bridge now runs on swift-nio-http3 and swift-nio-quic instead of
URLSession, which has no HTTP datagram API. It keeps the method and event
channel protocol, reports failures in NSURLErrorDomain codes, and adds
openDatagrams / sendDatagram / datagram events: an Extended CONNECT
(RFC 9220) stream carrying HTTP datagrams (RFC 9297).

- Dart: NativeHttpClient.openDatagramSession returning a DatagramSession;
  Android (Cronet) throws UnsupportedError. NativeHttpConfig gains
  connectTimeout (iOS), and quicIdleTimeout now applies on iOS too.
- iOS now needs iOS 27 (the libraries' availability) and speaks HTTP/3 only:
  no HTTP/2 fallback. A rejected certificate is reported as -1200 (notSent),
  since the QUIC stack doesn't say why a TLS handshake failed. Writes have no
  backpressure: swift-nio-quic completes them once buffered.
- Request streams set halfCloseOnStopSending: without it, a server's
  STOP_SENDING closes the whole stream and swift-nio-http3 asserts.
- The Swift core builds on Linux; CI runs its tests in swift:6.4.2 against
  the Go test server, which gains a /datagrams/echo endpoint.
- Removed the Connect end-stream detector and URLSession header fixups,
  which only URLSession needed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BqmpXUbxP9wUhn1EyGGpc6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants