1
1
import ConcurrencyExtras
2
2
import Foundation
3
3
import Helpers
4
+ import HTTPTypes
4
5
5
6
#if canImport(FoundationNetworking)
6
7
import FoundationNetworking
@@ -25,12 +26,12 @@ public final class FunctionsClient: Sendable {
25
26
26
27
struct MutableState {
27
28
/// Headers to be included in the requests.
28
- var headers = HTTPHeaders ( )
29
+ var headers = HTTPFields ( )
29
30
}
30
31
31
32
private let mutableState = LockIsolated ( MutableState ( ) )
32
33
33
- var headers : HTTPHeaders {
34
+ var headers : HTTPFields {
34
35
mutableState. headers
35
36
}
36
37
@@ -71,9 +72,9 @@ public final class FunctionsClient: Sendable {
71
72
self . http = http
72
73
73
74
mutableState. withValue {
74
- $0. headers = HTTPHeaders ( headers)
75
- if $0. headers [ " X-Client-Info " ] == nil {
76
- $0. headers [ " X-Client-Info " ] = " functions-swift/ \( version) "
75
+ $0. headers = HTTPFields ( headers)
76
+ if $0. headers [ . xClientInfo ] == nil {
77
+ $0. headers [ . xClientInfo ] = " functions-swift/ \( version) "
77
78
}
78
79
}
79
80
}
@@ -102,9 +103,9 @@ public final class FunctionsClient: Sendable {
102
103
public func setAuth( token: String ? ) {
103
104
mutableState. withValue {
104
105
if let token {
105
- $0. headers [ " Authorization " ] = " Bearer \( token) "
106
+ $0. headers [ . authorization ] = " Bearer \( token) "
106
107
} else {
107
- $0. headers [ " Authorization " ] = nil
108
+ $0. headers [ . authorization ] = nil
108
109
}
109
110
}
110
111
}
@@ -160,15 +161,15 @@ public final class FunctionsClient: Sendable {
160
161
private func rawInvoke(
161
162
functionName: String ,
162
163
invokeOptions: FunctionInvokeOptions
163
- ) async throws -> HTTPResponse {
164
+ ) async throws -> Helpers . HTTPResponse {
164
165
let request = buildRequest ( functionName: functionName, options: invokeOptions)
165
166
let response = try await http. send ( request)
166
167
167
168
guard 200 ..< 300 ~= response. statusCode else {
168
169
throw FunctionsError . httpError ( code: response. statusCode, data: response. data)
169
170
}
170
171
171
- let isRelayError = response. headers [ " x-relay-error " ] == " true "
172
+ let isRelayError = response. headers [ . xRelayError ] == " true "
172
173
if isRelayError {
173
174
throw FunctionsError . relayError
174
175
}
@@ -211,17 +212,17 @@ public final class FunctionsClient: Sendable {
211
212
return stream
212
213
}
213
214
214
- private func buildRequest( functionName: String , options: FunctionInvokeOptions ) -> HTTPRequest {
215
+ private func buildRequest( functionName: String , options: FunctionInvokeOptions ) -> Helpers . HTTPRequest {
215
216
var request = HTTPRequest (
216
217
url: url. appendingPathComponent ( functionName) ,
217
218
method: options. httpMethod ?? . post,
218
219
query: options. query,
219
- headers: mutableState. headers. merged ( with: options. headers) ,
220
+ headers: mutableState. headers. merging ( with: options. headers) ,
220
221
body: options. body
221
222
)
222
223
223
224
if let region = options. region ?? region {
224
- request. headers [ " x-region " ] = region
225
+ request. headers [ . xRegion ] = region
225
226
}
226
227
227
228
return request
0 commit comments