move ngx.arg[1] to the beginning

This commit is contained in:
wiaamm
2025-12-07 10:05:02 +02:00
parent 69b1578523
commit 4f2808e857

View File

@@ -249,6 +249,8 @@ function NanoHandler.header_filter(conf)
end end
function NanoHandler.body_filter(conf) function NanoHandler.body_filter(conf)
local chunk = ngx.arg[1]
local eof = ngx.arg[2]
local ctx = kong.ctx.plugin local ctx = kong.ctx.plugin
if ctx.blocked or ctx.bypass_inspection then if ctx.blocked or ctx.bypass_inspection then
return return
@@ -258,9 +260,6 @@ function NanoHandler.body_filter(conf)
local session_data = ctx.session_data local session_data = ctx.session_data
if not session_id or not session_data or ctx.session_finalized then if not session_id or not session_data or ctx.session_finalized then
-- Clear the chunk to release it from memory immediately
-- Without this, Kong holds chunks in memory causing OOM
ngx.arg[1] = nil
return return
end end
@@ -273,7 +272,6 @@ function NanoHandler.body_filter(conf)
local verdict, response, modifications = nano.end_inspection(session_id, session_data, nano.HttpChunkType.HTTP_RESPONSE_END) local verdict, response, modifications = nano.end_inspection(session_id, session_data, nano.HttpChunkType.HTTP_RESPONSE_END)
if modifications then if modifications then
local chunk = ngx.arg[1]
chunk = nano.handle_body_modifications(chunk, modifications, ctx.body_buffer_chunk or 0) chunk = nano.handle_body_modifications(chunk, modifications, ctx.body_buffer_chunk or 0)
ngx.arg[1] = chunk ngx.arg[1] = chunk
end end
@@ -300,9 +298,6 @@ function NanoHandler.body_filter(conf)
return return
end end
local chunk = ngx.arg[1]
local eof = ngx.arg[2]
if chunk and #chunk > 0 then if chunk and #chunk > 0 then
ctx.body_buffer_chunk = ctx.body_buffer_chunk or 0 ctx.body_buffer_chunk = ctx.body_buffer_chunk or 0
ctx.body_seen = true ctx.body_seen = true