<commit_before>// Quick'n'Dirty Mock API Server
// n.b., This only allows for hardcoded and parameterised routes
// ...No regexps :(

// AGPLv3 or later
// Copyright (c) 2014 Genome Research Limited

var express = require('express'),
    app     = express();

var routes  = require('./routes'),
    allowed = ('get,post,put,head,delete,trace,copy,lock,mkcol,move,' + 
              'purge,propfind,proppatch,unlock,report,mkactivity,' +
              'checkout,merge,m-search,notify,subscribe,unsubscribe,' +
              'patch,search,connect').split(',');

var authenticate = require('./authenticate');

// Set up route handlers
Object.keys(routes).forEach(function(route) {
  var routeVerbs = Object.keys(routes[route]);

  // Catch all middleware for 401 and 405s
  app.all(route, authenticate, function(req, res, next) {
    var verb = req.method.toLowerCase();

    if (verb == 'options' || routeVerbs.indexOf(verb) != -1) {
      next();

    } else {
      // Not cool
      res.status(405).send('Method Not Allowed');
    }
  });

  // Set up OPTIONS handler
  app.options(route, function(req, res) {
    var allow = routeVerbs.map(function(x) { return x.toUpperCase(); })
                          .concat('OPTIONS')
                          .join(',');

    res.set('Allow', allow);
    res.send();
  });

  // Set defined request handlers
  routeVerbs.forEach(function(verb) {
    // Fail on unhandlable verb
    // n.b., We explicitly disallow OPTIONS, because we sort that out
    // ourselves automagically (i.e., see above)
    if (allowed.indexOf(verb) == -1) {
      throw new Error('I do not know how to \'' + verb.toUpperCase() + '\' ' + route)
    }<commit_msg>...Oops! This is much more obvious and efficient<commit_after>// Quick'n'Dirty Mock API Server
// n.b., This only allows for hardcoded and parameterised routes
// ...No regexps :(

// AGPLv3 or later
// Copyright (c) 2014 Genome Research Limited

var express = require('express'),
    app     = express();

var routes  = require('./routes'),
    allowed = ('get,post,put,head,delete,trace,copy,lock,mkcol,move,' + 
              'purge,propfind,proppatch,unlock,report,mkactivity,' +
              'checkout,merge,m-search,notify,subscribe,unsubscribe,' +
              'patch,search,connect').split(',');

var authenticate = require('./authenticate');

// Set up route handlers
Object.keys(routes).forEach(function(route) {
  var routeVerbs = Object.keys(routes[route]);

  // Catch all middleware for 401 and 405s
  app.all(route, authenticate, function(req, res, next) {
    var verb = req.method.toLowerCase();

    if (verb == 'options' || routeVerbs.indexOf(verb) != -1) {
      next();

    } else {
      // Not cool
      res.status(405).send('Method Not Allowed');
    }
  });

  // Set up OPTIONS handler
  app.options(route, function(req, res) {
    var allow = routeVerbs.join(',').toUpperCase() + ',OPTIONS';

    res.set('Allow', allow);
    res.send();
  });

  // Set defined request handlers
  routeVerbs.forEach(function(verb) {
    // Fail on unhandlable verb
    // n.b., We explicitly disallow OPTIONS, because we sort that out
    // ourselves automagically (i.e., see above)
    if (allowed.indexOf(verb) == -1) {
      throw new Error('I do not know how to \'' + verb.toUpperCase() + '\' ' + route)
    }
{'fraction_non_alphanumeric': 0.15605191669182011, 'fraction_numerical': 0.009658919408391186, 'mean_word_length': 2.885111371629543, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6398795', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1020, 'n_words': 264}