Content-Type not available via ngx.resp.get_headers()?

324 views
Skip to first unread message

Jon Keys

unread,
Aug 11, 2014, 9:19:26 PM8/11/14
to openre...@googlegroups.com
Hello,

I'm attempting to capture response headers using `ngx.resp.get_headers()` inside a `body_filter_by_lua_file`.
I'm unable to get the `Content-Type` (among other "standard headers like Transfer-Encoding, Connection, etc...). If I set an `X-Content-Type` in the same place I set the `Content-Type` header I can get access to it with no issue.

Is there some rule which is blocking my access to "standard" headers?
I saw a note here (https://groups.google.com/d/msg/openresty-en/H7rMySqWTo4/RY3EM9kiqJ4J) about not being able to access some headers because they are set later in the output chain.
I'm not 100% certain this is my issue since I am able to capture headers which have been set in the exact same place so long as they are non-standard (e.g. `X-Content-Type` vs `Content-Type`).
Is there any way to work around it?

Thanks!

Jon

Jon Keys

unread,
Aug 12, 2014, 9:27:00 AM8/12/14
to openre...@googlegroups.com
In case anyone else is looking: it looks like we must use the builtin `sent_http_` vars to access "standard" headers (https://github.com/nginx/nginx/blob/b72398c9a386f5100c857869af10a910d97549fe/src/http/ngx_http_variables.c#L281).

Yichun Zhang (agentzh)

unread,
Aug 12, 2014, 4:02:19 PM8/12/14
to openresty-en
Hello!

On Mon, Aug 11, 2014 at 6:19 PM, Jon Keys wrote:
> I'm attempting to capture response headers using `ngx.resp.get_headers()`
> inside a `body_filter_by_lua_file`.
> I'm unable to get the `Content-Type` (among other "standard headers like
> Transfer-Encoding, Connection, etc...). If I set an `X-Content-Type` in the
> same place I set the `Content-Type` header I can get access to it with no
> issue.

For the ngx.resp.get_headers() API function, special support for these
builtin headers are added on user demand due to performance
considerations.

I've just added support for Content-Type, Content-Length, Connection,
and Transfer-Encoding to ngx.resp.get_headers() in the git repos:

https://github.com/openresty/lua-nginx-module/commit/e0cd3ccf

Regards,
-agentzh

Jon Keys

unread,
Aug 12, 2014, 4:10:14 PM8/12/14
to openre...@googlegroups.com
Wow! Awesome! Thank you so much for the super quick response and resolution.
You've been so helpful and courteous. I really appreciate all your help.
 
Reply all
Reply to author
Forward
0 new messages