Skip to content

Commit 4bca978

Browse files
committed
Reverted utils.dart
1 parent 7ece5aa commit 4bca978

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

pkgs/http/lib/src/browser_client.dart

+22-9
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,21 @@ BaseClient createClient() {
4444
class BrowserClient extends BaseClient {
4545
final _abortController = AbortController();
4646

47+
final String? _cacheMode;
48+
4749
/// Create a new browser-based HTTP Client.
4850
///
4951
/// If [cacheMode] is provided then it can be used to cache the request
5052
/// in the browser.
5153
///
5254
/// For example:
5355
/// ```dart
54-
/// const mode = 'reload';
55-
/// final client = BrowserClient(cacheMode: mode);
56+
/// final client = BrowserClient(cacheMode: 'reload');
5657
/// ```
57-
BrowserClient({this.cacheMode = 'default'});
58+
///
59+
/// Defaults to `default`.
60+
/// https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
61+
BrowserClient([String? cacheMode]) : _cacheMode = cacheMode ?? "default";
5862

5963
/// Whether to send credentials such as cookies or authorization headers for
6064
/// cross-site requests.
@@ -64,11 +68,6 @@ class BrowserClient extends BaseClient {
6468

6569
bool _isClosed = false;
6670

67-
/// Use different caching mode for a HTTP request.
68-
/// Defaults to `default`.
69-
// https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
70-
String cacheMode;
71-
7271
/// Sends an HTTP request and asynchronously returns the response.
7372
@override
7473
Future<StreamedResponse> send(BaseRequest request) async {
@@ -85,7 +84,7 @@ class BrowserClient extends BaseClient {
8584
RequestInit(
8685
method: request.method,
8786
body: bodyBytes.isNotEmpty ? bodyBytes.toJS : null,
88-
cache: cacheMode,
87+
cache: _cacheMode!,
8988
credentials: withCredentials ? 'include' : 'same-origin',
9089
headers: {
9190
if (request.contentLength case final contentLength?)
@@ -201,3 +200,17 @@ Stream<List<int>> _readBody(BaseRequest request, Response response) async* {
201200
extension type _IterableHeaders._(JSObject _) implements JSObject {
202201
external void forEach(JSFunction fn);
203202
}
203+
204+
/// Caching modes for any http request in a browser.
205+
enum CacheMode {
206+
defaultType('default'),
207+
reload('reload'),
208+
noStore('no-store'),
209+
noCache('no-cache'),
210+
forceCache('force-cache'),
211+
onlyIfCached('only-if-cached');
212+
213+
final String cacheType;
214+
215+
const CacheMode(this.cacheType);
216+
}

pkgs/http/lib/src/utils.dart

-19
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,3 @@ Stream<T> onDone<T>(Stream<T> stream, void Function() onDone) =>
6868
sink.close();
6969
onDone();
7070
}));
71-
72-
/// Caching modes for any http request in a browser.
73-
enum CacheMode {
74-
defaultType('default'),
75-
reload('reload'),
76-
noStore('no-store'),
77-
noCache('no-cache'),
78-
forceCache('force-cache'),
79-
onlyIfCached('only-if-cached');
80-
81-
final String cacheType;
82-
83-
const CacheMode(this.cacheType);
84-
85-
static CacheMode fromString(String cacheType) => values.firstWhere(
86-
(v) => v.cacheType == cacheType,
87-
orElse: () => CacheMode.defaultType,
88-
);
89-
}

0 commit comments

Comments
 (0)