From ea222ba67a087f76819c8bb208ee6d2721c3781d Mon Sep 17 00:00:00 2001 From: Stefan Prodan Date: Sun, 8 Dec 2013 14:23:39 +0200 Subject: [PATCH] Added XML comments --- WebApiThrottle/IThrottleRepository.cs | 3 +++ WebApiThrottle/RequestIndentity.cs | 3 +++ WebApiThrottle/ThrottleCounter.cs | 3 +++ WebApiThrottle/ThrottlePolicy.cs | 15 +++++++++++++++ WebApiThrottle/ThrottlingHandler.cs | 3 +-- WebApiThrottle/WebApiThrottle.csproj | 1 + 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/WebApiThrottle/IThrottleRepository.cs b/WebApiThrottle/IThrottleRepository.cs index 404ef99..d82e824 100644 --- a/WebApiThrottle/IThrottleRepository.cs +++ b/WebApiThrottle/IThrottleRepository.cs @@ -6,6 +6,9 @@ namespace WebApiThrottle { + /// + /// Implement this interface if you want to create a persistent store for the throttle metrics + /// public interface IThrottleRepository { bool Any(string id); diff --git a/WebApiThrottle/RequestIndentity.cs b/WebApiThrottle/RequestIndentity.cs index 6aebfef..a5ef8e8 100644 --- a/WebApiThrottle/RequestIndentity.cs +++ b/WebApiThrottle/RequestIndentity.cs @@ -6,6 +6,9 @@ namespace WebApiThrottle { + /// + /// Stores the client ip, key and endpoint + /// public class RequestIndentity { public string ClientIp { get; set; } diff --git a/WebApiThrottle/ThrottleCounter.cs b/WebApiThrottle/ThrottleCounter.cs index 7fcb564..d22ae91 100644 --- a/WebApiThrottle/ThrottleCounter.cs +++ b/WebApiThrottle/ThrottleCounter.cs @@ -6,6 +6,9 @@ namespace WebApiThrottle { + /// + /// Stores the initial access time and the numbers of calls made from that point + /// public class ThrottleCounter { public DateTime Timestamp { get; set; } diff --git a/WebApiThrottle/ThrottlePolicy.cs b/WebApiThrottle/ThrottlePolicy.cs index 3775893..87348c8 100644 --- a/WebApiThrottle/ThrottlePolicy.cs +++ b/WebApiThrottle/ThrottlePolicy.cs @@ -6,21 +6,36 @@ namespace WebApiThrottle { + /// + /// Rate limits policy + /// public class ThrottlePolicy { + /// + /// Enables IP throttling + /// public bool IpThrottling { get; set; } public List IpWhitelist { get; set; } public Dictionary IpRules { get; set; } + /// + /// Enables Cient Key throttling + /// public bool ClientThrottling { get; set; } public List ClientWhitelist { get; set; } public Dictionary ClientRules { get; set; } + /// + /// Enables routes throttling + /// public bool EndpointThrottling { get; set; } public List EndpointWhitelist { get; set; } internal Dictionary Rates { get; set; } + /// + /// Configure default request limits per second, minute, hour or day + /// public ThrottlePolicy(long? perSecond, long? perMinute = null, long? perHour = null, long? perDay = null) { Rates = new Dictionary(); diff --git a/WebApiThrottle/ThrottlingHandler.cs b/WebApiThrottle/ThrottlingHandler.cs index 59446d5..f1e404c 100644 --- a/WebApiThrottle/ThrottlingHandler.cs +++ b/WebApiThrottle/ThrottlingHandler.cs @@ -61,8 +61,7 @@ protected override Task SendAsync(HttpRequestMessage reques //check limit if (rateLimit > 0 && throttleCounter.TotalRequests > rateLimit) { - var id = identity.ToString() + "-" + rateLimitPeriod; - return QuotaExceededResponse(request, string.Format("API calls quota exceeded! maximum admitted {0} per {1} ID {2}", rateLimit, rateLimitPeriod, id)); + return QuotaExceededResponse(request, string.Format("API calls quota exceeded! maximum admitted {0} per {1}", rateLimit, rateLimitPeriod)); } } } diff --git a/WebApiThrottle/WebApiThrottle.csproj b/WebApiThrottle/WebApiThrottle.csproj index 624c20d..1820916 100644 --- a/WebApiThrottle/WebApiThrottle.csproj +++ b/WebApiThrottle/WebApiThrottle.csproj @@ -30,6 +30,7 @@ TRACE prompt 4 + bin\Release\WebApiThrottle.XML