Skip to content

Commit a8521ee

Browse files
committed
fix: Dio does not expand Cache-Control values
1 parent 2ae5510 commit a8521ee

4 files changed

Lines changed: 21 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 2.3.1
2+
- fix: Cache-Control parsing. Dio does not expand multi valued headers.
3+
14
## 2.3.0
25
- feat: `allowPostMethod` added to `CacheOptions`.
36

lib/src/model/cache_control.dart

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,22 @@ class CacheControl {
3737
final other = <String>[];
3838

3939
for (var value in headerValues) {
40-
if (value == 'no-cache') {
41-
noCache = true;
42-
} else if (value == 'no-store') {
43-
noStore = true;
44-
} else if (value == 'public' || value == 'private') {
45-
privacy = value;
46-
} else if (value.startsWith('max-age')) {
47-
maxAge = int.tryParse(value.substring(value.indexOf('=') + 1));
48-
} else {
49-
other.add(value);
40+
// Expand values since dio does not do it !
41+
for (var expandedValue in value.split(',')) {
42+
expandedValue = expandedValue.trim();
43+
if (expandedValue == 'no-cache') {
44+
noCache = true;
45+
} else if (expandedValue == 'no-store') {
46+
noStore = true;
47+
} else if (expandedValue == 'public' || expandedValue == 'private') {
48+
privacy = expandedValue;
49+
} else if (expandedValue.startsWith('max-age')) {
50+
maxAge = int.tryParse(
51+
expandedValue.substring(expandedValue.indexOf('=') + 1),
52+
);
53+
} else {
54+
other.add(expandedValue);
55+
}
5056
}
5157
}
5258

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Dio HTTP cache interceptor with multiple stores respecting HTTP dir
33
repository: https://github.com/llfbandit/dio_cache_interceptor
44
issue_tracker: https://github.com/llfbandit/dio_cache_interceptor/issues
55

6-
version: 2.3.0
6+
version: 2.3.1
77

88
environment:
99
sdk: ">=2.12.0 <3.0.0"

test/mock_httpclient_adapter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ class MockHttpClientAdapter extends HttpClientAdapter {
153153
200,
154154
headers: {
155155
Headers.contentTypeHeader: [Headers.jsonContentType],
156-
'cache-control': ['public', 'max-age=1'],
156+
'cache-control': ['public, max-age=1'],
157157
},
158158
);
159159
}

0 commit comments

Comments
 (0)