diff --git a/src/main/java/io/github/poshjosh/ratelimiter/web/spring/RateLimitingFilter.java b/src/main/java/io/github/poshjosh/ratelimiter/web/spring/RateLimitingFilter.java index 4102663..fd42bc5 100644 --- a/src/main/java/io/github/poshjosh/ratelimiter/web/spring/RateLimitingFilter.java +++ b/src/main/java/io/github/poshjosh/ratelimiter/web/spring/RateLimitingFilter.java @@ -55,27 +55,24 @@ protected void initFilterBean() throws ServletException { super.initFilterBean(); + if (rateLimiterFactory != null) { + return; + } + WebRateLimiterContext context = rateLimiterContextBuilder().build(); if (webRateLimiterRegistry == null) { webRateLimiterRegistry = rateLimiterRegistry(context); } - if (rateLimiterFactory != null) { - return; - } + rateLimiterFactory = webRateLimiterRegistry.createRateLimiterFactory(); - if (!context.hasRateSources()) { - rateLimiterFactory = RateLimiterFactory.noop(); - } else { - rateLimiterFactory = webRateLimiterRegistry.createRateLimiterFactory(); - } LOG.info(webRateLimiterRegistry.isRateLimitingEnabled() ? "Completed setup of automatic rate limiting" : "Rate limiting is disabled"); } - protected WebRateLimiterRegistry rateLimiterRegistry(WebRateLimiterContext config) { - return WebRateLimiterRegistrySpring.of(config); + protected WebRateLimiterRegistry rateLimiterRegistry(WebRateLimiterContext context) { + return WebRateLimiterRegistrySpring.of(context); } protected WebRateLimiterContext.Builder rateLimiterContextBuilder() {