Allow custom limit definitions that encompass multiple subnets
This commit is contained in:
Shivaram Lingamneni 2020-12-04 03:51:54 -05:00
parent 7e56f62aed
commit f9b842c88b
4 changed files with 65 additions and 24 deletions

View file

@ -32,7 +32,8 @@ var baseConfig = LimiterConfig{
Exempted: []string{"localhost"},
CustomLimits: map[string]CustomLimitConfig{
"8.8.0.0/16": {
"google": {
Nets: []string{"8.8.0.0/16"},
MaxConcurrent: 128,
MaxPerWindow: 256,
},
@ -57,7 +58,7 @@ func TestKeying(t *testing.T) {
assertEqual(maxWin, 8, t)
key, maxConc, maxWin = limiter.addrToKey(easyParseIP("8.8.4.4"))
assertEqual(key, "8.8.0.0/16", t)
assertEqual(key, "*google", t)
assertEqual(maxConc, 128, t)
assertEqual(maxWin, 256, t)
}