Exemplo n.º 1
0
        public async Task <RateLimitResult?> GetLimits(HttpContext context, RateLimitingOptions options)
        {
            var discriminator = await Discriminator.Invoke(context);

            if (string.IsNullOrEmpty(discriminator))
            {
                // TODO: Log missing discriminator as warning.
                return(default);
 public static RateLimitingOptions Limit(this RateLimitingOptions options, string name, Selector <int> limit, TimeSpan period, Selector <string> discriminator)
 {
     return(options.Limit(name, limit.ToAsync(), period, discriminator.ToAsync()));
 }
 public static RateLimitingOptions Limit(this RateLimitingOptions options, string name, int limit, AsyncSelector <TimeSpan> period, AsyncSelector <string> discriminator)
 {
     return(options.Limit(name, _ => limit, period, discriminator));
 }
 public static RateLimitingOptions Allow(this RateLimitingOptions options, string name, IPAddress address)
 {
     return(options.Allow(name, ctx => ctx.Connection.RemoteIpAddress.Equals(address)));
 }
 public static RateLimitingOptions Block(this RateLimitingOptions options, string name, Selector <bool> predicate)
 {
     return(options.Block(name, predicate.ToAsync()));
 }
 public static RateLimitingOptions Block(this RateLimitingOptions options, string name, IPNetwork network)
 {
     return(options.Block(name, ctx => network.Contains(ctx.Connection.RemoteIpAddress)));
 }