nginx lua阅读内容编码标题

时间:2018-05-21 10:25:01

标签: nginx lua http-headers

我正在尝试读取header_filter_by_lua块中的Content-Encoding。我使用chrome的开发人员工具进行测试,同时请求使用Content-Encoding响应的URL:gzip。我使用这些检查:

local test1 = ngx.var.http_content_encoding
local test2 = ngx.header.content_encoding
local test3 = ngx.resp.get_headers()["Content-Encoding"]

并且所有这些都给出空/零值。以相同的方式获取User-Agent是成功的,那么Content-Encoding的问题是什么?

2 个答案:

答案 0 :(得分:0)

ngx.var.http_content_encoding - 将返回请求(不是响应)标题

下面的API适用于header_filter_by_lua_block及后续阶段的上下文中的读访问:

ngx.header.content_encoding始终适合我,是正确的方式。

如果不起作用 - 请检查https://github.com/openresty/lua-nginx-module#lua_transform_underscores_in_response_headers

ngx.resp.get_headers()["Content-Encoding"]也可以,但无法获得单个标题。

答案 1 :(得分:0)

要从请求中获取值,请使用以下

ngx.req.get_headers()["content_encoding"]
相关问题