in kong/kong/init.lua [1231:1300]
function Kong.header_filter()
local ctx = ngx.ctx
if not ctx.KONG_PROCESSING_START then
ctx.KONG_PROCESSING_START = start_time() * 1000
end
if not ctx.workspace then
ctx.workspace = kong.default_workspace
end
if not ctx.KONG_HEADER_FILTER_START then
ctx.KONG_HEADER_FILTER_START = now() * 1000
if ctx.KONG_REWRITE_START and not ctx.KONG_REWRITE_ENDED_AT then
ctx.KONG_REWRITE_ENDED_AT = ctx.KONG_BALANCER_START or
ctx.KONG_ACCESS_START or
ctx.KONG_RESPONSE_START or
ctx.KONG_HEADER_FILTER_START
ctx.KONG_REWRITE_TIME = ctx.KONG_REWRITE_ENDED_AT -
ctx.KONG_REWRITE_START
end
if ctx.KONG_ACCESS_START and not ctx.KONG_ACCESS_ENDED_AT then
ctx.KONG_ACCESS_ENDED_AT = ctx.KONG_BALANCER_START or
ctx.KONG_RESPONSE_START or
ctx.KONG_HEADER_FILTER_START
ctx.KONG_ACCESS_TIME = ctx.KONG_ACCESS_ENDED_AT -
ctx.KONG_ACCESS_START
end
if ctx.KONG_BALANCER_START and not ctx.KONG_BALANCER_ENDED_AT then
ctx.KONG_BALANCER_ENDED_AT = ctx.KONG_RESPONSE_START or
ctx.KONG_HEADER_FILTER_START
ctx.KONG_BALANCER_TIME = ctx.KONG_BALANCER_ENDED_AT -
ctx.KONG_BALANCER_START
end
if ctx.KONG_RESPONSE_START and not ctx.KONG_RESPONSE_ENDED_AT then
ctx.KONG_RESPONSE_ENDED_AT = ctx.KONG_HEADER_FILTER_START
ctx.KONG_RESPONSE_TIME = ctx.KONG_RESPONSE_ENDED_AT -
ctx.KONG_RESPONSE_START
end
end
if ctx.KONG_PROXIED then
if not ctx.KONG_WAITING_TIME then
ctx.KONG_WAITING_TIME = (ctx.KONG_RESPONSE_START or ctx.KONG_HEADER_FILTER_START) -
(ctx.KONG_BALANCER_ENDED_AT or ctx.KONG_ACCESS_ENDED_AT)
end
if not ctx.KONG_PROXY_LATENCY then
ctx.KONG_PROXY_LATENCY = (ctx.KONG_RESPONSE_START or ctx.KONG_HEADER_FILTER_START) -
ctx.KONG_PROCESSING_START
end
elseif not ctx.KONG_RESPONSE_LATENCY then
ctx.KONG_RESPONSE_LATENCY = (ctx.KONG_RESPONSE_START or ctx.KONG_HEADER_FILTER_START) -
ctx.KONG_PROCESSING_START
end
ctx.KONG_PHASE = PHASES.header_filter
runloop.header_filter.before(ctx)
local plugins_iterator = runloop.get_plugins_iterator()
execute_collected_plugins_iterator(plugins_iterator, "header_filter", ctx)
runloop.header_filter.after(ctx)
ctx.KONG_HEADER_FILTER_ENDED_AT = get_updated_now_ms()
ctx.KONG_HEADER_FILTER_TIME = ctx.KONG_HEADER_FILTER_ENDED_AT - ctx.KONG_HEADER_FILTER_START
end