Beispiel #1
0
 protected virtual string ComputeThrottleKey(RequestIdentity requestIdentity, RateLimitPeriod period,
                                             ThrottlingBy throttlingBy)
 {
     return(core.ComputeThrottleKey(requestIdentity, period, throttlingBy));
 }
Beispiel #2
0
        internal string ComputeThrottleKey(RequestIdentity requestIdentity, RateLimitPeriod period, ThrottlingBy throttlingBy)
        {
            var keyValues = new List <string>()
            {
                ThrottleManager.GetThrottleKey()
            };

            if (Policy.IpThrottling && throttlingBy.HasFlag(ThrottlingBy.IpThrottling))
            {
                keyValues.Add(requestIdentity.ClientIp);
            }

            if (Policy.ClientThrottling && throttlingBy.HasFlag(ThrottlingBy.ClientThrottling))
            {
                keyValues.Add(requestIdentity.ClientKey);
            }

            if (Policy.EndpointThrottling && throttlingBy.HasFlag(ThrottlingBy.EndpointThrottling))
            {
                keyValues.Add(requestIdentity.Endpoint);
            }

            keyValues.Add(period.ToString());

            var id      = string.Join("_", keyValues);
            var idBytes = Encoding.UTF8.GetBytes(id);

            byte[] hashBytes;

            using (var algorithm = System.Security.Cryptography.SHA1.Create())
            {
                hashBytes = algorithm.ComputeHash(idBytes);
            }

            var hex = BitConverter.ToString(hashBytes).Replace("-", string.Empty);

            return(hex);
        }