<commit_before>'use strict';

exports.register = function(plugin, opts, next) {
  if (!opts.password) {
    throw new Error('Missing required password in options');
  }
  if (!opts.sessionStoreName) {
    throw new Error('Missing required sessionStoreName in options');
  }

  var cookieName = opts.cookieName || 'sid';
  var sessionService = plugin.plugins[opts.sessionStoreName];

  var cookieOpts = {
    encoding: 'iron',
    ttl: opts.ttl || 1000 * 60 * 60 * 24,
    password: <PASSWORD>,
    isSecure: opts.isSecure !== false,
    isHttpOnly: opts.isHttpOnly !== false,
    path: '/'
  };
  plugin.state(cookieName, cookieOpts);

  plugin.decorate('request', 'getSession', function(cb) {
    var sessionId = this.state[cookieName];
    if (!sessionId) {
      cb(null, {});
      return;
    }
    sessionService.get(sessionId, cb);
  });

  plugin.decorate('reply', 'setSession', function(updatedSession, cb) {
    updatedSession.sid = updatedSession.sid || Math.random();
    this.state(cookieName, updatedSession.sid);
    sessionService.set(updatedSession.sid, updatedSession, cb);
  });

  next();
};

exports.register.attributes = {
  pkg: require('../package.json')
};<commit_msg>Returning cached session when available.<commit_after>'use strict';

exports.register = function(plugin, opts, next) {
  if (!opts.password) {
    throw new Error('Missing required password in options');
  }
  if (!opts.sessionStoreName) {
    throw new Error('Missing required sessionStoreName in options');
  }

  var cookieName = opts.cookieName || 'sid';
  var sessionService = plugin.plugins[opts.sessionStoreName];

  var cookieOpts = {
    encoding: 'iron',
    ttl: opts.ttl || 1000 * 60 * 60 * 24,
    password: <PASSWORD>,
    isSecure: opts.isSecure !== false,
    isHttpOnly: opts.isHttpOnly !== false,
    path: '/'
  };
  plugin.state(cookieName, cookieOpts);

  plugin.decorate('request', 'getSession', function(cb) {
    if (this.session) {
      cb(null, this.session);
      return;
    }
    var sessionId = this.state[cookieName];
    if (!sessionId) {
      cb(null, {});
      return;
    }
    sessionService.get(sessionId, function(err, session) {
      if (!err) {
        this.session = session;
      }
      cb(err, session);
    }.bind(this));
  });

  plugin.decorate('reply', 'setSession', function(updatedSession, cb) {
    updatedSession.sid = updatedSession.sid || Math.random();
    this.state(cookieName, updatedSession.sid);
    sessionService.set(updatedSession.sid, updatedSession, cb);
  });

  next();
};

exports.register.attributes = {
  pkg: require('../package.json')
};
{'fraction_non_alphanumeric': 0.15184049079754602, 'fraction_numerical': 0.007668711656441718, 'mean_word_length': 3.5216637781629117, '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': '7168606', 'n_tokens_mistral': 833, 'n_tokens_neox': 803, 'n_words': 177}