Response body is coming as nil using register_fetches and lua

I am trying to intercept the response body of HTTP requests in a lua script using the register_fetches core API.
My lua code is as follows:

local function resp_filter(txn)
	local payload = txn.f:req_body()
	if payload ~= nil then
		core.Info("** Response " .. payload .. "\n")
		core.Info("** Response is nil")
core.register_fetches("resp_filter", resp_filter)

I am calling the function as follows from config file

http-response   set-var(txn.req_body) lua.resp_filter

However I am getting the response body as nil for versions 1.9.7 - 2.1.12. It is working fine for versions outside of this bracket.

NOTE: The API was changed from req.body to res.body post version 2.2.

Why is the req.body returning nil for the versions mentioned above but is working fine prior to those releases?

I don’t know about older versions, but starting with 2.5 the filter API is available from Lua and may help you to achieve that:

Also, please consider upgrading to an LTS release to benefit from latest bug fixes and security updates, see for the list of supported versions