Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Added XML comments
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Dec 8, 2013
1 parent a5290f7 commit ea222ba
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
3 changes: 3 additions & 0 deletions WebApiThrottle/IThrottleRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace WebApiThrottle
{
/// <summary>
/// Implement this interface if you want to create a persistent store for the throttle metrics
/// </summary>
public interface IThrottleRepository
{
bool Any(string id);
Expand Down
3 changes: 3 additions & 0 deletions WebApiThrottle/RequestIndentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace WebApiThrottle
{
/// <summary>
/// Stores the client ip, key and endpoint
/// </summary>
public class RequestIndentity
{
public string ClientIp { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions WebApiThrottle/ThrottleCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace WebApiThrottle
{
/// <summary>
/// Stores the initial access time and the numbers of calls made from that point
/// </summary>
public class ThrottleCounter
{
public DateTime Timestamp { get; set; }
Expand Down
15 changes: 15 additions & 0 deletions WebApiThrottle/ThrottlePolicy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,36 @@

namespace WebApiThrottle
{
/// <summary>
/// Rate limits policy
/// </summary>
public class ThrottlePolicy
{
/// <summary>
/// Enables IP throttling
/// </summary>
public bool IpThrottling { get; set; }
public List<string> IpWhitelist { get; set; }
public Dictionary<string, RateLimits> IpRules { get; set; }

/// <summary>
/// Enables Cient Key throttling
/// </summary>
public bool ClientThrottling { get; set; }
public List<string> ClientWhitelist { get; set; }
public Dictionary<string, RateLimits> ClientRules { get; set; }

/// <summary>
/// Enables routes throttling
/// </summary>
public bool EndpointThrottling { get; set; }
public List<string> EndpointWhitelist { get; set; }

internal Dictionary<RateLimitPeriod, long> Rates { get; set; }

/// <summary>
/// Configure default request limits per second, minute, hour or day
/// </summary>
public ThrottlePolicy(long? perSecond, long? perMinute = null, long? perHour = null, long? perDay = null)
{
Rates = new Dictionary<RateLimitPeriod, long>();
Expand Down
3 changes: 1 addition & 2 deletions WebApiThrottle/ThrottlingHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ protected override Task<HttpResponseMessage> 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));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions WebApiThrottle/WebApiThrottle.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\WebApiThrottle.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
Expand Down

0 comments on commit ea222ba

Please sign in to comment.