<commit_before>var redback = require('redback'),
	Hoek = require('hoek'),
	Defaults = require('./defaults');

exports.register = function (plugin, options, next) {
	var settings = Hoek.applyToDefaults(Defaults, options);
	if (!settings.enabled) {
		return next();
	}

	var ratelimit;
	if (options.client) {
		ratelimit = redback.use(options.client).createRateLimit('requests');
	} else {
		ratelimit = redback.createClient().createRateLimit('requests');
	}

	var error = plugin.hapi.error.wrap(new Error(), settings.error.code, settings.error.message);
	error.reformat();

	plugin.ext('onRequest', function(request, reply) {
		if (request.path.match(settings.path)) {
			ratelimit.add(request.info.remoteAddress);

			ratelimit.count(request.info.remoteAddress, settings.interval, function (err, requests) {
				if (!err && requests > settings.requestLimit) {
					return reply(error);
				} else {
					return reply();
				}
			});
		} else {
			return reply();
		}
	});

	return next();
};<commit_msg>Update plugin to work with version 6<commit_after>var redback = require('redback'),
	Hoek = require('hoek'),
	Defaults = require('./defaults');

exports.register = function (plugin, options, next) {
	var settings = Hoek.applyToDefaults(Defaults, options);
	if (!settings.enabled) {
		return next();
	}

	var ratelimit;
	if (options.client) {
		ratelimit = redback.use(options.client).createRateLimit('requests');
	} else {
		ratelimit = redback.createClient().createRateLimit('requests');
	}

	var error = plugin.hapi.error.wrap(new Error(), settings.error.code, settings.error.message);
	error.reformat();

	plugin.ext('onRequest', function(request, reply) {
		if (request.path.match(settings.path)) {
			ratelimit.add(request.info.remoteAddress);

			ratelimit.count(request.info.remoteAddress, settings.interval, function (err, requests) {
				if (!err && requests > settings.requestLimit) {
					return reply(error);
				} else {
					return reply();
				}
			});
		} else {
			return reply();
		}
	});

	return next();
};

exports.register.attributes = {
	pkg: require('../package.json')
};
{'fraction_non_alphanumeric': 0.16062917063870352, 'fraction_numerical': 0.00047664442326024784, 'mean_word_length': 4.313924050632911, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1913832', 'n_tokens_mistral': 738, 'n_tokens_neox': 656, 'n_words': 131}