Hi Folks,
I'm testing a use case that I've handled previously with header rewrites,
but I would like to replace arbitrary strings in both the request header
and request body.
I've enabled request buffering and also http-server-close to simplify
things and avoid streaming requests as per some other examples that I've
seen.
SAMPLE LUA CODE:
function mod_body(txn)
local reqbody = txn.req:get()
reqbody = string.gsub( reqbody, 'fixed-string-1', 'fixed-string-2' )
txn.req:set( reqbody )
--txn.req:send( ??? reqbody )
end
core.register_action( "do_something", { "http-req" }, mod_body )
-------------
In testing I would call this from haproxy in a backend like so:
http-request lua.do_something if METH_POST
I've also tried in the frontend.
I'm not certain this use case is supported so I haven't done extensive
testing, but if I simply call "txn.req:set( reqbody )" then haproxy exits
on signal 11.
As you can see from the commented line I was also experimenting with
calling txn.req:send but it requires another argument, and it's not clear
to me what the argument should be in this context.
So it would seem that one of these things is occurring:
1) I'm using the wrong channel call to end this function
2) This could work, but I would need to read the http request buffer one
line at a time, process, and then call either txn.req:set() or
txn.req:send() when completed
3) This isn't expected to work and I should pursue other methods
Any advice, general or specific?
Many thanks,
-=Mark