Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions src/Throttlr.Api.RateLimit/Middleware/RateLimitingMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
context.Response.StatusCode = StatusCodes.Status429TooManyRequests;

// Add standard rate limit headers
context.Response.Headers[RetryAfter] = ((int)result.RetryAfter.Value.TotalSeconds).ToString();

Check warning on line 37 in src/Throttlr.Api.RateLimit/Middleware/RateLimitingMiddleware.cs

View workflow job for this annotation

GitHub Actions / build (6.0.x)

Nullable value type may be null.

Check warning on line 37 in src/Throttlr.Api.RateLimit/Middleware/RateLimitingMiddleware.cs

View workflow job for this annotation

GitHub Actions / build (6.0.x)

Nullable value type may be null.

Check warning on line 37 in src/Throttlr.Api.RateLimit/Middleware/RateLimitingMiddleware.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

Nullable value type may be null.

Check warning on line 37 in src/Throttlr.Api.RateLimit/Middleware/RateLimitingMiddleware.cs

View workflow job for this annotation

GitHub Actions / build (8.0.x)

Nullable value type may be null.

Check warning on line 37 in src/Throttlr.Api.RateLimit/Middleware/RateLimitingMiddleware.cs

View workflow job for this annotation

GitHub Actions / demo-build

Nullable value type may be null.

Check warning on line 37 in src/Throttlr.Api.RateLimit/Middleware/RateLimitingMiddleware.cs

View workflow job for this annotation

GitHub Actions / demo-build

Nullable value type may be null.

Check warning on line 37 in src/Throttlr.Api.RateLimit/Middleware/RateLimitingMiddleware.cs

View workflow job for this annotation

GitHub Actions / build (7.0.x)

Nullable value type may be null.

Check warning on line 37 in src/Throttlr.Api.RateLimit/Middleware/RateLimitingMiddleware.cs

View workflow job for this annotation

GitHub Actions / build (7.0.x)

Nullable value type may be null.
context.Response.Headers[RateLimitLimit] = _rateLimiter.GetLimit().ToString();
context.Response.Headers[RateLimitRemaining] = result.Remaining.ToString();
context.Response.Headers[RateLimitReset] = result.Reset?.ToUnixTimeSeconds().ToString();
Expand All @@ -56,41 +56,5 @@
// Default: use IP address. Could be swapped for API key / user ID.
return context.Connection.RemoteIpAddress?.ToString() ?? "unknown";
}

///// <summary>
///// Processes the HTTP request, applying rate limiting.
///// </summary>
//public async Task InvokeAsync(HttpContext context)
//{
// var requestKey = context.Connection.RemoteIpAddress?.ToString() ?? "unknown";

// var rateLimitContext = new RateLimitContext(requestKey);
// var result = await _rateLimiter.CheckAsync(rateLimitContext, context.RequestAborted);

// if (!result.Allowed)
// {
// context.Response.StatusCode = StatusCodes.Status429TooManyRequests;

// if (result.RetryAfter.HasValue)
// {
// context.Response.Headers["Retry-After"] =
// ((int)result.RetryAfter.Value.TotalSeconds).ToString();
// }

// if (result.Reset.HasValue)
// {
// context.Response.Headers["X-RateLimit-Reset"] =
// ((int)result.Reset.Value.TotalSeconds).ToString();
// }

// context.Response.Headers["X-RateLimit-Remaining"] = "0";
// return;
// }

// context.Response.Headers["X-RateLimit-Remaining"] =
// result.Remaining?.ToString() ?? "unknown";

// await _next(context);
//}
}
}
Loading