convertResponse method

HttpResponse convertResponse(
  1. StreamedResponse response,
  2. Uint8List body
)

Implementation

HttpResponse convertResponse(http.StreamedResponse response, Uint8List body) {
  MediaType? mediaType = _extractMediaType(response.headers);
  return HttpResponse(
    headers: response.headers,
    statusCode: response.statusCode,
    statusMessage: response.reasonPhrase,
    body: _isMediaTypeText(mediaType)
        ? http.Response.bytes(body, 200).body
        : body,
    time: DateTime.now(),
    additionalData: {
      "contentLength": response.contentLength ?? body.lengthInBytes,
      "persistentConnection": response.persistentConnection,
      "isRedirect": response.isRedirect,
    },
  );
}