Skip to content
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
Added x-firebase-client header
  • Loading branch information
maneesht committed Jan 24, 2025
commit 12b69b6d6522f7201e6fe1222a1dc4e1f3757baa
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ String getGoogApiVal(CallerSDKType sdkType, String packageVersion) {
return apiClientValue;
}

String getFirebaseClientVal(String packageVersion) {
return 'flutter-fire-dc/$packageVersion';
}

/// Transport Options for connecting to a specific host.
class TransportOptions {
/// Constructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class GRPCTransport implements DataConnectTransport {
Map<String, String> metadata = {
'x-goog-request-params': 'location=${options.location}&frontend=data',
'x-goog-api-client': getGoogApiVal(sdkType, packageVersion),
'x-firebase-client': getFirebaseClientVal(packageVersion)
};

if (authToken != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class RestTransport implements DataConnectTransport {
'Content-Type': 'application/json',
'Accept': 'application/json',
'x-goog-api-client': getGoogApiVal(sdkType, packageVersion),
'x-firebase-client': getFirebaseClientVal(packageVersion)
};
String? appCheckToken;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import 'dart:convert';
import 'package:firebase_app_check/firebase_app_check.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_data_connect/src/common/common_library.dart';
import 'package:firebase_data_connect/src/dataconnect_version.dart';
import 'package:firebase_data_connect/src/network/rest_library.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -260,6 +261,42 @@ void main() {
),
).called(1);
});
test('invokeOperation should include x-firebase-client headers', () async {
final mockResponse = http.Response('{"data": {"key": "value"}}', 200);
when(
mockHttpClient.post(
any,
headers: anyNamed('headers'),
body: anyNamed('body'),
),
).thenAnswer((_) async => mockResponse);

when(mockUser.getIdToken()).thenAnswer((_) async => 'authToken123');
when(mockAppCheck.getToken()).thenAnswer((_) async => 'appCheckToken123');

final deserializer = (String data) => 'Deserialized Data';

await transport.invokeOperation(
'testQuery',
'executeQuery',
deserializer,
null,
null,
'authToken123',
);

verify(
mockHttpClient.post(
any,
headers: argThat(
containsPair(
'x-firebase-client', getFirebaseClientVal(packageVersion)),
named: 'headers',
),
body: anyNamed('body'),
),
).called(1);
});

test(
'invokeOperation should handle missing auth and appCheck tokens gracefully',
Expand Down
Loading