<commit_before>part of bridge.http;

UrlGenerator _urlGenerator;

class HttpServiceProvider extends ServiceProvider {
  Server server;
  Router router;
  Program program;

  setUp(Container container,
        Server server,
        Router router,
        _ResponseMapper responseMapper,
        SessionManager manager) {
    this.server = server;
    this.router = router;

    server.attachRouter(router);

    container.singleton(responseMapper);
    container.singleton(server, as: Server);
    container.singleton(router, as: Router);
    container.singleton(manager);
  }

  load(Program program,
       SessionsMiddleware sessionsMiddleware,
       CsrfMiddleware csrfMiddleware,
       StaticFilesMiddleware staticFilesMiddleware,
       InputMiddleware inputMiddleware,
       UrlGenerator urlGenerator) {
    _urlGenerator = urlGenerator;

    server.addMiddleware(sessionsMiddleware, highPriority: true);
    server.addMiddleware(staticFilesMiddleware);
    server.addMiddleware(inputMiddleware);
    server.addMiddleware(csrfMiddleware);
    server.onError = (e, s) {
      print('');
      program.printInfo(new trace.Chain.forTrace(s).terse
      .toString().split('\n').toList().reversed.join('\n'));
      print('');
      program.printWarning('<underline>Error in HTTP layer:</underline>');
      program.printInfo(e);
      print('');
    };

    this.program = program;
    program.addCommand(start);
    program.addCommand(stop);
    program.addCommand(routes);
  }

  tearDown() async {
    await stop();
  }

  @Command('Start the server')
  start() async {
    await server.start();
    program.printInfo('Server started on http://${server.hostname}:${server.port}');
  }

  @Command('Stop the server')
  stop() async {
    try {
      await server.stop();
      program.printInfo('Server stopped');
    } catch (e) {
    }
  }

  @Command('List all the end-points defined in the router')
  routes() async {
    var table = new dlog.Table(3);

    table.columns.addAll([
      'Method',
      'End-point',
      'Name',
    ]);

    for (var row in router._routes) {
      table.data.addAll([
        row.method,
        row.route,
        row.name == null ? '' : row.name,
      ]);
    }

    print(table);
  }
}
<commit_msg>Explicitly complain when HTTP exception is not caught<commit_after>part of bridge.http;

UrlGenerator _urlGenerator;

class HttpServiceProvider extends ServiceProvider {
  Server server;
  Router router;
  Program program;

  setUp(Container container,
        Server server,
        Router router,
        _ResponseMapper responseMapper,
        SessionManager manager) {
    this.server = server;
    this.router = router;

    server.attachRouter(router);

    container.singleton(responseMapper);
    container.singleton(server, as: Server);
    container.singleton(router, as: Router);
    container.singleton(manager);
  }

  load(Program program,
       SessionsMiddleware sessionsMiddleware,
       CsrfMiddleware csrfMiddleware,
       StaticFilesMiddleware staticFilesMiddleware,
       InputMiddleware inputMiddleware,
       UrlGenerator urlGenerator) {
    _urlGenerator = urlGenerator;

    server.addMiddleware(sessionsMiddleware, highPriority: true);
    server.addMiddleware(staticFilesMiddleware);
    server.addMiddleware(inputMiddleware);
    server.addMiddleware(csrfMiddleware);
    server.onError = (e, s) {
      print('');
      program.printDanger(new trace.Chain.forTrace(s).terse
      .toString().split('\n').toList().reversed.join('\n'));
      print('');
      program.printWarning('<underline>Uncaught HTTP exception</underline>');
      program.printDanger(e);
      print('');
    };

    this.program = program;
    program.addCommand(start);
    program.addCommand(stop);
    program.addCommand(routes);
  }

  tearDown() async {
    await stop();
  }

  @Command('Start the server')
  start() async {
    await server.start();
    program.printInfo('Server started on http://${server.hostname}:${server.port}');
  }

  @Command('Stop the server')
  stop() async {
    try {
      await server.stop();
      program.printInfo('Server stopped');
    } catch (e) {
    }
  }

  @Command('List all the end-points defined in the router')
  routes() async {
    var table = new dlog.Table(3);

    table.columns.addAll([
      'Method',
      'End-point',
      'Name',
    ]);

    for (var row in router._routes) {
      table.data.addAll([
        row.method,
        row.route,
        row.name == null ? '' : row.name,
      ]);
    }

    print(table);
  }
}

{'fraction_non_alphanumeric': 0.12431243124312431, 'fraction_numerical': 0.00044004400440044003, 'mean_word_length': 2.998240985048373, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2964301', 'n_tokens_mistral': 1319, 'n_tokens_neox': 1334, 'n_words': 274}