diff --git a/haproxy/haproxy.cfg b/haproxy/haproxy.cfg index 47ce854..a4b39bb 100644 --- a/haproxy/haproxy.cfg +++ b/haproxy/haproxy.cfg @@ -17,7 +17,7 @@ frontend http-in http-request lua.hcaptcha-redirect if !{ path -m beg /captcha } http-request use-service lua.hello-world if { path /hello_world } http-request use-service lua.hcaptcha-view if { path /captcha/ } - http-request use-service lua.ratelimit if { path /test } + http-request lua.ratelimit if !{ path -m beg /captcha } acl captcha_passed var(txn.captcha_passed) -m bool acl on_captcha_url path -m beg /captcha diff --git a/scripts/test.lua b/scripts/test.lua index 25df7e0..520b847 100644 --- a/scripts/test.lua +++ b/scripts/test.lua @@ -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([[powel naxyi %s, current - %s\n]], 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([[lox %s, current - %s\n]], 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 \ No newline at end of file