<commit_before>var http = require('http')
var crypto = require('crypto')
var concat = require('concat-stream')

var handlers = {
  '/api/login': loginHandler
}

exports.createServer = function (opts) {
  opts = opts || {}
  opts.users = opts.users || []

  return http.createServer(function (req, res) {
    if (!handlers[req.url]) {
      res.statusCode = 404
      res.end()
    }

    res.setHeader('Content-Type', 'application/json')

    req.pipe(concat(function (data) {

      try {
        req.body = JSON.parse(data)
      } catch (er) {
        res.statusCode = 400
        return res.end()
      }

      handlers[req.url](opts, req, res)
    }))
  })
}

function loginHandler (opts, req, res) {
  var user = findUser(req.body.username, req.body.password, opts.users)

  if (!user) {
    res.statusCode = 401
    res.end()
  }

  var hash = crypto.createHash('sha256').update(crypto.randomBytes(256)).digest('base64')

  res.write(JSON.stringify({
    user: user,
    authHeader: 'Basic ' + hash
  }))
  res.end()<commit_msg>Return if no user<commit_after>var http = require('http')
var crypto = require('crypto')
var concat = require('concat-stream')

var handlers = {
  '/api/login': loginHandler
}

exports.createServer = function (opts) {
  opts = opts || {}
  opts.users = opts.users || []

  return http.createServer(function (req, res) {
    if (!handlers[req.url]) {
      res.statusCode = 404
      res.end()
    }

    res.setHeader('Content-Type', 'application/json')

    req.pipe(concat(function (data) {

      try {
        req.body = JSON.parse(data)
      } catch (er) {
        res.statusCode = 400
        return res.end()
      }

      handlers[req.url](opts, req, res)
    }))
  })
}

function loginHandler (opts, req, res) {
  var user = findUser(req.body.username, req.body.password, opts.users)

  if (!user) {
    res.statusCode = 401
    return res.end()
  }

  var hash = crypto.createHash('sha256').update(crypto.randomBytes(256)).digest('base64')

  res.write(JSON.stringify({
    user: user,
    authHeader: 'Basic ' + hash
  }))
  res.end()
{'fraction_non_alphanumeric': 0.1603456553048488, 'fraction_numerical': 0.01632261161785886, 'mean_word_length': 2.8238532110091743, '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': '1604575', 'n_tokens_mistral': 741, 'n_tokens_neox': 688, 'n_words': 143}