11namespace 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