Skip to content

Commit 1ca0c3a

Browse files
committed
Reformated the committed files
1 parent ae7be97 commit 1ca0c3a

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

pkgs/http/lib/src/browser_client.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import 'dart:async';
66
import 'dart:js_interop';
7-
7+
import 'package:http/src/utils.dart' show CacheOption;
88
import 'package:web/web.dart'
99
show
1010
AbortController,
@@ -45,6 +45,10 @@ BaseClient createClient() {
4545
class BrowserClient extends BaseClient {
4646
final _abortController = AbortController();
4747

48+
BrowserClient([CacheOption? cacheOption]) {
49+
_cacheOption = cacheOption?.cacheType ?? CacheOption.defaultType.cacheType;
50+
}
51+
4852
/// Whether to send credentials such as cookies or authorization headers for
4953
/// cross-site requests.
5054
///
@@ -53,6 +57,8 @@ class BrowserClient extends BaseClient {
5357

5458
bool _isClosed = false;
5559

60+
String? _cacheOption;
61+
5662
/// Sends an HTTP request and asynchronously returns the response.
5763
@override
5864
Future<StreamedResponse> send(BaseRequest request) async {
@@ -69,7 +75,7 @@ class BrowserClient extends BaseClient {
6975
RequestInit(
7076
method: request.method,
7177
body: bodyBytes.isNotEmpty ? bodyBytes.toJS : null,
72-
cache: request.cache!,
78+
cache: _cacheOption!,
7379
credentials: withCredentials ? 'include' : 'same-origin',
7480
headers: {
7581
if (request.contentLength case final contentLength?)

pkgs/http/lib/src/utils.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,20 @@ Stream<T> onDone<T>(Stream<T> stream, void Function() onDone) =>
7272
/// Caching utilities types for using cache for any http request.
7373
///
7474
/// For more references, check (Caching types)[https://developer.mozilla.org/en-US/docs/Web/API/Request/cache]
75-
mixin HttpCacheOptions {
76-
static const String defaultType = 'default';
77-
static const String reloadType = 'reload';
78-
static const String noStoringType = 'no-store';
79-
static const String noCachingType = 'no-cache';
80-
static const String forceCachingType = 'force-cache';
81-
static const String onlyIfCachedType = 'only-if-cached';
75+
enum CacheOption {
76+
defaultType('default'),
77+
reload('reload'),
78+
noStore('no_store'),
79+
noCache('no_cache'),
80+
forceCache('force_cache'),
81+
onlyIfCached('only_if_cached');
82+
83+
final String cacheType;
84+
85+
const CacheOption(this.cacheType);
86+
87+
static CacheOption fromString(String cacheType) => values.firstWhere(
88+
(v) => v.cacheType == cacheType,
89+
orElse: () => CacheOption.defaultType,
90+
);
8291
}

0 commit comments

Comments
 (0)