Beispiel #1
0
        internal static string GetPolicyValue(this HttpContext context, ApiThrottleOptions options, Policy policy, string policyKey)
        {
            switch (policy)
            {
            case Policy.Ip:
                return(CommonHelper.IpToNum(options.OnIpAddress(context)));

            case Policy.UserIdentity:
                return(options.OnUserIdentity(context));

            case Policy.Header:
                return(context.GetHeaderValue(policyKey));

            case Policy.Query:
                return(context.GetQueryValue(policyKey));

            case Policy.RequestPath:
                return(context.GetRequestPath());

            case Policy.Cookie:
                return(context.GetCookieValue(policyKey));

            case Policy.Form:
                return(context.GetFormValue(policyKey));

            default:
                throw new ArgumentException("参数出错", "policy");
            }
        }
 public ApiThrottleActionFilter(ICacheProvider cache, ApiThrottleOptions options)
 {
     _cache   = cache;
     _options = options;
 }
Beispiel #3
0
 public ApiThrottleService(ICacheProvider cache, IOptions <ApiThrottleOptions> options, IStorageProvider storage)
 {
     _cache   = cache;
     _options = options.Value;
     _storage = storage;
 }
Beispiel #4
0
 public ApiThrottleMiddleware(RequestDelegate next, ICacheProvider cache, IOptions <ApiThrottleOptions> options)
 {
     _next    = next;
     _cache   = cache;
     _options = options.Value;
 }