diff --git a/lib/src/constants.dart b/lib/src/constants.dart new file mode 100644 index 0000000..eab366f --- /dev/null +++ b/lib/src/constants.dart @@ -0,0 +1,3 @@ +import 'package:postgrest/src/version.dart'; + +const defaultHeaders = {'X-Client-Info': 'postgrest-dart/$version'}; diff --git a/lib/src/postgrest.dart b/lib/src/postgrest.dart index 2f69d26..a218ab0 100644 --- a/lib/src/postgrest.dart +++ b/lib/src/postgrest.dart @@ -1,3 +1,5 @@ +import 'package:postgrest/src/constants.dart'; + import 'postgrest_query_builder.dart'; import 'postgrest_rpc_builder.dart'; import 'postgrest_transform_builder.dart'; @@ -19,7 +21,7 @@ class PostgrestClient { this.url, { Map? headers, this.schema, - }) : headers = headers ?? {}; + }) : headers = {...defaultHeaders, if (headers != null) ...headers}; /// Authenticates the request with JWT. PostgrestClient auth(String token) { diff --git a/lib/src/version.dart b/lib/src/version.dart new file mode 100644 index 0000000..d5d36b6 --- /dev/null +++ b/lib/src/version.dart @@ -0,0 +1 @@ +const version = '0.1.6'; diff --git a/test/basic_test.dart b/test/basic_test.dart index 53dae4d..de02008 100644 --- a/test/basic_test.dart +++ b/test/basic_test.dart @@ -38,6 +38,13 @@ void main() { expect(postgrest.from('users').select().headers['apikey'], 'foo'); }); + test('override X-Client-Info', () async { + final postgrest = PostgrestClient(rootUrl, + headers: {'X-Client-Info': 'supabase-dart/0.0.0'}); + expect(postgrest.from('users').select().headers['X-Client-Info'], + 'supabase-dart/0.0.0'); + }); + test('auth', () async { postgrest = PostgrestClient(rootUrl).auth('foo'); expect(postgrest.from('users').select().headers['Authorization'],