Skip to content

Commit

Permalink
Issue 54 make it possible to add Reset header when using the FixedWin…
Browse files Browse the repository at this point in the history
…dowLimiter
  • Loading branch information
SwintDC committed Apr 21, 2023
1 parent 54fb56d commit 9580775
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected override RateLimitLease AttemptAcquireCore(int permitCount)

leaseContext.Count = response.Count;
leaseContext.RetryAfter = response.RetryAfter;
leaseContext.ExpiresAt = DateTimeOffset.FromUnixTimeSeconds(response.ExpiresAt);

if (leaseContext.Count > _options.PermitLimit)
{
Expand Down Expand Up @@ -114,6 +115,8 @@ private sealed class FixedWindowLeaseContext
public TimeSpan Window { get; set; }

public TimeSpan? RetryAfter { get; set; }

public DateTimeOffset? ExpiresAt { get; set; }
}

private sealed class FixedWindowLease : RateLimitLease
Expand Down Expand Up @@ -152,6 +155,12 @@ public override bool TryGetMetadata(string metadataName, out object? metadata)
return true;
}

if (metadataName == RateLimitMetadataName.Reset.Name && _context?.ExpiresAt is not null)
{
metadata = _context.ExpiresAt.Value;
return true;
}

metadata = default;
return false;
}
Expand Down

0 comments on commit 9580775

Please sign in to comment.