예제 #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");
            }
        }
예제 #2
0
 public ApiThrottleActionFilter(ICacheProvider cache, ApiThrottleOptions options)
 {
     _cache   = cache;
     _options = options;
 }
예제 #3
0
 public ApiThrottleService(ICacheProvider cache, IOptions <ApiThrottleOptions> options, IStorageProvider storage)
 {
     _cache   = cache;
     _options = options.Value;
     _storage = storage;
 }
예제 #4
0
 public ApiThrottleMiddleware(RequestDelegate next, ICacheProvider cache, IOptions <ApiThrottleOptions> options)
 {
     _next    = next;
     _cache   = cache;
     _options = options.Value;
 }