File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change 1
1
import Foundation
2
2
3
3
public actor FunctionsClient {
4
+ public typealias FetchHandler = @Sendable ( _ request: URLRequest ) async throws -> (
5
+ Data , URLResponse
6
+ )
7
+
4
8
let url : URL
5
9
var headers : [ String : String ]
6
- let session : URLSession
10
+ let fetch : FetchHandler
7
11
8
12
public init (
9
13
url: URL ,
10
14
headers: [ String : String ] = [ : ] ,
11
- session : URLSession = . shared
15
+ fetch : @escaping FetchHandler = { try await URLSession . shared. data ( for : $0 ) }
12
16
) {
13
17
self . url = url
14
18
self . headers = headers
15
19
self . headers [ " X-Client-Info " ] = " functions-swift/ \( version) "
16
- self . session = session
20
+ self . fetch = fetch
17
21
}
18
22
19
23
/// Updates the authorization header.
@@ -77,7 +81,7 @@ public actor FunctionsClient {
77
81
urlRequest. httpMethod = " POST "
78
82
urlRequest. httpBody = invokeOptions. body
79
83
80
- let ( data, response) = try await session . data ( for : urlRequest)
84
+ let ( data, response) = try await fetch ( urlRequest)
81
85
82
86
guard let httpResponse = response as? HTTPURLResponse else {
83
87
throw URLError ( . badServerResponse)
You can’t perform that action at this time.
0 commit comments