mapHttpResponseAsResponse function

  1. @visibleForTesting
Future<Response> mapHttpResponseAsResponse(
  1. StreamedResponse httpResponse
)

Implementation

@visibleForTesting
Future<Response> mapHttpResponseAsResponse(
  final http.StreamedResponse httpResponse,
) async {
  final statusCode = httpResponse.statusCode;

  final contentType = ContentTypeExtension.of(
    httpResponse.headers['content-type'] ?? '',
  );

  final body = await httpResponse.stream.toBytes();

  final headers = httpResponse.headers;

  if ((statusCode - 200) < 200) {
    return Response.fromContentType(
      contentType: contentType,
      body: body,
      statusCode: statusCode,
      headers: headers,
    );
  } else {
    return ErrorResponse(
      contentType: contentType,
      body: body,
      statusCode: statusCode,
      headers: headers,
    );
  }
}