ts-lua icon indicating copy to clipboard operation
ts-lua copied to clipboard

lua脚本不存在,ts 会一直重启

Open phonehold opened this issue 12 years ago • 9 comments

当lua脚本不存在,ts 会一直重启。这个不太合理。 当检查到传递的参数lua脚本不存在。则放弃加载。保证ats服务正常

phonehold avatar Sep 30 '13 08:09 phonehold

嗯, 这个后续再看一下吧, 我是觉得如果脚本加载出错依然让ats正常服务的话, 有可能很难察觉到lua加载出错

portl4t avatar Oct 07 '13 11:10 portl4t

能添加获取 method的hook吗。我想要取到是一个请求是get 还是post ,body内容是什么,这样方便做处理

phonehold avatar Oct 07 '13 12:10 phonehold

获取method这个不难, 只是我最近还没来得及添加, 应该是以一个函数的形式来体现,例如: ts.client_request.get_method()

body内容的话, 我需要想一下, 因为数据都是流式的么, 可能类似于transform那种的

portl4t avatar Oct 07 '13 12:10 portl4t

恩。像ngx_lua 一样。有一套完整的hook。就完美了。谢谢你的回复

phonehold avatar Oct 07 '13 12:10 phonehold

ngx_lua那个太完美了, 而且agentzh和chaoslawful都是神级的人物, 很多事情我还需要和他们请教,呵呵

portl4t avatar Oct 07 '13 12:10 portl4t

恩。readme再加一个debug 的tag 为ts_lua (Log the MESSAGE to traffic.out if debug is enabled. The tag is ts_lua),要不好多人不知道tag名字

还有一个要请教一下

local HOSTNAME = ''

function init(argtb)

if (#argtb) < 1 then
    print(argtb[0], 'hostname parameter required!!')
    return -1
end

HOSTNAME = argtb[1]

end

function send_response() ts.client_response.header['X-Cache'] = ts.ctx['lookup'] end

function cache_lookup() local cache_status = ts.http.get_cache_lookup_status() --ts.http.set_resp(400, "params invalid\n") if cache_status == 0 then status= "HIT_FRESH " elseif cache_status == 1 then status = "MISS " elseif cache_status == 2 then status = "HIT " elseif cache_status == 3 then status = "SKIP " else status = "Unknow " end local return_status = status .. HOSTNAME ts.ctx['lookup'] = return_status end

function do_remap() ts.hook(TS_LUA_HOOK_SEND_RESPONSE_HDR, send_response) ts.hook(TS_LUA_HOOK_CACHE_LOOKUP_COMPLETE, cache_lookup) end

枚举类型中 typedef enum { TS_LUA_CACHE_LOOKUP_MISS, TS_LUA_CACHE_LOOKUP_HIT_STALE, TS_LUA_CACHE_LOOKUP_HIT_FRESH, TS_LUA_CACHE_LOOKUP_SKIPPED } TSLuaCacheLookupResult;

这个不应是0-3 吗。可是对应出来的hit miss 状态是不对的。比较小白。能解释一下吗

phonehold avatar Oct 07 '13 12:10 phonehold

嗯,很多API和常量的定义我还没写在Readme里.

cache枚举的范围是0-3 0是MISS 1是命中但已过期 2是命中并且没有过期 3这个一般用不到

portl4t avatar Oct 07 '13 12:10 portl4t

可是1是miss 。从来测试的情况来看。2是hit 3是skip 我测试过

phonehold avatar Oct 07 '13 12:10 phonehold

好, 那我晚点也测一下, 我记得过去是测过的, 理论上0和1这两种结果都会造成回源

portl4t avatar Oct 07 '13 12:10 portl4t