1. override
Future<Response> handle(Request request)

Source

@override Future<Response> handle(Request request) async {
  final beforeTime = new DateTime.now();
  duration() => beforeTime.difference(new DateTime.now());
  try {
    final response = await super.handle(request);
    final controller = new StreamController<List<int>>();
    var errored = false;
    response.read().listen(controller.add, onDone: () {
      controller.close();
      if (errored) return;
      _log(request, response.statusCode, duration());
    }, onError: (e, s) {
      _log(request, response.statusCode, duration(), failed: true);
      errored = true;
      controller.addError(e, s);
    });
    return response.change(body: controller.stream);
  } on NoResponseFromPipelineException {
    _log(request, 404, duration());
    rethrow;
  } on HttpException catch(e) {
    _log(request, e.statusCode, duration());
    rethrow;
  } catch(e) {
    _log(request, 500, duration());
    rethrow;
  }
}