<commit_before>var base64 = require("base64");

var sys = require("sys");

module.exports = function basicAuth(callback) {
  function unauthorized(res) {
    res.writeHead(401);
    res.end();
  }

  return function(req, res, next) {
    var authorization = req.headers.authorization;

    if (!authorization)
      unauthorized(res);

    var parts  = authorization.split(" ");
    var scheme = parts[0];

    if (scheme === "Basic") {
      var credentials = base64.decode(parts[1]).split(":");

      if (callback(credentials[0], credentials[1]) === true) {
        req.headers["remote_user"] = credentials[0];
        next();
      } else {
        unauthorized(res);
      }
    } else {
      res.writeHead(400);
      res.end();
    }
  }
}

module.exports.encode = function encode(user, password) {
  return "Basic " + base64.encode(user + ":" + password);
}<commit_msg>even smaller<commit_after>var base64 = require("base64");

var sys = require("sys");

module.exports = function basicAuth(callback) {
  function unauthorized(res) {
    res.writeHead(401);
    res.end();
  }

  return function(req, res, next) {
    var authorization = req.headers.authorization;

    if (!authorization)
      unauthorized(res);

    var parts       = authorization.split(" ");
    var scheme      = parts[0];
    var credentials = base64.decode(parts[1]).split(":");

    if (scheme !== "Basic") {
      res.writeHead(400);
      res.end();
    }

    if (callback(credentials[0], credentials[1]) === true) {
      req.headers["remote_user"] = credentials[0];
      next();
    } else {
      unauthorized(res);
    }
  }
}

module.exports.encode = function encode(user, password) {
  return "Basic " + base64.encode(user + ":" + password);
}
{'fraction_non_alphanumeric': 0.16340621403912542, 'fraction_numerical': 0.02186421173762946, 'mean_word_length': 2.9977011494252874, 'pattern_counts': {'":': 4, '<': 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': '705321', 'n_tokens_mistral': 568, 'n_tokens_neox': 534, 'n_words': 110}