Sessie: een start-refresh zonder oordeel (429/5xx/netwerk) zet de gebruiker niet meer op gast maar toont een retry-scherm; Retry-After wordt gestuurd en gerespecteerd

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 21:04:49 +01:00
co-authored by Claude Sonnet 5.5
parent b8f6b25121
commit 64a467b41b
12 changed files with 297 additions and 12 deletions
@@ -183,6 +183,29 @@ public static class ServiceCollectionExtensions
.GetMetadata<EnableRateLimitingAttribute>()?.PolicyName ?? "(unknown)",
context.HttpContext.Request.Path);
// Tells a well-behaved client (the admin app's start-up retries) how long to wait, instead of
// having it retry into the same window and stay limited.
// A sliding-window lease carries no RetryAfter, so the "refresh" policy falls back to one segment
// (a quarter of the window: the earliest moment a permit frees up); other policies to their window.
var policyName = context.HttpContext.GetEndpoint()?.Metadata.GetMetadata<EnableRateLimitingAttribute>()?.PolicyName;
var section = policyName switch
{
"login" => "Login",
"refresh" => "Refresh",
_ => null
};
double? waitSeconds = null;
if (context.Lease.TryGetMetadata(MetadataName.RetryAfter, out var retryAfter))
waitSeconds = retryAfter.TotalSeconds;
else if (section is not null)
{
var window = configuration.GetValue<int>($"RateLimiting:{section}:WindowSeconds", 60);
waitSeconds = policyName == "refresh" ? window / 4.0 : window;
}
if (waitSeconds is not null)
context.HttpContext.Response.Headers.RetryAfter =
Math.Max(1, (int)Math.Ceiling(waitSeconds.Value)).ToString(System.Globalization.CultureInfo.InvariantCulture);
return ValueTask.CompletedTask;
};