11import ConcurrencyExtras
22import Foundation
33import Helpers
4+ import HTTPTypes
45
56#if canImport(FoundationNetworking)
67 import FoundationNetworking
@@ -25,12 +26,12 @@ public final class FunctionsClient: Sendable {
2526
2627 struct MutableState {
2728 /// Headers to be included in the requests.
28- var headers = HTTPHeaders ( )
29+ var headers = HTTPFields ( )
2930 }
3031
3132 private let mutableState = LockIsolated ( MutableState ( ) )
3233
33- var headers : HTTPHeaders {
34+ var headers : HTTPFields {
3435 mutableState. headers
3536 }
3637
@@ -71,9 +72,9 @@ public final class FunctionsClient: Sendable {
7172 self . http = http
7273
7374 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) "
7778 }
7879 }
7980 }
@@ -102,9 +103,9 @@ public final class FunctionsClient: Sendable {
102103 public func setAuth( token: String ? ) {
103104 mutableState. withValue {
104105 if let token {
105- $0. headers [ " Authorization " ] = " Bearer \( token) "
106+ $0. headers [ . authorization ] = " Bearer \( token) "
106107 } else {
107- $0. headers [ " Authorization " ] = nil
108+ $0. headers [ . authorization ] = nil
108109 }
109110 }
110111 }
@@ -160,15 +161,15 @@ public final class FunctionsClient: Sendable {
160161 private func rawInvoke(
161162 functionName: String ,
162163 invokeOptions: FunctionInvokeOptions
163- ) async throws -> HTTPResponse {
164+ ) async throws -> Helpers . HTTPResponse {
164165 let request = buildRequest ( functionName: functionName, options: invokeOptions)
165166 let response = try await http. send ( request)
166167
167168 guard 200 ..< 300 ~= response. statusCode else {
168169 throw FunctionsError . httpError ( code: response. statusCode, data: response. data)
169170 }
170171
171- let isRelayError = response. headers [ " x-relay-error " ] == " true "
172+ let isRelayError = response. headers [ . xRelayError ] == " true "
172173 if isRelayError {
173174 throw FunctionsError . relayError
174175 }
@@ -211,17 +212,17 @@ public final class FunctionsClient: Sendable {
211212 return stream
212213 }
213214
214- private func buildRequest( functionName: String , options: FunctionInvokeOptions ) -> HTTPRequest {
215+ private func buildRequest( functionName: String , options: FunctionInvokeOptions ) -> Helpers . HTTPRequest {
215216 var request = HTTPRequest (
216217 url: url. appendingPathComponent ( functionName) ,
217218 method: options. httpMethod ?? . post,
218219 query: options. query,
219- headers: mutableState. headers. merged ( with: options. headers) ,
220+ headers: mutableState. headers. merging ( with: options. headers) ,
220221 body: options. body
221222 )
222223
223224 if let region = options. region ?? region {
224- request. headers [ " x-region " ] = region
225+ request. headers [ . xRegion ] = region
225226 }
226227
227228 return request
0 commit comments