Skip to content

Commit

Permalink
Merge pull request supabase#181 from supabase-community/feat/header
Browse files Browse the repository at this point in the history
feat: Accept custom headers and add add X-Client-Info header
  • Loading branch information
dshukertjr committed Aug 11, 2022
2 parents c3a7990 + 8578ee0 commit 8a1e0ff
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/src/constants.dart
@@ -0,0 +1,7 @@
import 'package:supabase_flutter/src/version.dart';

class Constants {
static const Map<String, String> defaultHeaders = {
'X-Client-Info': 'supabase-flutter/$version',
};
}
15 changes: 14 additions & 1 deletion lib/src/supabase.dart
@@ -1,6 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:http/http.dart';
import 'package:supabase/supabase.dart';
import 'package:supabase_flutter/src/constants.dart';
import 'package:supabase_flutter/src/local_storage.dart';
import 'package:supabase_flutter/src/supabase_auth.dart';

Expand Down Expand Up @@ -45,6 +46,7 @@ class Supabase {
bool? debug,
LocalStorage? localStorage,
Client? httpClient,
Map<String, String>? headers,
}) async {
assert(
!_instance._initialized,
Expand All @@ -54,6 +56,7 @@ class Supabase {
url,
anonKey,
httpClient: httpClient,
customHeaders: headers,
);
_instance._debugEnable = debug ?? kDebugMode;
_instance.log('***** Supabase init completed $_instance');
Expand Down Expand Up @@ -82,11 +85,21 @@ class Supabase {
_initialized = false;
}

void _init(String supabaseUrl, String supabaseAnonKey, {Client? httpClient}) {
void _init(
String supabaseUrl,
String supabaseAnonKey, {
Client? httpClient,
Map<String, String>? customHeaders,
}) {
final headers = {
...Constants.defaultHeaders,
if (customHeaders != null) ...customHeaders
};
client = SupabaseClient(
supabaseUrl,
supabaseAnonKey,
httpClient: httpClient,
headers: headers,
);
_initialized = true;
}
Expand Down
1 change: 1 addition & 0 deletions lib/src/version.dart
@@ -0,0 +1 @@
const version = '1.0.0-dev.3';

0 comments on commit 8a1e0ff

Please sign in to comment.