Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
]
}
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/FoundationNetworking/URLSession/NetworkingSpecific.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions Tests/Foundation/TestURL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,11 @@ class TestURL : XCTestCase {
throw error
}
}

func test_dataFromNonFileURL() throws {
// Tests the up-call to FoundationNetworking to perform the network request
XCTAssertNoThrow(try Data(contentsOf: URL(string: "https://swift.org")!))
}

// MARK: -

Expand Down