onRequest method
Handles httpClientRequest and creates http alice call from it
Implementation
void onRequest(HttpClientRequest request, {dynamic body}) {
AliceHttpCall call = AliceHttpCall(request.hashCode);
call.loading = true;
call.client = "HttpClient (io package)";
call.method = request.method;
call.uri = request.uri.toString();
var path = request.uri.path;
if (path.length == 0) {
path = "/";
}
call.endpoint = path;
call.server = request.uri.host;
if (request.uri.scheme == "https") {
call.secure = true;
}
AliceHttpRequest httpRequest = AliceHttpRequest();
if (body == null) {
httpRequest.size = 0;
httpRequest.body = "";
} else {
httpRequest.size = utf8.encode(body.toString()).length;
httpRequest.body = body;
}
httpRequest.time = DateTime.now();
Map<String, dynamic> headers = Map();
httpRequest.headers.forEach((header, value) {
headers[header] = value;
});
httpRequest.headers = headers;
String contentType = "unknown";
if (headers.containsKey("Content-Type")) {
contentType = headers["Content-Type"];
}
httpRequest.contentType = contentType;
httpRequest.cookies = request.cookies;
call.request = httpRequest;
call.response = AliceHttpResponse();
aliceCore.addCall(call);
}