【问题标题】:nginx lua reading content encoding headernginx lua 读取内容编码头
【发布时间】:2018-10-30 23:44:48
【问题描述】:

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

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 有什么问题?

【问题讨论】:

    标签: nginx lua http-headers


    【解决方案1】:

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

    ngx.req.get_headers()["content_encoding"]
    

    【讨论】:

      【解决方案2】:

      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"] 也可以,但获取单个标头效率不高。

      【讨论】:

        猜你喜欢
        • 2021-04-27
        • 2014-11-05
        • 1970-01-01
        • 2016-02-13
        • 2021-04-06
        • 2014-05-14
        • 1970-01-01
        • 2016-03-16
        • 2021-03-15
        相关资源
        最近更新 更多