Returns a Lua table holding the response headers. Keys are header names.
Values are either a string with the header value, or an array of strings
if a header was sent multiple times. Header names in this table are
case-insensitive and are normalized to lowercase, and dashes (-
) can be
written as underscores (_
). For example, the header X-Custom-Header
can
also be retrieved as x_custom_header
.
A response initially has no headers. Headers are added when a plugin
short-circuits the proxying by producing a header
(e.g. an authentication plugin rejecting a request), or if the request has
been proxied, and one of the latter execution phases is currently running.
Unlike kong.service.response.get_headers()
, this function returns all
headers as the client would see them upon reception, including headers
added by Kong itself.
By default, this function returns up to 100 headers (or what has been
configured using lua_max_resp_headers
). The optional max_headers
argument
can be specified to customize this limit, but must be greater than 1 and
equal to or less than 1000.
Phases
- header_filter, response, body_filter, log, admin_api
Parameters
-
max_headers (
number
, optional): Limits the number of headers parsed.
Returns
-
table
: headers A table representation of the headers in the
response.
-
string
: err If more headers than max_headers
were present,
returns a string with the error "truncated"
.
Usage
-- Given an response from the Service with the following headers:
-- X-Custom-Header: bla
-- X-Another: foo bar
-- X-Another: baz
local headers = kong.response.get_headers()
headers.x_custom_header -- "bla"
headers.x_another[1] -- "foo bar"
headers["X-Another"][2] -- "baz"