@@ -161,17 +161,7 @@ public final class FunctionsClient: Sendable {
161
161
functionName: String ,
162
162
invokeOptions: FunctionInvokeOptions
163
163
) async throws -> HTTPResponse {
164
- var request = HTTPRequest (
165
- url: url. appendingPathComponent ( functionName) ,
166
- method: invokeOptions. httpMethod ?? . post,
167
- headers: mutableState. headers. merged ( with: invokeOptions. headers) ,
168
- body: invokeOptions. body
169
- )
170
-
171
- if let region = invokeOptions. region ?? region {
172
- request. headers [ " x-region " ] = region
173
- }
174
-
164
+ let request = buildRequest ( functionName: functionName, options: invokeOptions)
175
165
let response = try await http. send ( request)
176
166
177
167
guard 200 ..< 300 ~= response. statusCode else {
@@ -206,11 +196,7 @@ public final class FunctionsClient: Sendable {
206
196
207
197
let session = URLSession ( configuration: . default, delegate: delegate, delegateQueue: nil )
208
198
209
- let url = url. appendingPathComponent ( functionName)
210
- var urlRequest = URLRequest ( url: url)
211
- urlRequest. allHTTPHeaderFields = mutableState. headers. merged ( with: invokeOptions. headers) . dictionary
212
- urlRequest. httpMethod = ( invokeOptions. method ?? . post) . rawValue
213
- urlRequest. httpBody = invokeOptions. body
199
+ let urlRequest = buildRequest ( functionName: functionName, options: invokeOptions) . urlRequest
214
200
215
201
let task = session. dataTask ( with: urlRequest) { data, response, _ in
216
202
guard let httpResponse = response as? HTTPURLResponse else {
@@ -241,6 +227,22 @@ public final class FunctionsClient: Sendable {
241
227
242
228
return stream
243
229
}
230
+
231
+ private func buildRequest( functionName: String , options: FunctionInvokeOptions ) -> HTTPRequest {
232
+ var request = HTTPRequest (
233
+ url: url. appendingPathComponent ( functionName) ,
234
+ method: options. httpMethod ?? . post,
235
+ query: options. query,
236
+ headers: mutableState. headers. merged ( with: options. headers) ,
237
+ body: options. body
238
+ )
239
+
240
+ if let region = options. region ?? region {
241
+ request. headers [ " x-region " ] = region
242
+ }
243
+
244
+ return request
245
+ }
244
246
}
245
247
246
248
final class StreamResponseDelegate : NSObject , URLSessionDataDelegate , Sendable {
0 commit comments