-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathPluginEvents.cs
More file actions
35 lines (31 loc) · 1.7 KB
/
PluginEvents.cs
File metadata and controls
35 lines (31 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace DevProxy.Abstractions.Plugins;
public class ThrottlerInfo(string throttlingKey, Func<HttpRequestMessage, string, ThrottlingInfo> shouldThrottle, DateTime resetTime)
{
/// <summary>
/// Time when the throttling window will be reset
/// </summary>
public DateTime ResetTime { get; set; } = resetTime;
/// <summary>
/// Function responsible for matching the request to the throttling key.
/// Takes as arguments:
/// - intercepted request
/// - the throttling key
/// Returns an instance of ThrottlingInfo that contains information
/// whether the request should be throttled or not.
/// </summary>
public Func<HttpRequestMessage, string, ThrottlingInfo> ShouldThrottle { get; private set; } = shouldThrottle ?? throw new ArgumentNullException(nameof(shouldThrottle));
/// <summary>
/// Throttling key used to identify which requests should be throttled.
/// Can be set to a hostname, full URL or a custom string value, that
/// represents for example a portion of the API
/// </summary>
public string ThrottlingKey { get; private set; } = throttlingKey ?? throw new ArgumentNullException(nameof(throttlingKey));
}
public class ThrottlingInfo(int throttleForSeconds, string retryAfterHeaderName)
{
public string RetryAfterHeaderName { get; set; } = retryAfterHeaderName ?? throw new ArgumentNullException(nameof(retryAfterHeaderName));
public int ThrottleForSeconds { get; set; } = throttleForSeconds;
}