From cb3416740888bced077532e44ec99e0b597d5935 Mon Sep 17 00:00:00 2001 From: Guoye Zhang Date: Wed, 22 Jan 2025 15:43:45 -0800 Subject: [PATCH 1/3] [Proposal] New HTTP loader for URLSession --- Proposals/NNNN-urlsession-new-loader.md | 111 ++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 Proposals/NNNN-urlsession-new-loader.md diff --git a/Proposals/NNNN-urlsession-new-loader.md b/Proposals/NNNN-urlsession-new-loader.md new file mode 100644 index 000000000..a7e058f5b --- /dev/null +++ b/Proposals/NNNN-urlsession-new-loader.md @@ -0,0 +1,111 @@ +# New HTTP loader for URLSession + +* Proposal: [SF-NNNN](NNNN-urlsession-new-loader.md) +* Authors: [Guoye Zhang](https://github.com/guoye-zhang) +* Review Manager: TBD +* Status: **Awaiting review** +* Implementation: [swiftlang/swift-corelibs-foundation#5162](https://github.com/swiftlang/swift-corelibs-foundation/pull/5162) +* Review: ([pitch](https://forums.swift.org/...)) + +## Introduction + +The new HTTP stack built in Network framework was enabled in Safari on iOS 18 and macOS Sequoia. It supports new features like 0-RTT early data, oblivious HTTP, WebSocket over HTTP/2, and unix domain socket. Support for FTP and HTTP/1 pipelining was dropped. + +In this proposal, we are introducing an API to enable the new HTTP loader in URLSession on Darwin, as well as deprecating several legacy features not supported in the new stack. + +## Proposed solution + +Introducing a new flag `usesClassicLoadingMode` that defaults to true on URLSessionConfiguration to allow developers to opt-in to the new stack. + +The flag is not available on non-Darwin platforms at this moment. + +## Detailed design + +### Opt-in flag + +The new loader is enabled when `usesClassicLoadingMode` is set to false. `usesClassicLoadingMode` currently defaults to true, but might default to false in a future OS. + +```swift +open class URLSessionConfiguration { + + /* Uses the classic network loader */ + @available(*, unavailable, message: "Not available on non-Darwin platforms") + open var usesClassicLoadingMode: Bool +} +``` + +### Deprecations + +* FTP was deprecated in the old stack and unsupported in the new stack. +* HTTP/1 pipelining is not supported in the new HTTP stack. It is disabled by default in the old stack and has known compatibility issues with some servers. +* Server push was disabled in both stacks on iOS 17 and aligned releases due to low adoption and web compatibility issues. +* `NSURLErrorFailingURLStringErrorKey` is redundant with `NSURLErrorFailingURLErrorKey` and it is incompatible with WHATWG URLs. +* `shouldUseExtendedBackgroundIdleMode` was not supported in either the old stack or the new stack. + +```swift +public struct URLRequest { + + @available(swift, deprecated: 6.1, message: "HTTP/1 pipelining has known compatibility issues, please adopt HTTP/2 and HTTP/3 instead") + public var httpShouldUsePipelining: Bool +} + +open class NSURLRequest { + + @available(swift, deprecated: 6.1, message: "HTTP/1 pipelining has known compatibility issues, please adopt HTTP/2 and HTTP/3 instead") + open var httpShouldUsePipelining: Bool { get } +} + +open class NSMutableURLRequest { + + @available(swift, deprecated: 6.1, message: "HTTP/1 pipelining has known compatibility issues, please adopt HTTP/2 and HTTP/3 instead") + open override var httpShouldUsePipelining: Bool +} + +open class URLSessionConfiguration { + + @available(swift, deprecated: 6.1, message: "HTTP/1 pipelining has known compatibility issues, please adopt HTTP/2 and HTTP/3 instead") + open var httpShouldUsePipelining: Bool + + @available(swift, deprecated: 6.1, message: "Not supported") + open var shouldUseExtendedBackgroundIdleMode: Bool +} + +public enum URLSessionTaskMetrics.ResourceFetchType { + + @available(swift, deprecated: 6.1, message: "Server push is not supported") + case serverPush +} + +public struct URLError { + + @available(swift, deprecated: 6.1, message: "Use failingURL instead") + public var failureURLString: String? +} + +@available(swift, deprecated: 6.1, message: "Use NSURLErrorFailingURLErrorKey instead") +public let NSURLErrorFailingURLStringErrorKey: String + +@available(swift, deprecated: 6.1, message: "FTP is deprecated") +public let NSURLProtectionSpaceFTP: String + +@available(swift, deprecated: 6.1, message: "FTP is deprecated") +public let NSURLProtectionSpaceFTPProxy: String +``` + +## Source compatibility + +No impact. + +## Implications on adoption + +This feature can be freely adopted and un-adopted in source code with no deployment constraints and without affecting source compatibility. + +## Future directions + +The new HTTP stack might become the default on a future Darwin release. + +## Alternatives considered + +### Alternative spelling `usesNewLoader` + +The initial idea was an opt-in flag where YES means the new loader, and we considered multiple variants, including `usesModernLoader`, `usesNWLoader` (NW stands for Network framework). However, this makes it hard to come up with names for newer loaders in the future, and an opt-out flag gives the impression that the new loader is the default, not the exception. From e24966c7331ce113bb5efe58db74f75f8e441f39 Mon Sep 17 00:00:00 2001 From: Guoye Zhang Date: Tue, 4 Feb 2025 12:13:44 -0800 Subject: [PATCH 2/3] Update number --- ...lsession-new-loader.md => 0018-urlsession-new-loader.md} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename Proposals/{NNNN-urlsession-new-loader.md => 0018-urlsession-new-loader.md} (95%) diff --git a/Proposals/NNNN-urlsession-new-loader.md b/Proposals/0018-urlsession-new-loader.md similarity index 95% rename from Proposals/NNNN-urlsession-new-loader.md rename to Proposals/0018-urlsession-new-loader.md index a7e058f5b..77a2e3d03 100644 --- a/Proposals/NNNN-urlsession-new-loader.md +++ b/Proposals/0018-urlsession-new-loader.md @@ -1,11 +1,11 @@ # New HTTP loader for URLSession -* Proposal: [SF-NNNN](NNNN-urlsession-new-loader.md) +* Proposal: [SF-0018](0018-urlsession-new-loader.md) * Authors: [Guoye Zhang](https://github.com/guoye-zhang) -* Review Manager: TBD +* Review Manager: [Tina L](https://github.com/itingliu) * Status: **Awaiting review** * Implementation: [swiftlang/swift-corelibs-foundation#5162](https://github.com/swiftlang/swift-corelibs-foundation/pull/5162) -* Review: ([pitch](https://forums.swift.org/...)) +* Review: ([pitch](https://forums.swift.org/t/pitch-new-http-loader-for-urlsession-on-darwin/77440)) ## Introduction From 3021ac6abd60c9ce2d4bbe75d997ba03ca256d62 Mon Sep 17 00:00:00 2001 From: Guoye Zhang Date: Mon, 10 Feb 2025 14:27:52 -0800 Subject: [PATCH 3/3] Update status --- Proposals/0018-urlsession-new-loader.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Proposals/0018-urlsession-new-loader.md b/Proposals/0018-urlsession-new-loader.md index 77a2e3d03..852c9e75c 100644 --- a/Proposals/0018-urlsession-new-loader.md +++ b/Proposals/0018-urlsession-new-loader.md @@ -3,7 +3,7 @@ * Proposal: [SF-0018](0018-urlsession-new-loader.md) * Authors: [Guoye Zhang](https://github.com/guoye-zhang) * Review Manager: [Tina L](https://github.com/itingliu) -* Status: **Awaiting review** +* Status: **Accepted** * Implementation: [swiftlang/swift-corelibs-foundation#5162](https://github.com/swiftlang/swift-corelibs-foundation/pull/5162) * Review: ([pitch](https://forums.swift.org/t/pitch-new-http-loader-for-urlsession-on-darwin/77440))