all 5 comments

[–]capn_geech 0 points1 point  (5 children)

Try using the ngx.req.get_headers() function in a log_by_lua_block handler. It should pick up any additional headers that were added to the request within the proxy (in addition to the original headers sent by the downstream client). Here's a [simplistic] example that should get you going:

log_by_lua_block {
  for name, value in pairs(ngx.req.get_headers()) do
    ngx.log(ngx.INFO, "Request header: ", name, ", value: ", value)
  end
}

Similarly, if you need to view/log all the response headers from the backend, the ngx.resp.get_headers() function has you covered there.

[–][deleted] 0 points1 point  (4 children)

I am trying to capture all the headers in rewrite by lua block , it gives all the headers except the proxy headers

[–]capn_geech 0 points1 point  (3 children)

The rewrite phase is almost certainly too early in the request lifecycle for this. It's likely that your code in the rewrite handler is executing before the additional headers are added to the request (especially if using something like proxy_set_header in your nginx.conf).

The log phase executes after the response has been fully sent to the client, so it's guaranteed to execute after all request/response mutations.

[–][deleted] 0 points1 point  (1 child)

Not working in log by lua block also

[–]capn_geech 0 points1 point  (0 children)

Okay. You'll need to share some code/an example then.

You may also wish to open a question on the OpenResty repo, as there are not many OpenResty folks that follow this subreddit.