Skip to content

Commit

Permalink
fix: Correctly sierialize null content responses.
Browse files Browse the repository at this point in the history
  • Loading branch information
llfbandit committed Sep 25, 2023
1 parent 9190771 commit c0d843e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 4 additions & 0 deletions dio_cache_interceptor/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.4.3
- fix: Correctly sierialize null content responses.
- chore: explicitly allow dart 3.

## 3.4.2
- fix: Headers were not saved/restored in/from `CacheResponse`.
- fix: Cache trigger now enabled again with `expires`, `Cache-Control`/`max-age`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import 'dart:convert';

import 'package:dio/dio.dart';

Future<List<int>> serializeContent(ResponseType type, dynamic content) async {
Future<List<int>?> serializeContent(ResponseType type, dynamic content) async {
if (content == null) {
return null;
}

switch (type) {
case ResponseType.bytes:
return content;
Expand Down
6 changes: 3 additions & 3 deletions dio_cache_interceptor/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ 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: 3.4.2
version: 3.4.3

environment:
sdk: ">=2.12.0 <3.0.0"
sdk: ">=2.12.0 <4.0.0"

dependencies:
# https://pub.dev/packages/dio
dio: ">=4.0.0 <6.0.0"
# https://pub.dev/packages/uuid
uuid: ^3.0.4
uuid: ^3.0.7
# https://pub.dev/packages/string_scanner
string_scanner: ^1.1.0

Expand Down
13 changes: 13 additions & 0 deletions dio_cache_interceptor/test/content_serialization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,17 @@ void main() {
);
expect(deserializedContent, equals(content));
});

test('Serialize null', () async {
final serializedContent = await serializeContent(
ResponseType.json,
null,
);
final deserializedContent = await deserializeContent(
ResponseType.json,
serializedContent,
);

expect(deserializedContent, isNull);
});
}

0 comments on commit c0d843e

Please sign in to comment.