簡體   English   中英

nginx lua讀取內容編碼頭

[英]nginx lua reading content encoding header

我正在嘗試讀取 header_filter_by_lua 塊中的內容編碼。 我使用 chrome 的開發人員工具進行測試,同時請求一個響應 Content-Encoding: gzip 的 url。 我使用這些檢查:

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 有什么問題呢?

ngx.var.http_content_encoding - 將返回請求的(不是響應的)標頭

下面的 API 用於在header_filter_by_lua_block和后續階段的上下文中進行讀取訪問:

ngx.header.content_encoding總是對我ngx.header.content_encoding ,而且是正確的方法。

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

ngx.resp.get_headers()["Content-Encoding"]也可以工作,但不能有效地獲取單個標頭。

要從請求中獲取值,請使用以下內容

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM