ts-lua - Embed the Power of Lua into Apache TrafficServer.
This module is under active development and is production ready.
This document describes ts-lua v0.1.7 released on 31 May 2015. It can work with Apache TrafficServer v4.x, v5.x.
https://groups.google.com/forum/#!forum/ts-lua
##Synopsis hdr.lua
function send_response()
ts.client_response.header['Rhost'] = ts.ctx['rhost']
return 0
end
function do_remap()
local req_host = ts.client_request.header.Host
ts.ctx['rhost'] = string.reverse(req_host)
ts.hook(TS_LUA_HOOK_SEND_RESPONSE_HDR, send_response)
return 0
end
sethost.lua
local HOSTNAME = ''
function __init__(argtb)
if (#argtb) < 1 then
print(argtb[0], 'hostname parameter required!!')
return -1
end
HOSTNAME = argtb[1]
end
function do_remap()
ts.client_request.header['Host'] = HOSTNAME
return 0
end
This module embeds Lua, via the standard Lua 5.1 interpreter, into Apache Traffic Server. This module acts as remap plugin of Traffic Server, so we should realize 'do_remap' function in each lua script. We can write this in remap.config:
map http://a.foo.com/ http://inner.foo.com/ @plugin=/X/libtslua.so @pparam=/X/hdr.lua
Sometimes we want to receive parameters and process them in the script, we should realize '_init_' function in the lua script(sethost.lua
is a reference), and we can write this in remap.config:
map http://a.foo.com/ http://b.foo.com/ @plugin=/X/libtslua.so @pparam=/X/sethost.lua @pparam=a.st.com
https://github.com/portl4t/ts-lua/wiki/Doc
- linux/freebsd 64bits
- trafficserver
- pcre
- tcl
- openssl
- lua-5.1
step1: get ts-lua
git clone https://github.com/portl4t/ts-lua.git
cd ts-lua/src
step2: modify Makefile to insure INC_PATH and LIB_PATH is right for trafficserver, lua-5.1 and tcl
make
step3: modify remap.config and restart the trafficserver
https://github.com/portl4t/ts-lua/wiki/ChangeLog
- ts-fetcher http fetcher for ats, implement as plugin with c