Hadi Abbasi
unread,May 16, 2021, 11:17:16 AM5/16/21Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to openresty-en
Hello
I'm using header_filter_by_lua & body_filter_by_lua for caching!
I don't use nginx self rage -request caching system!
for caching audio & video using header & body filter systems, I can use this code for status 206 (partial content - range request):
body_filter_by_lua_block {
local cache_possible = false;
local response_content_data = nil;
if ngx.arg[1] then --on body buffering
ngx.ctx["resBody"] = ngx.ctx["resBody"] .. ngx.arg[1]
end
if ngx.arg[2] == true then --response body is loaded completely
response_content_data = ngx.ctx["resBody"]
if ngx.status == 206 then
if ngx.header["content-range"] ~= nil and tonumber(ngx.var.content_length) > 1 then
local start_range , end_range , total_range = string.match(ngx.header["content-range"], "bytes (%d+)-(%d+)/(%d+)")
if start_range ~= nil and end_range ~= nil and total_range ~= nil then
start_range = tonumber(start_range)
end_range = tonumber(end_range)
total_range = tonumber(total_range)
if start_range == 0 and tonumber(ngx.var.content_length) == total_range and end_range + 1 == total_range then
cache_possible = true
end
end
end
else
-- some codes
end
if cache_possible == true then
save_meta_data(meta_data);
save_body_data(response_content_data);
end
end
}
it works for me on caching & loading from cache times, but not always!
because at many states and times, I see caching is ignored and partial content is coming from origin server!
is it correct code?
if not, can I use filter system for caching partial contents?
if not, what is your suggestion? nginx self caching mechanism or (probably) openresty self mechanism?
Thanks a lot..
Best,
Hadi