Closed karlseguin closed 1 year ago
@karlseguin, nice! let me think about this a bit. I think this originally worked outside OpenResty too, like normal Lua. So we may need to be careful if we want to keep that.
There is also this: https://github.com/bungle/lua-resty-template#templateprint
So one way is to monkeypatch to print
. But perhaps good default should include the length. Thus I was thinking that perhaps changing this to include the header is better:
https://github.com/bungle/lua-resty-template/blob/master/lib/resty/template.lua#L130
The content type is another thing that we may want to consider (perhaps headers as a whole).
I actually think you're right. I think this just needs to be documented.
I ended up adding a helper file in my own app that looks something like:
local print = ngx.print
local function render(file, layout)
local t = template.new(file, layout)
local view = t:process()
ngx.header["Content-Length"] = #view
print(view)
end
I'm not sure if there's a reason not to do this? By setting the content length, we're no longer relying on chunked encoding which, all other things being equal, I think is a win.