mirror of
https://gitgud.io/fatchan/haproxy-protection.git
synced 2025-05-09 02:05:37 +00:00
Adjust lua get_server_names
This commit is contained in:
@ -1,13 +1,16 @@
|
|||||||
package.path = package.path .. "./?.lua;/etc/haproxy/scripts/?.lua;/etc/haproxy/libs/?.lua"
|
package.path = package.path .. "./?.lua;/etc/haproxy/scripts/?.lua;/etc/haproxy/libs/?.lua"
|
||||||
|
|
||||||
local bot_check = require("bot-check")
|
local bot_check = require("bot-check")
|
||||||
|
local utils = require("utils")
|
||||||
|
|
||||||
local backends_map = Map.new('/etc/haproxy/map/backends.map', Map._str)
|
local backends_map = Map.new('/etc/haproxy/map/backends.map', Map._str)
|
||||||
function get_server_names(txn)
|
function get_server_names(txn)
|
||||||
local key = txn.sf:hdr("Host")
|
local key = txn.sf:hdr("Host")
|
||||||
local value = backends_map:lookup(key or "")
|
local value = backends_map:lookup(key or "")
|
||||||
if value ~= nil then
|
if value ~= nil then
|
||||||
return value
|
local vals = utils.split(value, ",")
|
||||||
|
-- todo: something smarter?
|
||||||
|
return vals[math.random(#vals)]
|
||||||
else
|
else
|
||||||
return ""
|
return ""
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user