Skip to content

Commit cfa9128

Browse files
authored
Add the ability to control cupertino_http caching policy (#763)
1 parent 9c23d20 commit cfa9128

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

pkgs/cupertino_http/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
## 0.0.4
2+
3+
* Add the ability to control caching policy.
4+
15
## 0.0.3
26

37
* Follow the project style in the example app.
48
* Use `runWithClient` in the example app.
59
* Add another README example
6-
*
10+
711
## 0.0.2
812

913
* A single comment adjustment.

pkgs/cupertino_http/example/integration_test/url_session_configuration_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ void testProperties(URLSessionConfiguration config) {
5454
config.httpShouldUsePipelining = false;
5555
expect(config.httpShouldUsePipelining, false);
5656
});
57+
test('requestCachePolicy', () {
58+
config.requestCachePolicy = URLRequestCachePolicy.returnCacheDataDontLoad;
59+
expect(config.requestCachePolicy,
60+
URLRequestCachePolicy.returnCacheDataDontLoad);
61+
config.requestCachePolicy =
62+
URLRequestCachePolicy.reloadIgnoringLocalCacheData;
63+
expect(config.requestCachePolicy,
64+
URLRequestCachePolicy.reloadIgnoringLocalCacheData);
65+
});
5766
test('sessionSendsLaunchEvents', () {
5867
config.sessionSendsLaunchEvents = true;
5968
expect(config.sessionSendsLaunchEvents, true);

pkgs/cupertino_http/lib/cupertino_http.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ enum HTTPCookieAcceptPolicy {
5050
httpCookieAcceptPolicyOnlyFromMainDocumentDomain,
5151
}
5252

53+
// Controls how response data is cached.
54+
//
55+
// See [URLRequestCachePolicy](https://developer.apple.com/documentation/foundation/nsurlrequestcachepolicy).
56+
enum URLRequestCachePolicy {
57+
useProtocolCachePolicy,
58+
reloadIgnoringLocalCacheData,
59+
returnCacheDataElseLoad,
60+
returnCacheDataDontLoad,
61+
reloadIgnoringLocalAndRemoteCacheData,
62+
reloadRevalidatingCacheData,
63+
}
64+
5365
// Controls how [URLSessionTask] execute will proceed after the response is
5466
// received.
5567
//
@@ -190,6 +202,14 @@ class URLSessionConfiguration
190202
set httpShouldUsePipelining(bool value) =>
191203
_nsObject.HTTPShouldUsePipelining = value;
192204

205+
// Controls how to deal with response caching.
206+
//
207+
// See [NSURLSessionConfiguration.requestCachePolicy](https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration/1411655-requestcachepolicy)
208+
URLRequestCachePolicy get requestCachePolicy =>
209+
URLRequestCachePolicy.values[_nsObject.requestCachePolicy];
210+
set requestCachePolicy(URLRequestCachePolicy value) =>
211+
_nsObject.requestCachePolicy = value.index;
212+
193213
/// Whether the app should be resumed when background tasks complete.
194214
///
195215
/// See [NSURLSessionConfiguration.sessionSendsLaunchEvents](https://developer.apple.com/documentation/foundation/nsurlsessionconfiguration/1617174-sessionsendslaunchevents)
@@ -234,6 +254,7 @@ class URLSessionConfiguration
234254
'httpCookieAcceptPolicy=$httpCookieAcceptPolicy '
235255
'httpShouldSetCookies=$httpShouldSetCookies '
236256
'httpShouldUsePipelining=$httpShouldUsePipelining '
257+
'requestCachePolicy=$requestCachePolicy '
237258
'sessionSendsLaunchEvents=$sessionSendsLaunchEvents '
238259
'shouldUseExtendedBackgroundIdleMode='
239260
'$shouldUseExtendedBackgroundIdleMode '

pkgs/cupertino_http/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: cupertino_http
22
description: >
33
A macOS/iOS Flutter plugin that provides access to the Foundation URL
44
Loading System.
5-
version: 0.0.3
5+
version: 0.0.4
66
repository: https://github.com/dart-lang/http/tree/master/pkgs/cupertino_http
77

88
environment:

0 commit comments

Comments
 (0)