<commit_before>

var	_ = require("lodash"),
	jwt = require("jsonwebtoken"),
	utils = require("./utils");

module.exports = function(options){

	if(!options.client || !options.secret)
		throw new Error("Redis client and secret required for jwtRedisSession!");

	options = {
		client: options.client,
		secret: options.secret,
		algorithm: options.algorithm || "HS256",
		keyspace: options.keyspace || "sess:",
		maxAge: options.maxAge || 86400,
		requestKey: options.requestKey || "session",
		requestArg: options.requestArg || "accessToken"
	};

	var sessionMethods = utils(options);

	var requestHeader = _.reduce(options.requestArg.split(""), function(memo, ch){
		return memo + (ch.toUpperCase() === ch ? "-" + ch.toLowerCase() : ch);
	}, "x" + (options.requestArg.charAt(0) === options.requestArg.charAt(0).toUpperCase() ? "" : "-"));

	return function(req, res, next){

		req[options.requestKey] = {};

		_.assign(req[options.requestKey], sessionMethods);

		var token = req.param ? req.param(options.requestArg) : false;
		token = token || req.headers[requestHeader];
		token = token || (req.cookies ? req.cookies[requestHeader] : false);

		if(token){
			jwt.verify(token, options.secret, function(error, decoded){
				if(error || !decoded.jti)
					return next();

				options.client.get(options.keyspace + decoded.jti, function(err, session){
					if(err || !session)
						return next();

					try{
						session = JSON.parse(session);
					}catch(e){
						return next();
					}

					_.assign(req[options.requestKey], session);
					req[options.requestKey].claims = decoded;
					req[options.requestKey].id = decoded.jti;
					req[options.requestKey].jwt = token;
					req[options.requestKey].touch(); // update the TTL
					next();
				});
			});
		}else{
			next();
		}
	};

};<commit_msg>Update jwtRedisSession.js<commit_after>
var	jwt = require("jsonwebtoken"),
	utils = require("./utils");

module.exports = function(options){

	if(!options.client || !options.secret)
		throw new Error("Redis client and secret required for jwtRedisSession!");

	options = {
		client: options.client,
		secret: options.secret,
		algorithm: options.algorithm || "HS256",
		keyspace: options.keyspace || "sess:",
		maxAge: options.maxAge || 86400,
		requestKey: options.requestKey || "session",
		requestArg: options.requestArg || "accessToken"
	};

	var sessionMethods = utils(options);

	var requestHeader = options.requestArg.split("").reduce(function(memo, ch){
		return memo + (ch.toUpperCase() === ch ? "-" + ch.toLowerCase() : ch);
	}, "x" + (options.requestArg.charAt(0) === options.requestArg.charAt(0).toUpperCase() ? "" : "-"));

	return function(req, res, next){

		req[options.requestKey] = {};

		req[options.requestKey] = Object.assign(sessionMethods);

		var token = req.param ? req.param(options.requestArg) : false;
		token = token || req.headers[requestHeader];
		token = token || (req.cookies ? req.cookies[requestHeader] : false);

		if(token){
			jwt.verify(token, options.secret, function(error, decoded){
				if(error || !decoded.jti)
					return next();

				options.client.get(options.keyspace + decoded.jti, function(err, session){
					if(err || !session)
						return next();

					try{
						session = JSON.parse(session);
					}catch(e){
						return next();
					}

					req[options.requestKey] = Object.assign(session);
					req[options.requestKey].claims = decoded;
					req[options.requestKey].id = decoded.jti;
					req[options.requestKey].jwt = token;
					req[options.requestKey].touch(); // update the TTL
					next();
				});
			});
		}else{
			next();
		}
	};
};
{'fraction_non_alphanumeric': 0.16995279089141904, 'fraction_numerical': 0.005554012774229381, 'mean_word_length': 3.8155080213903743, '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': '1643010', 'n_tokens_mistral': 1381, 'n_tokens_neox': 1155, 'n_words': 229}