diff --git a/Package.swift b/Package.swift index fc639c7be8..4a81751dd1 100644 --- a/Package.swift +++ b/Package.swift @@ -105,10 +105,10 @@ var dependencies: [Package.Dependency] { [ .package( url: "https://github.com/apple/swift-foundation-icu", - from: "0.0.9"), + branch: "main"), .package( url: "https://github.com/apple/swift-foundation", - revision: "acae3d26b69113cec2db7772b4144ab9558241db") + branch: "main") ] } } diff --git a/Sources/FoundationNetworking/URLSession/NetworkingSpecific.swift b/Sources/FoundationNetworking/URLSession/NetworkingSpecific.swift index c8ae632a45..c07d751526 100644 --- a/Sources/FoundationNetworking/URLSession/NetworkingSpecific.swift +++ b/Sources/FoundationNetworking/URLSession/NetworkingSpecific.swift @@ -35,6 +35,16 @@ internal func NSRequiresConcreteImplementation(_ fn: String = #function, file: S fatalError("\(fn) must be overridden", file: file, line: line) } +extension Data { + @_dynamicReplacement(for: init(_contentsOfRemote:options:)) + private init(_contentsOfRemote_foundationNetworking url: URL, options: Data.ReadingOptions = []) throws { + let (nsData, _) = try _NSNonfileURLContentLoader().contentsOf(url: url) + self = withExtendedLifetime(nsData) { + return Data(bytes: nsData.bytes, count: nsData.length) + } + } +} + @usableFromInline class _NSNonfileURLContentLoader: _NSNonfileURLContentLoading, @unchecked Sendable { @usableFromInline diff --git a/Tests/Foundation/TestURL.swift b/Tests/Foundation/TestURL.swift index 9aff650183..c10d4963cd 100644 --- a/Tests/Foundation/TestURL.swift +++ b/Tests/Foundation/TestURL.swift @@ -775,6 +775,18 @@ class TestURL : XCTestCase { throw error } } + + func test_dataFromNonFileURL() { + do { + // Tests the up-call to FoundationNetworking to perform the network request + try Data(contentsOf: URL(string: "https://swift.org")!) + } catch { + if let cocoaCode = (error as? CocoaError)?.code { + // Just ensure that we supported this feature, even if the request failed + XCTAssertNotEqual(cocoaCode, .featureUnsupported) + } + } + } // MARK: -