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