1

I'm trying to read the Content-Encoding in a header_filter_by_lua block. I test using chrome's developer tools while requesting an url which respond with Content-Encoding: gzip. I use these checks:

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

and all of them give empty/nil value. Getting User-Agent in same way is successful so what's the problem with Content-Encoding?

2 Answers 2

7

ngx.var.http_content_encoding - would return request's (not response's) header

API below work for read access in context of header_filter_by_lua_block and later phases:

ngx.header.content_encoding works for me always and is the right way.

If it doesn't work - check https://github.com/openresty/lua-nginx-module#lua_transform_underscores_in_response_headers

ngx.resp.get_headers()["Content-Encoding"] also work, but not efficient to obtain single header.

Sign up to request clarification or add additional context in comments.

1 Comment

I tried to get the response headers, but I am getting only "connection:keep-alive" header. Not getting any other headers. Can you help?
0

To get the value from request use following

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.