From 5554ccb660c96f9e4ce75a2b1fac9482761021ab Mon Sep 17 00:00:00 2001 From: Jason Koneczny Date: Sat, 29 Jul 2017 15:26:45 -0700 Subject: [PATCH] Passing in repository key from throttling implementations' ComputeThrottleKey to ProcessRequest instead of always using core ComputeThrottleKey method. --- WebApiThrottle/ThrottlingCore.cs | 4 +--- WebApiThrottle/ThrottlingFilter.cs | 4 ++-- WebApiThrottle/ThrottlingHandler.cs | 4 ++-- WebApiThrottle/ThrottlingMiddleware.cs | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/WebApiThrottle/ThrottlingCore.cs b/WebApiThrottle/ThrottlingCore.cs index 5e41d32..747ca66 100644 --- a/WebApiThrottle/ThrottlingCore.cs +++ b/WebApiThrottle/ThrottlingCore.cs @@ -184,7 +184,7 @@ internal List> RatesWithDefaults(List 0) { // increment counter - string requestId; - var throttleCounter = core.ProcessRequest(identity, timeSpan, rateLimitPeriod, out requestId); + var requestId = ComputeThrottleKey(identity, rateLimitPeriod); + var throttleCounter = core.ProcessRequest(timeSpan, requestId); // check if key expired if (throttleCounter.Timestamp + timeSpan < DateTime.UtcNow) diff --git a/WebApiThrottle/ThrottlingHandler.cs b/WebApiThrottle/ThrottlingHandler.cs index 7bdcd40..93e5bb1 100644 --- a/WebApiThrottle/ThrottlingHandler.cs +++ b/WebApiThrottle/ThrottlingHandler.cs @@ -177,8 +177,8 @@ protected override Task SendAsync(HttpRequestMessage reques if (rateLimit > 0) { // increment counter - string requestId; - var throttleCounter = core.ProcessRequest(identity, timeSpan, rateLimitPeriod, out requestId); + var requestId = ComputeThrottleKey(identity, rateLimitPeriod); + var throttleCounter = core.ProcessRequest(timeSpan, requestId); // check if key expired if (throttleCounter.Timestamp + timeSpan < DateTime.UtcNow) diff --git a/WebApiThrottle/ThrottlingMiddleware.cs b/WebApiThrottle/ThrottlingMiddleware.cs index a9be672..0178d16 100644 --- a/WebApiThrottle/ThrottlingMiddleware.cs +++ b/WebApiThrottle/ThrottlingMiddleware.cs @@ -173,8 +173,8 @@ public override async Task Invoke(IOwinContext context) if (rateLimit > 0) { // increment counter - string requestId; - var throttleCounter = core.ProcessRequest(identity, timeSpan, rateLimitPeriod, out requestId); + var requestId = ComputeThrottleKey(identity, rateLimitPeriod); + var throttleCounter = core.ProcessRequest(timeSpan, requestId); // check if key expired if (throttleCounter.Timestamp + timeSpan < DateTime.UtcNow)