syntax: headers = ngx.resp.get_headers(max_headers?, raw?)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, balancer_by_lua*
Returns a Lua table holding all the current response headers for the current request.
1 2 3 4 |
<span class="pl-k">local</span> h <span class="pl-k">=</span> ngx.<span class="pl-smi">resp</span>.<span class="pl-c1">get_headers</span>() <span class="pl-k">for</span> k, v <span class="pl-k">in</span> <span class="pl-c1">pairs</span>(h) <span class="pl-k">do</span> <span class="pl-c1">...</span> <span class="pl-k">end</span> |
This function has the same signature as ngx.req.get_headers except getting response headers instead of request headers.
参考: https://github.com/openresty/lua-nginx-module#ngxrespget_headers
注意: 字段名都会转换成小写
1 2 3 4 5 6 |
expires:Thu, 19 Nov 1981 08:52:00 GMT content-type:text/html; charset=utf-8 connection:keep-alive cache-control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0 pragma:no-cache content-encoding:gzip |