HttpResponse.factory constructor

HttpResponse.factory(
  1. String url,
  2. Response response
)

Implementation

factory HttpResponse.factory(String url, dart_http.Response response) {
  // content type
  String? contentType;
  if (response.headers.containsKey(HttpHeaders.contentTypeHeader)) {
    contentType = response.headers[HttpHeaders.contentTypeHeader];
  }

  dynamic body;
  try {
    body = utf8.decode(response.bodyBytes);
  } catch (e) {
    body = response.body;
  }

  return HttpResponse(url,
      body: body,
      bytes: response.bodyBytes,
      contentType: contentType,
      statusCode: response.statusCode,
      statusMessage: response.reasonPhrase);
}