Closed tjarvstrand closed 3 years ago
In case anyone else runs into this I have been able to work around it by adding the below dio interceptor before stash_dio
:
...
import 'package:http_parser/http_parser.dart';
InterceptorsWrapper(
onResponse: (response, handler) {
final expires = response.headers.value('expires');
final hasValidExpiry = expires != null &&
expires.length > 4 &&
parseHttpDate(expires).toLocal().compareTo(DateTime.now()) >= 0;
final hasMaxStale =
response.headers.value("cache-control")?.contains("max-stale") ??
false;
if (!hasValidExpiry && !hasMaxStale) {
response.headers.set("cache-control", "max-stale=0");
}
handler.next(response);
},
);
Hi thank you for your report. I’m preparing a new version for the next weekend and I intend to fix this issue then.
I've published a new version that fixes this issue. I was a bit surprised that this was not caught on the unit tests but later understood that this was only happen when there's a need to serialise data. I've now added a unit test to make sure this does not happen again
Describe the bug Caching crashes when responses do not have
cache-control
orexpires
headers setTo Reproduce Make a request to any URL that does not return any of the
cache-control
orexpires
headers set.Expected behavior The response should be successfully cached.
Version stash_dio 2.0.2
Additional context I believe there is a typo here: https://github.com/ivoleitao/stash/blob/de443ce6bb0fc203677d66d4f581db21d47b4af1/packages/stash_dio/lib/src/dio/cache_value.dart#L52
This line looks like it should be
?.
rather than!.