Skip to content
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
namespace DigitalLearningSolutions.Web.Middleware
{
using System;
using System.Threading.Tasks;
using AspNetCoreRateLimit;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using static Org.BouncyCastle.Math.EC.ECCurve;

public class DLSIPRateLimitMiddleware : IpRateLimitMiddleware
{
private readonly IConfiguration _configuration;
public DLSIPRateLimitMiddleware(
RequestDelegate next,
IProcessingStrategy processingStrategy,
IOptions<IpRateLimitOptions> options,
IConfiguration configuration,
IIpPolicyStore policyStore,
IRateLimitConfiguration config,
ILogger<IpRateLimitMiddleware> logger)
Expand All @@ -21,16 +26,23 @@ public DLSIPRateLimitMiddleware(
policyStore,
config,
logger)
{ }
{
_configuration = configuration;
}

public override Task ReturnQuotaExceededResponse(
HttpContext httpContext,
RateLimitRule rule,
string retryAfter)
{
httpContext.Response.Headers["Location"] = "/toomanyrequests";
httpContext.Response.StatusCode = 302;
if (_configuration["ASPNETCORE_ENVIRONMENT"] == "PRODUCTION")
{
httpContext.Response.Headers["Location"] = "/toomanyrequests";
httpContext.Response.StatusCode = 302;

}
return httpContext.Response.WriteAsync("");

}
}
}
Loading