Skip to content

Commit

Permalink
chore: use Uuid v4 as the alice_token to make it completely unique
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse committed Jun 9, 2024
1 parent fda3903 commit 8732199
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 10 additions & 5 deletions packages/alice_chopper/lib/alice_chopper_adapter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:alice/model/alice_http_request.dart';
import 'package:alice/model/alice_http_response.dart';
import 'package:chopper/chopper.dart';
import 'package:http/http.dart' as http;
import 'package:uuid/uuid.dart';

class AliceChopperAdapter with AliceAdapter implements Interceptor {
/// Creates hashcode based on request
Expand All @@ -31,11 +32,15 @@ class AliceChopperAdapter with AliceAdapter implements Interceptor {
FutureOr<Response<BodyType>> intercept<BodyType>(
Chain<BodyType> chain,
) async {
final int requestId = getRequestHashCode(applyHeader(
chain.request,
'alice_token',
DateTime.now().microsecondsSinceEpoch.toString(),
));
final int requestId = getRequestHashCode(
/// The alice_token header is added to the request in order to keep track
/// of the request in the AliceCore instance.
applyHeader(
chain.request,
'alice_token',
Uuid().v4(),
),
);

aliceCore.addCall(
AliceHttpCall(requestId)
Expand Down
3 changes: 2 additions & 1 deletion packages/alice_chopper/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
alice: ^1.0.0-dev.4
chopper: ^8.0.0
http: ^1.2.1
uuid: ^4.4.0

dev_dependencies:
very_good_analysis: ^5.1.0
very_good_analysis: ^5.1.0

0 comments on commit 8732199

Please sign in to comment.