Skip to content

Commit

Permalink
feat: add onetime headers (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
rishtigupta committed Jun 18, 2024
1 parent 7c1b526 commit 9a9d4c5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/src/internal/control_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class ControlClient implements AbstractControlClient {
}

Map<String, String> makeHeaders({String? cacheName}) {
final headers = constructHeaders(firstRequest, cacheName: cacheName);
final headers =
constructHeaders(firstRequest, "cache", cacheName: cacheName);
if (firstRequest) {
firstRequest = false;
_logger.info("First request, sending agent header: $headers");
Expand Down
3 changes: 2 additions & 1 deletion lib/src/internal/data_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ class DataClient implements AbstractDataClient {
}

Map<String, String> makeHeaders({String? cacheName}) {
final headers = constructHeaders(firstRequest, cacheName: cacheName);
final headers =
constructHeaders(firstRequest, "cache", cacheName: cacheName);
if (firstRequest) {
firstRequest = false;
_logger.info("First request, sending agent header: $headers");
Expand Down
3 changes: 2 additions & 1 deletion lib/src/internal/pubsub_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class ClientPubsub implements AbstractPubsubClient {
}

Map<String, String> makeHeaders({String? cacheName}) {
final headers = constructHeaders(firstRequest, cacheName: cacheName);
final headers =
constructHeaders(firstRequest, "topic", cacheName: cacheName);
if (firstRequest) {
firstRequest = false;
_logger.info("First request, sending agent header: $headers");
Expand Down
7 changes: 5 additions & 2 deletions lib/src/internal/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import 'package_version.dart';
import 'dart:io' show Platform;

Map<String, String> constructHeaders(bool firstRequest, {String? cacheName}) {
Map<String, String> constructHeaders(bool firstRequest, String clientType,
{String? cacheName}) {
var headers = <String, String>{};
if (cacheName != null) {
headers.addEntries({'cache': cacheName}.entries);
}
if (firstRequest) {
headers.addEntries({'agent': 'dart:$packageVersion'}.entries);
headers.addEntries({'agent': 'dart:$clientType:$packageVersion'}.entries);
headers.addEntries({'runtime-version': Platform.version}.entries);
}
return headers;
}
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ dependencies:
jwt_decoder: ^2.0.1
logging: ^1.2.0
protobuf: ^3.1.0
string_validator: ^1.0.2
uuid: ^4.2.2
string_validator: ^1.1.0
uuid: ^4.4.0

dev_dependencies:
lints: ^2.1.0
test: ^1.24.0
lints: ^4.0.0
test: ^1.25.7

0 comments on commit 9a9d4c5

Please sign in to comment.