Skip to content

Commit 479a311

Browse files
committed
Revert to FetchHandler
1 parent c66b01f commit 479a311

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/Functions/FunctionsClient.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
import Foundation
22

33
public actor FunctionsClient {
4+
public typealias FetchHandler = @Sendable (_ request: URLRequest) async throws -> (
5+
Data, URLResponse
6+
)
7+
48
let url: URL
59
var headers: [String: String]
6-
let session: URLSession
10+
let fetch: FetchHandler
711

812
public init(
913
url: URL,
1014
headers: [String: String] = [:],
11-
session: URLSession = .shared
15+
fetch: @escaping FetchHandler = { try await URLSession.shared.data(for: $0) }
1216
) {
1317
self.url = url
1418
self.headers = headers
1519
self.headers["X-Client-Info"] = "functions-swift/\(version)"
16-
self.session = session
20+
self.fetch = fetch
1721
}
1822

1923
/// Updates the authorization header.
@@ -77,7 +81,7 @@ public actor FunctionsClient {
7781
urlRequest.httpMethod = "POST"
7882
urlRequest.httpBody = invokeOptions.body
7983

80-
let (data, response) = try await session.data(for: urlRequest)
84+
let (data, response) = try await fetch(urlRequest)
8185

8286
guard let httpResponse = response as? HTTPURLResponse else {
8387
throw URLError(.badServerResponse)

0 commit comments

Comments
 (0)