Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 54 make it possible to add Reset header when using the FixedWin… #55

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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