Exemplo n.º 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);
 }