public ThrottlerMiddleware CreateMiddleware(ThrottleOptions throttleOptions, TimeMachine timeMachine, RequestDelegate next) { var options = Options.Create(throttleOptions); var throttlerService = CreateThrottleService(timeMachine); var throttlePolicyProvider = new DefaultThrottlePolicyProvider(options); var middleware = new ThrottlerMiddleware(next, throttlerService, throttlePolicyProvider, options, timeMachine, NullLogger <ThrottlerMiddleware> .Instance); return(middleware); }
public ThrottlerMiddleware(RequestDelegate next, IThrottlerService throttlerService, IThrottlePolicyProvider throttlePolicyProvider, IOptions <ThrottleOptions> options, ISystemClock systemClock, ILogger <ThrottlerMiddleware> logger) { _next = next; _throttlerService = throttlerService; _throttlePolicyProvider = throttlePolicyProvider; _options = options.Value; _systemClock = systemClock; _logger = logger; }
private (Result next, TimeMachine timeMachine, ThrottleOptions throttleOptions, ThrottlerMiddleware middleware, HttpContext context) Create() { var result = new Result { Called = false }; Task Next(HttpContext context) { result.Called = true; return(Task.CompletedTask); } var timeMachine = new TimeMachine(); var throttleOptions = new ThrottleOptions(); var middleware = CreateMiddleware(throttleOptions, timeMachine, Next); var context = new DefaultHttpContext(); var endpoint = CreateEndpoint(); context.SetEndpoint(endpoint); return(result, timeMachine, throttleOptions, middleware, context); }
/// <summary> /// Creates a new instance of <see cref="DefaultCorsPolicyProvider"/>. /// </summary> /// <param name="options">The options configured for the application.</param> public DefaultThrottlePolicyProvider(IOptions <ThrottleOptions> options) { _options = options.Value; }