Nginx Lua code :
set $questionmark ""; #Declare our empty var
body_filter_by_lua_block {
local htmlvaluetomakeempty = "id=\"username\" value="
local loginpagematch = ngx.re.match(body, "" .. htmlvaluetomakeempty .. "\"(?:.*)\"(?<match>.*)") --Search through body to see if our html match is found
if loginpagematch then --If not empty
ngx.var.questionmark = "1" --Set var to a non empty value so content-length header gets removed
body = ngx.re.gsub(body, "" .. htmlvaluetomakeempty .. "\"(?:.*)\"(?:.*)", "" .. htmlvaluetomakeempty .. "\"\"") --.. loginpagematch["match"] )
ngx.arg[1] = body
end
}
#If body contents has been modified then remove content length header
header_filter_by_lua_block {
if ngx.var.questionmark then --If this var is no longer empty we know body contents have been modified so remove content-length header
ngx.header.content_length = nil
end
}
My HTML output that Lua will be modifying.
<div class="login-fields"><label id="username-lbl" for="username" class="">User Name</label> <input type="text" name="username" id="username" value="test" class="validate-username" size="25"/></div>
<div class="login-fields"><label id="password-lbl" for="password" class="">Password</label> <input type="password" name="password" id="password" value="test" class="validate-password" size="25"/></div>
The output from Lua I keep getting.
I am using Lua to modify the default (value="test") part of the html to be a empty value (value="") but as you can see from the above returned output after Lua has handled the page I have done something wrong and i loose the rest of the line of the HTML output. I can't see what I have done wrong can anyone assist or shed light, Also sorry if my code offends anyone if you know of a tidy / neater method to achieve the same thing please do share :)