File tree Expand file tree Collapse file tree 2 files changed +43
-34
lines changed Expand file tree Collapse file tree 2 files changed +43
-34
lines changed Original file line number Diff line number Diff line change @@ -11,40 +11,6 @@ import OpenAPIURLSession
11
11
12
12
let version = Helpers . version
13
13
14
- /// A ClientTransport implementation that adapts the old Fetch api.
15
- struct FetchTransportAdapter : ClientTransport {
16
- let fetch : FunctionsClient . FetchHandler
17
-
18
- init ( fetch: @escaping FunctionsClient . FetchHandler ) {
19
- self . fetch = fetch
20
- }
21
-
22
- func send(
23
- _ request: HTTPTypes . HTTPRequest ,
24
- body: HTTPBody ? ,
25
- baseURL: URL ,
26
- operationID: String
27
- ) async throws -> ( HTTPTypes . HTTPResponse , HTTPBody ? ) {
28
- guard var urlRequest = URLRequest ( httpRequest: request) else {
29
- throw URLError ( . badURL)
30
- }
31
-
32
- if let body {
33
- urlRequest. httpBody = try await Data ( collecting: body, upTo: . max)
34
- }
35
-
36
- let ( data, response) = try await fetch ( urlRequest)
37
-
38
- guard let httpURLResponse = response as? HTTPURLResponse ,
39
- let httpResponse = httpURLResponse. httpResponse
40
- else {
41
- throw URLError ( . badServerResponse)
42
- }
43
-
44
- let body = HTTPBody ( data)
45
- return ( httpResponse, body)
46
- }
47
- }
48
14
49
15
/// An actor representing a client for invoking functions.
50
16
public final class FunctionsClient : Sendable {
Original file line number Diff line number Diff line change
1
+ import Foundation
2
+ import HTTPTypes
3
+ import HTTPTypesFoundation
4
+ import OpenAPIRuntime
5
+
6
+ #if canImport(FoundationNetworking)
7
+ import FoundationNetworking
8
+ #endif
9
+
10
+ /// A ClientTransport implementation that adapts the old Fetch api.
11
+ package struct FetchTransportAdapter : ClientTransport {
12
+ let fetch : @Sendable ( _ request: URLRequest ) async throws -> ( Data , URLResponse )
13
+
14
+ package init ( fetch: @escaping @Sendable ( _ request: URLRequest ) async throws -> ( Data , URLResponse ) ) {
15
+ self . fetch = fetch
16
+ }
17
+
18
+ package func send(
19
+ _ request: HTTPTypes . HTTPRequest ,
20
+ body: HTTPBody ? ,
21
+ baseURL: URL ,
22
+ operationID: String
23
+ ) async throws -> ( HTTPTypes . HTTPResponse , HTTPBody ? ) {
24
+ guard var urlRequest = URLRequest ( httpRequest: request) else {
25
+ throw URLError ( . badURL)
26
+ }
27
+
28
+ if let body {
29
+ urlRequest. httpBody = try await Data ( collecting: body, upTo: . max)
30
+ }
31
+
32
+ let ( data, response) = try await fetch ( urlRequest)
33
+
34
+ guard let httpURLResponse = response as? HTTPURLResponse ,
35
+ let httpResponse = httpURLResponse. httpResponse
36
+ else {
37
+ throw URLError ( . badServerResponse)
38
+ }
39
+
40
+ let body = HTTPBody ( data)
41
+ return ( httpResponse, body)
42
+ }
43
+ }
You can’t perform that action at this time.
0 commit comments