Skip to content

Commit 02dfc3a

Browse files
committed
fix _headers
1 parent 5c9b211 commit 02dfc3a

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

Sources/Supabase/SupabaseClient.swift

+10-13
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public final class SupabaseClient: Sendable {
4747
$0.rest = PostgrestClient(
4848
url: databaseURL,
4949
schema: options.db.schema,
50-
headers: _headers,
50+
headers: headers,
5151
logger: options.global.logger,
5252
fetch: { request, bodyData in
5353
if let bodyData {
@@ -72,7 +72,7 @@ public final class SupabaseClient: Sendable {
7272
$0.storage = SupabaseStorageClient(
7373
configuration: StorageClientConfiguration(
7474
url: storageURL,
75-
headers: _headers,
75+
headers: headers,
7676
session: StorageHTTPSession { request, bodyData in
7777
if let bodyData {
7878
return try await self.uploadWithAuth(for: request, from: bodyData)
@@ -100,7 +100,7 @@ public final class SupabaseClient: Sendable {
100100
if $0.functions == nil {
101101
$0.functions = FunctionsClient(
102102
url: functionsURL,
103-
headers: _headers,
103+
headers: headers,
104104
region: options.functions.region,
105105
logger: options.global.logger,
106106
fetch: { request, bodyData in
@@ -116,14 +116,11 @@ public final class SupabaseClient: Sendable {
116116
return $0.functions!
117117
}
118118
}
119-
120-
let _headers: HTTPFields
119+
121120
/// Headers provided to the inner clients on initialization.
122121
///
123122
/// - Note: This collection is non-mutable, if you want to provide different headers, pass it in ``SupabaseClientOptions/GlobalOptions/headers``.
124-
public var headers: [String: String] {
125-
_headers.dictionary
126-
}
123+
public let headers: HTTPFields
127124

128125
struct MutableState {
129126
var listenForAuthEventsTask: Task<Void, Never>?
@@ -177,14 +174,14 @@ public final class SupabaseClient: Sendable {
177174
.authorization: "Bearer \(supabaseKey)",
178175
.apiKey: supabaseKey,
179176
]
180-
_headers = headers.merging(with: options.global.headers)
177+
self.headers = headers.merging(with: options.global.headers)
181178

182179
// default storage key uses the supabase project ref as a namespace
183180
let defaultStorageKey = "sb-\(supabaseURL.host!.split(separator: ".")[0])-auth-token"
184181

185182
_auth = AuthClient(
186183
url: supabaseURL.appendingPathComponent("/auth/v1"),
187-
headers: _headers,
184+
headers: self.headers,
188185
flowType: options.auth.flowType,
189186
redirectToURL: options.auth.redirectToURL,
190187
storageKey: options.auth.storageKey ?? defaultStorageKey,
@@ -206,13 +203,13 @@ public final class SupabaseClient: Sendable {
206203
_realtime = UncheckedSendable(
207204
RealtimeClient(
208205
supabaseURL.appendingPathComponent("/realtime/v1").absoluteString,
209-
headers: _headers,
210-
params: _headers.dictionary
206+
headers: headers,
207+
params: headers.dictionary
211208
)
212209
)
213210

214211
var realtimeOptions = options.realtime
215-
realtimeOptions.headers.merge(with: _headers)
212+
realtimeOptions.headers.merge(with: self.headers)
216213
if realtimeOptions.logger == nil {
217214
realtimeOptions.logger = options.global.logger
218215
}

Tests/SupabaseTests/SupabaseClientTests.swift

+6-7
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,22 @@ final class SupabaseClientTests: XCTestCase {
6464
)
6565

6666
XCTAssertEqual(
67-
client.headers,
67+
client.headers,
6868
[
69-
"X-Client-Info": "supabase-swift/\(Supabase.version)",
70-
"Apikey": "ANON_KEY",
71-
"header_field": "header_value",
72-
"Authorization": "Bearer ANON_KEY",
69+
.xClientInfo: "supabase-swift/\(Supabase.version)",
70+
.apiKey: "ANON_KEY",
71+
.init("header_field")!: "header_value",
72+
.authorization: "Bearer ANON_KEY",
7373
]
7474
)
75-
expectNoDifference(client._headers.dictionary, client.headers)
7675

7776
XCTAssertEqual(client.functions.region, "ap-northeast-1")
7877

7978
let realtimeURL = client.realtimeV2.url
8079
XCTAssertEqual(realtimeURL.absoluteString, "https://project-ref.supabase.co/realtime/v1")
8180

8281
let realtimeOptions = client.realtimeV2.options
83-
let expectedRealtimeHeader = client._headers.merging(with: [
82+
let expectedRealtimeHeader = client.headers.merging(with: [
8483
.init("custom_realtime_header_key")!: "custom_realtime_header_value"
8584
]
8685
)

0 commit comments

Comments
 (0)