mirror of
https://gitgud.io/fatchan/haproxy-protection.git
synced 2025-05-09 02:05:37 +00:00
refactor: sets ratelimit as action
This commit is contained in:
@@ -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
|
Reference in New Issue
Block a user