Skip to content

Commit

Permalink
Merge pull request #55 from SwintDC/master
Browse files Browse the repository at this point in the history
Issue 54 make it possible to add Reset header when using the FixedWin…
  • Loading branch information
cristipufu authored Apr 21, 2023
2 parents 54fb56d + 9580775 commit 27cfdf5
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 27cfdf5

Please sign in to comment.