Last active
December 10, 2015 00:48
-
-
Save ilmanzo/4353368 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
SECONDS_BETWEEN_REQUEST=5 | |
enable :sessions | |
def ratelimit? | |
now=Time.new.to_i | |
session['lastrequest']||=0 #inizializza se non presente | |
result=(now-session['lastrequest'])<SECONDS_BETWEEN_REQUEST #passati dall'ultima richiesta ? | |
session['lastrequest']=now # aggiorna | |
return result | |
end | |
get '/' do | |
if ratelimit? | |
return "<h1>sorry, rate limit exceeded!</h1>" | |
end | |
"<h1>hello!</h1>" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment