Skip to content
This repository has been archived by the owner on May 13, 2023. It is now read-only.

feat: added x-client-info header with manually updating version number #42

Merged
merged 2 commits into from
Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:postgrest/src/version.dart';

const defaultHeaders = {'X-Client-Info': 'postgrest-dart/$version'};
4 changes: 3 additions & 1 deletion lib/src/postgrest.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -19,7 +21,7 @@ class PostgrestClient {
this.url, {
Map<String, String>? headers,
this.schema,
}) : headers = headers ?? {};
}) : headers = {...defaultHeaders, if (headers != null) ...headers};

/// Authenticates the request with JWT.
PostgrestClient auth(String token) {
Expand Down
1 change: 1 addition & 0 deletions lib/src/version.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const version = '0.1.6';
7 changes: 7 additions & 0 deletions test/basic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down