refactor: sets ratelimit as action

This commit is contained in:
followcube
2021-06-08 22:45:51 +03:00
parent 7b83affae5
commit bda2f31996
2 changed files with 7 additions and 23 deletions

View File

@@ -2,26 +2,10 @@ package.path = package.path .. "./?.lua;/usr/local/etc/haproxy/scripts/?.lua"
test = {}
local redis = require 'redis'
client = redis.connect('redis', 6379)
-- response = client:ping()
-- print(response)
function test.ratelimit(applet)
host = applet.headers.host[0]
current = client:llen(host)
if current > 3 then
applet:set_status(200)
local response = string.format([[<html><body>powel naxyi %s, current - %s\n</body></html>]], host, current, message);
applet:add_header("content-type", "text/html");
applet:add_header("content-length", string.len(response))
applet:start_response()
applet:send(response)
else
client:rpush(host,host)
client:expire(host, 10)
applet:set_status(200)
local response = string.format([[<html><body>lox %s, current - %s\n</body></html>]], host, current, message);
applet:add_header("content-type", "text/html");
applet:add_header("content-length", string.len(response))
applet:start_response()
applet:send(response)
end
local expire_time
function test.ratelimit(txn)
local host = txn.sf:hdr("Host")
client:rpush(host,host)
client:expire(host, expire_time)
end