Skip to content

Commit 7ece5aa

Browse files
committed
Changed the parameter to String type
1 parent 85daade commit 7ece5aa

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

pkgs/http/lib/src/browser_client.dart

+16-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import 'base_client.dart';
1717
import 'base_request.dart';
1818
import 'exception.dart';
1919
import 'streamed_response.dart';
20-
import 'utils.dart';
2120

2221
/// Create a [BrowserClient].
2322
///
@@ -45,9 +44,17 @@ BaseClient createClient() {
4544
class BrowserClient extends BaseClient {
4645
final _abortController = AbortController();
4746

48-
BrowserClient([CacheOption? cacheOption]) {
49-
_cacheOption = cacheOption?.cacheType ?? CacheOption.defaultType.cacheType;
50-
}
47+
/// Create a new browser-based HTTP Client.
48+
///
49+
/// If [cacheMode] is provided then it can be used to cache the request
50+
/// in the browser.
51+
///
52+
/// For example:
53+
/// ```dart
54+
/// const mode = 'reload';
55+
/// final client = BrowserClient(cacheMode: mode);
56+
/// ```
57+
BrowserClient({this.cacheMode = 'default'});
5158

5259
/// Whether to send credentials such as cookies or authorization headers for
5360
/// cross-site requests.
@@ -57,7 +64,10 @@ class BrowserClient extends BaseClient {
5764

5865
bool _isClosed = false;
5966

60-
String? _cacheOption;
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;
6171

6272
/// Sends an HTTP request and asynchronously returns the response.
6373
@override
@@ -75,7 +85,7 @@ class BrowserClient extends BaseClient {
7585
RequestInit(
7686
method: request.method,
7787
body: bodyBytes.isNotEmpty ? bodyBytes.toJS : null,
78-
cache: _cacheOption!,
88+
cache: cacheMode,
7989
credentials: withCredentials ? 'include' : 'same-origin',
8090
headers: {
8191
if (request.contentLength case final contentLength?)

pkgs/http/lib/src/utils.dart

+5-7
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,8 @@ Stream<T> onDone<T>(Stream<T> stream, void Function() onDone) =>
6969
onDone();
7070
}));
7171

72-
/// Caching utilities types for using cache for any http request.
73-
///
74-
/// For more references, check (Caching types)[https://developer.mozilla.org/en-US/docs/Web/API/Request/cache]
75-
enum CacheOption {
72+
/// Caching modes for any http request in a browser.
73+
enum CacheMode {
7674
defaultType('default'),
7775
reload('reload'),
7876
noStore('no-store'),
@@ -82,10 +80,10 @@ enum CacheOption {
8280

8381
final String cacheType;
8482

85-
const CacheOption(this.cacheType);
83+
const CacheMode(this.cacheType);
8684

87-
static CacheOption fromString(String cacheType) => values.firstWhere(
85+
static CacheMode fromString(String cacheType) => values.firstWhere(
8886
(v) => v.cacheType == cacheType,
89-
orElse: () => CacheOption.defaultType,
87+
orElse: () => CacheMode.defaultType,
9088
);
9189
}

0 commit comments

Comments
 (0)