@@ -22,6 +22,7 @@ internal enum GenericRandomErrorFailMode
22
22
public class GenericRandomErrorConfiguration
23
23
{
24
24
public string ? ErrorsFile { get ; set ; }
25
+ public int RetryAfterInSeconds { get ; set ; } = 5 ;
25
26
[ JsonPropertyName ( "responses" ) ]
26
27
public IEnumerable < GenericErrorResponse > Responses { get ; set ; } = Array . Empty < GenericErrorResponse > ( ) ;
27
28
}
@@ -34,7 +35,6 @@ public class GenericRandomErrorPlugin : BaseProxyPlugin
34
35
35
36
public override string Name => nameof ( GenericRandomErrorPlugin ) ;
36
37
37
- private const int retryAfterInSeconds = 5 ;
38
38
private readonly Random _random ;
39
39
40
40
public GenericRandomErrorPlugin ( )
@@ -55,7 +55,7 @@ private void FailResponse(ProxyRequestArgs e, GenericRandomErrorFailMode failMod
55
55
private ThrottlingInfo ShouldThrottle ( Request request , string throttlingKey )
56
56
{
57
57
var throttleKeyForRequest = BuildThrottleKey ( request ) ;
58
- return new ThrottlingInfo ( throttleKeyForRequest == throttlingKey ? retryAfterInSeconds : 0 , "Retry-After" ) ;
58
+ return new ThrottlingInfo ( throttleKeyForRequest == throttlingKey ? _configuration . RetryAfterInSeconds : 0 , "Retry-After" ) ;
59
59
}
60
60
61
61
private void UpdateProxyResponse ( ProxyRequestArgs e , GenericErrorResponse error )
@@ -72,7 +72,7 @@ private void UpdateProxyResponse(ProxyRequestArgs e, GenericErrorResponse error)
72
72
error . Headers is not null &&
73
73
error . Headers . FirstOrDefault ( h => h . Name == "Retry-After" || h . Name == "retry-after" ) ? . Value == "@dynamic" )
74
74
{
75
- var retryAfterDate = DateTime . Now . AddSeconds ( retryAfterInSeconds ) ;
75
+ var retryAfterDate = DateTime . Now . AddSeconds ( _configuration . RetryAfterInSeconds ) ;
76
76
if ( ! e . GlobalData . ContainsKey ( RetryAfterPlugin . ThrottledRequestsKey ) )
77
77
{
78
78
e . GlobalData . Add ( RetryAfterPlugin . ThrottledRequestsKey , new List < ThrottlerInfo > ( ) ) ;
@@ -82,7 +82,7 @@ error.Headers is not null &&
82
82
// replace the header with the @dynamic value with the actual value
83
83
var h = headers . First ( h => h . Name == "Retry-After" || h . Name == "retry-after" ) ;
84
84
headers . Remove ( h ) ;
85
- headers . Add ( new ( "Retry-After" , retryAfterInSeconds . ToString ( ) ) ) ;
85
+ headers . Add ( new ( "Retry-After" , _configuration . RetryAfterInSeconds . ToString ( ) ) ) ;
86
86
}
87
87
88
88
var statusCode = ( HttpStatusCode ) error . StatusCode ;
0 commit comments