コード例 #1
0
 public virtual bool IsWhitelisted(ClientRequestIdentity clientRequestIdentity, out RateLimitNameListPolicyMatchedResult result)
 {
     if (WhiteList != null)
     {
         string rule = null;
         if (!string.IsNullOrWhiteSpace(clientRequestIdentity.ClientId))
         {
             if (WhiteList.Exists(m => m.LimitType == LimitType.Client && m.IsMatched(clientRequestIdentity.ClientId, out rule)))
             {
                 result = new RateLimitNameListPolicyMatchedResult(LimitType.Client, rule);
                 return(true);
             }
         }
         string requestEndpoint = clientRequestIdentity.RequestEndpoint();
         if (WhiteList.Exists(m => m.LimitType == LimitType.Endpoint && m.IsMatched(requestEndpoint, out rule)))
         {
             result = new RateLimitNameListPolicyMatchedResult(LimitType.Endpoint, rule);
             return(true);
         }
         if (WhiteList.Exists(m => m.LimitType == LimitType.IP && m.IsMatched(clientRequestIdentity.ClientIp, out rule)))
         {
             result = new RateLimitNameListPolicyMatchedResult(LimitType.IP, rule);
             return(true);
         }
     }
     result = null;
     return(false);
 }
コード例 #2
0
 public override bool IsWhitelisted(ClientRequestIdentity clientRequestIdentity, out RateLimitNameListPolicyMatchedResult result)
 {
     if (!base.IsWhitelisted(clientRequestIdentity, out result))
     {
         foreach (var item in IPRules)
         {
             if (item.IsWhitelisted(clientRequestIdentity, out result))
             {
                 return(true);
             }
         }
         foreach (var item in ClientRules)
         {
             if (item.IsWhitelisted(clientRequestIdentity, out result))
             {
                 return(true);
             }
         }
         foreach (var item in EndpointRules)
         {
             if (item.IsWhitelisted(clientRequestIdentity, out result))
             {
                 return(true);
             }
         }
         return(false);
     }
     else
     {
         return(true);
     }
 }