Last active
April 11, 2018 13:58
-
-
Save cosimo/6d3318bf173357dfb2652b7b2e81e1e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vcl 4.0; | |
import std; | |
import vsthrottle; | |
sub vcl_recv { | |
... | |
call rate_limit; | |
... | |
} | |
# | |
# Throttling based on request inspection | |
# | |
sub rate_limit { | |
if (req.url ~ "pattern1") { | |
std.log("pattern1 requests must never be throttled"); | |
return; # <---- Need to return early here, but can't do it | |
} | |
if (req.url ~ "pattern2") { | |
if (vsthrottle.is_denied("pattern2" + client.identity, 100, 10s)) { | |
std.log("pattern2 throttling for ip " + client.identity); | |
return(synth(429, "ETOOMANYREQUESTS")); | |
} | |
} | |
if (vsthrottle.is_denied("ip:" + client.identity, 500, 10s)) { | |
std.log("global throttling for ip " + client.identity); | |
return(synth(429, "ETOOMANYREQUESTS")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment