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
8 changes: 4 additions & 4 deletions dev-proxy-plugins/RandomErrors/GenericRandomErrorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal enum GenericRandomErrorFailMode
public class GenericRandomErrorConfiguration
{
public string? ErrorsFile { get; set; }
public int RetryAfterInSeconds { get; set; } = 5;
[JsonPropertyName("responses")]
public IEnumerable<GenericErrorResponse> Responses { get; set; } = Array.Empty<GenericErrorResponse>();
}
Expand All @@ -34,7 +35,6 @@ public class GenericRandomErrorPlugin : BaseProxyPlugin

public override string Name => nameof(GenericRandomErrorPlugin);

private const int retryAfterInSeconds = 5;
private readonly Random _random;

public GenericRandomErrorPlugin()
Expand All @@ -55,7 +55,7 @@ private void FailResponse(ProxyRequestArgs e, GenericRandomErrorFailMode failMod
private ThrottlingInfo ShouldThrottle(Request request, string throttlingKey)
{
var throttleKeyForRequest = BuildThrottleKey(request);
return new ThrottlingInfo(throttleKeyForRequest == throttlingKey ? retryAfterInSeconds : 0, "Retry-After");
return new ThrottlingInfo(throttleKeyForRequest == throttlingKey ? _configuration.RetryAfterInSeconds : 0, "Retry-After");
}

private void UpdateProxyResponse(ProxyRequestArgs e, GenericErrorResponse error)
Expand All @@ -72,7 +72,7 @@ private void UpdateProxyResponse(ProxyRequestArgs e, GenericErrorResponse error)
error.Headers is not null &&
error.Headers.FirstOrDefault(h => h.Name == "Retry-After" || h.Name == "retry-after")?.Value == "@dynamic")
{
var retryAfterDate = DateTime.Now.AddSeconds(retryAfterInSeconds);
var retryAfterDate = DateTime.Now.AddSeconds(_configuration.RetryAfterInSeconds);
if (!e.GlobalData.ContainsKey(RetryAfterPlugin.ThrottledRequestsKey))
{
e.GlobalData.Add(RetryAfterPlugin.ThrottledRequestsKey, new List<ThrottlerInfo>());
Expand All @@ -82,7 +82,7 @@ error.Headers is not null &&
// replace the header with the @dynamic value with the actual value
var h = headers.First(h => h.Name == "Retry-After" || h.Name == "retry-after");
headers.Remove(h);
headers.Add(new("Retry-After", retryAfterInSeconds.ToString()));
headers.Add(new("Retry-After", _configuration.RetryAfterInSeconds.ToString()));
}

var statusCode = (HttpStatusCode)error.StatusCode;
Expand Down