onResponse method

FutureOr<Response> onResponse(
  1. Response response
)

Handles chopper response and adds data to existing alice http call

Implementation

FutureOr<chopper.Response> onResponse(chopper.Response response) {
  var httpResponse = AliceHttpResponse();
  httpResponse.status = response.statusCode;
  if (response.body == null) {
    httpResponse.body = "";
    httpResponse.size = 0;
  } else {
    httpResponse.body = response.body;
    httpResponse.size = utf8.encode(response.body.toString()).length;
  }

  httpResponse.time = DateTime.now();
  Map<String, String> headers = Map();
  response.headers.forEach((header, values) {
    headers[header] = values.toString();
  });
  httpResponse.headers = headers;

  aliceCore.addResponse(
      httpResponse, getRequestHashCode(response.base.request!));
  return response;
}