<commit_before>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';

import 'package:shelf_static/shelf_static.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf/shelf.dart';

const String usage = 'Usage: sky_server PORT';

main(List<String> argv) async {
  if (argv.length != 1) {
    print(usage);
    return;
  }

  int port;
  try {
    port = int.parse(argv[0]);
  } catch(e) {
    print(usage);
    return;
  }

  Handler handler = createStaticHandler(Directory.current.path,
      serveFilesOutsidePath: true);

  HttpServer server;
  try {
    server = await io.serve(handler, InternetAddress.LOOPBACK_IP_V4, port);
  } catch(e) {
    print(e);
    return;
  }

  server.defaultResponseHeaders
    ..removeAll('x-content-type-options')
    ..removeAll('x-frame-options')
    ..removeAll('x-xss-protection')
    ..add('cache-control', 'no-cache');
}
<commit_msg>Add the option to log to sky_server<commit_after>// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';

import 'package:args/args.dart';
import 'package:shelf_static/shelf_static.dart';
import 'package:shelf/shelf_io.dart' as io;
import 'package:shelf/shelf.dart';

void printUsage(parser) {
  print('Usage: sky_server [-v] PORT');
  print(parser.usage);
}

main(List<String> argv) async {
  ArgParser parser = new ArgParser();
  parser.addFlag('help', abbr: 'h', negatable: false,
                 help: 'Display this help message.');
  parser.addFlag('verbose', abbr: 'v', negatable: false,
                 help: 'Log requests to stdout.');

  ArgResults args = parser.parse(argv);

  if (args['help'] || args.rest.length != 1) {
    printUsage(parser);
    return;
  }

  int port;
  try {
    port = int.parse(args.rest[0]);
  } catch(e) {
    printUsage(parser);
    return;
  }

  Handler handler = createStaticHandler(Directory.current.path,
      serveFilesOutsidePath: true);

  if (args['verbose'])
    handler = const Pipeline().addMiddleware(logRequests()).addHandler(handler);

  HttpServer server;
  try {
    server = await io.serve(handler, InternetAddress.LOOPBACK_IP_V4, port);
  } catch(e) {
    print(e);
    return;
  }

  server.defaultResponseHeaders
    ..removeAll('x-content-type-options')
    ..removeAll('x-frame-options')
    ..removeAll('x-xss-protection')
    ..add('cache-control', 'no-cache');
}

{'fraction_non_alphanumeric': 0.1421378776142525, 'fraction_numerical': 0.005422153369481022, 'mean_word_length': 3.531578947368421, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5243741', 'n_tokens_mistral': 886, 'n_tokens_neox': 848, 'n_words': 206}