Skip to content

Commit 04054db

Browse files
committed
TD_5410_Adding config to the rate limiter so that we can conpare the environment, and add production logic to it.
1 parent 95a3da4 commit 04054db

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
namespace DigitalLearningSolutions.Web.Middleware
22
{
3+
using System;
34
using System.Threading.Tasks;
45
using AspNetCoreRateLimit;
56
using Microsoft.AspNetCore.Http;
7+
using Microsoft.Extensions.Configuration;
68
using Microsoft.Extensions.Logging;
79
using Microsoft.Extensions.Options;
10+
using static Org.BouncyCastle.Math.EC.ECCurve;
811

912
public class DLSIPRateLimitMiddleware : IpRateLimitMiddleware
1013
{
14+
private readonly IConfiguration _configuration;
1115
public DLSIPRateLimitMiddleware(
1216
RequestDelegate next,
1317
IProcessingStrategy processingStrategy,
1418
IOptions<IpRateLimitOptions> options,
19+
IConfiguration configuration,
1520
IIpPolicyStore policyStore,
1621
IRateLimitConfiguration config,
1722
ILogger<IpRateLimitMiddleware> logger)
@@ -21,16 +26,23 @@ public DLSIPRateLimitMiddleware(
2126
policyStore,
2227
config,
2328
logger)
24-
{ }
29+
{
30+
_configuration = configuration;
31+
}
2532

2633
public override Task ReturnQuotaExceededResponse(
2734
HttpContext httpContext,
2835
RateLimitRule rule,
2936
string retryAfter)
3037
{
31-
httpContext.Response.Headers["Location"] = "/toomanyrequests";
32-
httpContext.Response.StatusCode = 302;
38+
if (_configuration["ASPNETCORE_ENVIRONMENT"] == "PRODUCTION")
39+
{
40+
httpContext.Response.Headers["Location"] = "/toomanyrequests";
41+
httpContext.Response.StatusCode = 302;
42+
43+
}
3344
return httpContext.Response.WriteAsync("");
45+
3446
}
3547
}
3648
}

0 commit comments

Comments
 (0)