Skip to content

Commit

Permalink
[network] debug cookies operation
Browse files Browse the repository at this point in the history
  • Loading branch information
liplum committed May 25, 2024
1 parent 41263c9 commit 3691e8b
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions lib/storage/hive/cookie.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'package:flutter/foundation.dart';
import 'package:sit/r.dart';
import 'package:sit/utils/hive.dart';
import 'package:cookie_jar/cookie_jar.dart';
import 'package:hive/hive.dart';
Expand All @@ -8,17 +10,45 @@ class HiveCookieJar implements Storage {
const HiveCookieJar(this.box);

@override
Future<void> init(bool persistSession, bool ignoreExpires) async {}
Future<void> init(bool persistSession, bool ignoreExpires) async {
if (R.debugNetwork) {
debugPrint("[$HiveCookieJar] persistSession=$persistSession, ignoreExpires=$ignoreExpires");
}
}

@override
Future<void> write(String key, String value) async => box.safePut<String>(key, value);
Future<void> write(String key, String value) async {
if (R.debugNetwork) {
debugPrint("[$HiveCookieJar] Writing cookie: $key=$value.");
}
await box.safePut<String>(key, value);
}

@override
Future<String?> read(String key) async => box.safeGet<String>(key);
Future<String?> read(String key) async {
if (R.debugNetwork) {
debugPrint("[$HiveCookieJar] Reading cookie: $key.");
}
final value = box.safeGet<String?>(key);
if (R.debugNetwork) {
debugPrint("[$HiveCookieJar] Read cookie: $key=$value.");
}
return value;
}

@override
Future<void> delete(String key) async => box.delete(key);
Future<void> delete(String key) async {
if (R.debugNetwork) {
debugPrint("[$HiveCookieJar] Deleting cookie: $key.");
}
await box.delete(key);
}

@override
Future<void> deleteAll(List<String> keys) async => box.deleteAll(keys);
Future<void> deleteAll(List<String> keys) async {
if (R.debugNetwork) {
debugPrint("[$HiveCookieJar] Deleting all cookies: $keys.");
}
await box.deleteAll(keys);
}
}

0 comments on commit 3691e8b

Please sign in to comment.