diff --git a/CHANGELOG.md b/CHANGELOG.md index d159e3c..f47f636 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2.3.1 +- fix: Cache-Control parsing. Dio does not expand multi valued headers. + ## 2.3.0 - feat: `allowPostMethod` added to `CacheOptions`. diff --git a/lib/src/model/cache_control.dart b/lib/src/model/cache_control.dart index 1ee72fd..33ffbc0 100644 --- a/lib/src/model/cache_control.dart +++ b/lib/src/model/cache_control.dart @@ -37,16 +37,22 @@ class CacheControl { final other = []; for (var value in headerValues) { - if (value == 'no-cache') { - noCache = true; - } else if (value == 'no-store') { - noStore = true; - } else if (value == 'public' || value == 'private') { - privacy = value; - } else if (value.startsWith('max-age')) { - maxAge = int.tryParse(value.substring(value.indexOf('=') + 1)); - } else { - other.add(value); + // Expand values since dio does not do it ! + for (var expandedValue in value.split(',')) { + expandedValue = expandedValue.trim(); + if (expandedValue == 'no-cache') { + noCache = true; + } else if (expandedValue == 'no-store') { + noStore = true; + } else if (expandedValue == 'public' || expandedValue == 'private') { + privacy = expandedValue; + } else if (expandedValue.startsWith('max-age')) { + maxAge = int.tryParse( + expandedValue.substring(expandedValue.indexOf('=') + 1), + ); + } else { + other.add(expandedValue); + } } } diff --git a/pubspec.yaml b/pubspec.yaml index 9fac88a..1871398 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Dio HTTP cache interceptor with multiple stores respecting HTTP dir repository: https://github.com/llfbandit/dio_cache_interceptor issue_tracker: https://github.com/llfbandit/dio_cache_interceptor/issues -version: 2.3.0 +version: 2.3.1 environment: sdk: ">=2.12.0 <3.0.0" diff --git a/test/mock_httpclient_adapter.dart b/test/mock_httpclient_adapter.dart index 716c4bb..a6d0186 100644 --- a/test/mock_httpclient_adapter.dart +++ b/test/mock_httpclient_adapter.dart @@ -153,7 +153,7 @@ class MockHttpClientAdapter extends HttpClientAdapter { 200, headers: { Headers.contentTypeHeader: [Headers.jsonContentType], - 'cache-control': ['public', 'max-age=1'], + 'cache-control': ['public, max-age=1'], }, ); }