stefanprodan / WebApiThrottle

ASP.NET Web API rate limiter for IIS and Owin hosting
MIT License
1.28k stars 275 forks source link

Defaults ignored after throttle policy serialized to external cache #107

Closed dmarlow closed 7 years ago

dmarlow commented 7 years ago

PR: https://github.com/stefanprodan/WebApiThrottle/pull/106

I have the following config to be used as my "default":

public static readonly ThrottlePolicy Policy = new ThrottlePolicy(perMinute: 20)
{
    // Scope to clients
    ClientThrottling = true,

    // Scope to endpoints
    EndpointThrottling = true    
};

However, when it serializes to my Redis version of IPolicyRepository, it looks like this:

{
    "IpThrottling" : false,
    "IpWhitelist" : {
        "$values" : []
    },
    "IpRules" : {},
    "ClientThrottling" : true,
    "ClientWhitelist" : {
        "$values" : []
    },
    "ClientRules" : {},
    "EndpointThrottling" : true,
    "EndpointWhitelist" : {
        "$values" : []
    },
    "EndpointRules" : {},
    "StackBlockedRequests" : false
}

I lose the perMinute default of 20 I had specified and causes my throttling to be non-operational.

I believe the fix to be setting ThrottlePolicy.Rates to public from internal.

stefanprodan commented 7 years ago

Thanks for the PR, published on nuget v1.5.4