/** * Applies a key to the rate limit that defines to which keys, the rule applies, empty for any unmatched key. * * @param keys Defines a set of keys to which the rule applies. * @return a limit rule */ public RequestLimitRule matchingKeys(String... keys) { Set<String> keySet = keys.length > 0 ? new HashSet<>(Arrays.asList(keys)) : null; return matchingKeys(keySet); }
DefaultRequestLimitRulesSupplierTest() { allRules.add(RequestLimitRule.of(Duration.ofSeconds(1), 10).withName("localhostPerSeconds") .matchingKeys("localhost", "127.0.0.1")); allRules.add(RequestLimitRule.of(Duration.ofHours(1), 2000).withName("localhostPerHours") .matchingKeys("localhost", "127.0.0.1")); allRules.add(RequestLimitRule.of(Duration.ofSeconds(1), 5).withName("perSeconds")); allRules.add(RequestLimitRule.of(Duration.ofHours(1), 1000).withName("perHours")); requestLimitRulesSupplier = new DefaultRequestLimitRulesSupplier(allRules); }