Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add standard client headers #1130

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
16 changes: 15 additions & 1 deletion packages/supabase/lib/src/constants.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
import 'package:supabase/src/version.dart';
import 'dart:io' show Platform;

const bool kIsWeb = bool.fromEnvironment('dart.library.js_util');

class Constants {
static const Map<String, String> defaultHeaders = {
static String? get platform {
return kIsWeb ? null : Platform.operatingSystem;
}

static String? get platformVersion {
return kIsWeb ? null : Platform.operatingSystemVersion;
}

static final Map<String, String> defaultHeaders = {
'X-Client-Info': 'supabase-dart/$version',
if (platform != null) 'X-Supabase-Client-Platform': platform!,
if (platformVersion != null)
'X-Supabase-Client-Platform-Version': platformVersion!,
};
}
45 changes: 45 additions & 0 deletions packages/supabase/test/client_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,51 @@ void main() {
await supabase.dispose();
});

test('X-Supabase-Client-Platform header is set properly', () {
expect(supabase.headers['X-Supabase-Client-Platform'],
Platform.operatingSystem);
expect(supabase.headers['X-Supabase-Client-Platform-Version'],
Platform.operatingSystemVersion);
});
test('X-Supabase-Client-Platform header is set properly on auth', () {
expect(supabase.auth.headers['X-Supabase-Client-Platform'],
Platform.operatingSystem);
expect(supabase.auth.headers['X-Supabase-Client-Platform-Version'],
Platform.operatingSystemVersion);
});

test('X-Supabase-Client-Platform header is set properly on storage', () {
expect(supabase.storage.headers['X-Supabase-Client-Platform'],
Platform.operatingSystem);
expect(supabase.storage.headers['X-Supabase-Client-Platform-Version'],
Platform.operatingSystemVersion);
});

test('X-Supabase-Client-Platform header is set properly on functions', () {
expect(supabase.functions.headers['X-Supabase-Client-Platform'],
Platform.operatingSystem);
expect(supabase.functions.headers['X-Supabase-Client-Platform-Version'],
Platform.operatingSystemVersion);
});

test('X-Supabase-Client-Platform header is set properly on rest', () {
expect(supabase.rest.headers['X-Supabase-Client-Platform'],
Platform.operatingSystem);
expect(supabase.rest.headers['X-Supabase-Client-Platform-Version'],
Platform.operatingSystemVersion);
});

test('X-Supabase-Client-Platform header is set properly on realtime',
() async {
final request = await getRealtimeRequest(
server: mockServer,
supabaseClient: supabase,
);
expect(request.headers['X-Supabase-Client-Platform']?.first,
Platform.operatingSystem);
expect(request.headers['X-Supabase-Client-Platform-Version']?.first,
Platform.operatingSystemVersion);
});
test('X-Client-Info header is set properly on realtime', () async {
final request = await getRealtimeRequest(
server: mockServer,
Expand Down