public static CaseInsensitiveMap<String> extractHeaders(HttpResponse response) {
    final CaseInsensitiveMap<String> headers = new CaseInsensitiveMap<String>();

    for (Header header : response.getAllHeaders()) {
      headers.add(header.getName(), header.getValue());
    }
    return headers;
  }
  // Interface to AsyncHttpRequest
  void sendResponseMessage(HttpResponse response) {
    StatusLine status = response.getStatusLine();
    String responseBody = null;
    try {
      HttpEntity entity = null;
      HttpEntity temp = response.getEntity();
      if (temp != null) {
        entity = new BufferedHttpEntity(temp);
        responseBody = EntityUtils.toString(entity, "UTF-8");
      }
    } catch (IOException e) {
      sendFailureMessage(e, (String) null);
    }

    if (status.getStatusCode() >= 300) {
      sendFailureMessage(
          new HttpResponseException(status.getStatusCode(), status.getReasonPhrase()),
          responseBody);
    } else {
      sendSuccessMessage(status.getStatusCode(), response.getAllHeaders(), responseBody);
    }
  }