This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Haproxy map support to speed up vhost to backend lookup. (#229)
* Haproxy map support to speed up vhost to backend lookup. (#1) * added support for haproxy maps with the help of --haproxy-map flag * Updated read me for haproxy maps * updated readme * Updated readme * changed list comparison as it was not compatible with python3 * added lua module to expose vhostmaps and changed test cases to reflect it. Changed haproxy_dir to use a variable instead of extracting the value every time * changed to get path separator in getvhostmap.lua from library call instead of assuming a path separator * updated config and test_cases to use vhostmap lua module, irrespective of haproxy-map flag, and changed lua module to handle the same, fixed few formatting issues with readme * updated readme to reflect the change in _haproxy_getvhostmap behaviour * fix for multiple vhosts with path which ensures it checks if path and auth are present before proceding with multiple vhosts acl * regenerated the docs and added test case for haproxy map with http to https redirection * fixed issue where acl for http to https was not getting generated when no path and no auth where specified and modified the test case to catch the same
- Loading branch information
1 parent
5e34d29
commit 327bc90
Showing
6 changed files
with
823 additions
and
73 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-- A simple Lua script which serves up the HAProxy | ||
-- vhost to backend map file. | ||
function check_file_exists(name) | ||
local f=io.open(name,"r") | ||
if f~=nil then io.close(f) return true else return false end | ||
end | ||
|
||
function read_vhostmap_file(cmdline) | ||
local found = false | ||
local filename = '' | ||
for s in string.gmatch(cmdline, '%g+') do | ||
if s == '-f' then | ||
found = true | ||
elseif found then | ||
filename = s | ||
sep = package.config:sub(1,1) | ||
filename=filename:match("(.*"..sep..")").."domain2backend.map" | ||
break | ||
end | ||
end | ||
|
||
local map = '' | ||
if check_file_exists(filename) then | ||
local f = io.open(filename, "rb") | ||
map = f:read("*all") | ||
f:close() | ||
else | ||
map = '' | ||
end | ||
return map | ||
end | ||
|
||
function load_vhostmap() | ||
local f = io.open('/proc/self/cmdline', "rb") | ||
local cmdline = f:read("*all") | ||
f:close() | ||
return read_vhostmap_file(cmdline) | ||
end | ||
|
||
core.register_service("getvhostmap", "http", function(applet) | ||
local haproxy_vhostmap = load_vhostmap() | ||
applet:set_status(200) | ||
applet:add_header("content-length", string.len(haproxy_vhostmap)) | ||
applet:add_header("content-type", "text/plain") | ||
applet:start_response() | ||
applet:send(haproxy_vhostmap) | ||
end) | ||
|
Oops, something went wrong.