Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #105 from jlkoneczny/OverridableThrottlingKey
Browse files Browse the repository at this point in the history
Fixed ability to override ComputeThrottleKey
  • Loading branch information
stefanprodan authored Jul 30, 2017
2 parents 7de833f + 5554ccb commit abde47c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions WebApiThrottle/ThrottlingCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,14 @@ internal List<KeyValuePair<RateLimitPeriod, long>> RatesWithDefaults(List<KeyVal
return defRates;
}

internal ThrottleCounter ProcessRequest(RequestIdentity requestIdentity, TimeSpan timeSpan, RateLimitPeriod period, out string id)
internal ThrottleCounter ProcessRequest(TimeSpan timeSpan, string id)
{
var throttleCounter = new ThrottleCounter()
{
Timestamp = DateTime.UtcNow,
TotalRequests = 1
};

id = ComputeThrottleKey(requestIdentity, period);

// serial reads and writes
lock (ProcessLocker)
{
Expand Down
4 changes: 2 additions & 2 deletions WebApiThrottle/ThrottlingFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public override void OnActionExecuting(HttpActionContext actionContext)
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)
Expand Down
4 changes: 2 additions & 2 deletions WebApiThrottle/ThrottlingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ protected override Task<HttpResponseMessage> 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)
Expand Down
4 changes: 2 additions & 2 deletions WebApiThrottle/ThrottlingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit abde47c

Please sign in to comment.