decodeBodyBytes function

Future<String?> decodeBodyBytes(
  1. Stream<List<int>> body
)

Returns the decoded body by utf-8 if application/json with the given headers. Else, returns the decoded body by default algorithm of dart:http. Because avoid to text garbling when header only contains 'application/json' without '; charset=utf-8'.

Implementation

Future<String?> decodeBodyBytes(Stream<List<int>> body) async {
  try {
    return await utf8.decodeStream(body);
  } catch (e) {
    print(e.toString()); // for time being
    return null;
  }
}