九、加入lua,配置响应头信息:
1.修改配置文件plugin.config
2.修改配置文件remap.config
map http://www.test100.com/ http://www.test100.com/ @plugin=/usr/local/ats/libexec/trafficserver/tslua.so @pparam=/usr/local/ats/lua_ats/test_hdr.lua
注意:@plugin 这里需要加载tslua.so库, @pparam 这里是编写的lua脚本。
3.脚本如下(下面是测试的脚本):
function send_response()
ts.client_response.header['Host'] = ts.ctx['hdr']
ts.client_response.header['request-get-method'] = ts.ctx['re']
ts.client_response.header['Uri'] = ts.ctx['uri']
ts.client_response.header['server'] = ts.ctx['ser']
local cache_status = ts.http.get_cache_lookup_status()
if cache_status == TS_LUA_CACHE_LOOKUP_MISS then
ts.client_response.header['cache-lookup'] = 'MISS'
elseif cache_status == TS_LUA_CACHE_LOOKUP_HIT_STALE then
ts.client_response.header['cache-lookup'] = 'HIT_STALE'
elseif cache_status == TS_LUA_CACHE_LOOKUP_HIT_FRESH then
ts.client_response.header['cache-lookup'] = 'HIT_FRESH'
elseif cache_status == TS_LUA_CACHE_LOOKUP_SKIPPED then
ts.client_response.header['cache-lookup'] = 'HIT_SKIPPED'
end
return 0
end
function do_remap()
ts.ctx['hdr'] = 'www.test100.com'
ts.ctx['ser'] = 'wang'
ts.ctx['re'] = ts.client_request.get_method()
ts.ctx['uri'] = ts.client_request.get_uri()
ts.hook(TS_LUA_HOOK_SEND_RESPONSE_HDR, send_response)
return 0
end
然后wget 下,看看效果吧