-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Only produce null response body when the response is a JSON type (#…
…1874) Resolves #1834. ### New Pull Request Checklist - [x] I have read the [Documentation](https://pub.dev/documentation/dio/latest/) - [x] I have searched for a similar pull request in the [project](https://github.com/cfug/dio/pulls) and found none - [x] I have updated this branch with the latest `main` branch to avoid conflicts (via merge from master or rebase) - [x] I have added the required tests to prove the fix/feature I'm adding - [x] I have updated the documentation (if necessary) - [x] I have run the tests without failures - [x] I have updated the `CHANGELOG.md` in the corresponding package
- Loading branch information
Showing
9 changed files
with
127 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import 'package:dio/dio.dart'; | ||
import 'package:test/test.dart'; | ||
|
||
void main() { | ||
group(BackgroundTransformer(), () { | ||
test('transformResponse transforms the request', () async { | ||
final transformer = BackgroundTransformer(); | ||
final response = await transformer.transformResponse( | ||
RequestOptions(responseType: ResponseType.json), | ||
ResponseBody.fromString( | ||
'{"foo": "bar"}', | ||
200, | ||
headers: { | ||
Headers.contentTypeHeader: ['application/json'], | ||
}, | ||
), | ||
); | ||
expect(response, {'foo': 'bar'}); | ||
}); | ||
}); | ||
|
||
// Regression: https://github.com/cfug/dio/issues/1834 | ||
test('null response body only when the response is JSON', () async { | ||
final transformer = BackgroundTransformer(); | ||
final r1 = await transformer.transformResponse( | ||
RequestOptions(responseType: ResponseType.json), | ||
ResponseBody.fromBytes([], 200), | ||
); | ||
expect(r1, ''); | ||
final r2 = await transformer.transformResponse( | ||
RequestOptions(responseType: ResponseType.bytes), | ||
ResponseBody.fromBytes([], 200), | ||
); | ||
expect(r2, []); | ||
final r3 = await transformer.transformResponse( | ||
RequestOptions(responseType: ResponseType.plain), | ||
ResponseBody.fromBytes([], 200), | ||
); | ||
expect(r3, ''); | ||
final r4 = await transformer.transformResponse( | ||
RequestOptions(responseType: ResponseType.json), | ||
ResponseBody.fromBytes( | ||
[], | ||
200, | ||
headers: { | ||
Headers.contentTypeHeader: [Headers.jsonContentType], | ||
}, | ||
), | ||
); | ||
expect(r4, null); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters