onResponse method

void onResponse(
  1. HttpClientResponse response,
  2. HttpClientRequest request, {
  3. dynamic body,
})

Handles httpClientRequest and adds response to http alice call

Implementation

void onResponse(HttpClientResponse response, HttpClientRequest request,
    {dynamic body}) async {
  AliceHttpResponse httpResponse = AliceHttpResponse();
  httpResponse.status = response.statusCode;

  if (body != null) {
    httpResponse.body = body;
    httpResponse.size = utf8.encode(body.toString()).length;
  } else {
    httpResponse.body = "";
    httpResponse.size = 0;
  }
  httpResponse.time = DateTime.now();
  Map<String, String> headers = Map();
  response.headers.forEach((header, values) {
    headers[header] = values.toString();
  });
  httpResponse.headers = headers;
  aliceCore.addResponse(httpResponse, request.hashCode);
}